Log in

View Full Version : PHP / MySQL Keywords



queerfm
03-20-2008, 12:57 PM
Hi i would like to show a random ad based on keyword.
For e.g i have 3 technology ads and i would like the PHP to randomly choose a ad to show this is what i have.



<?php
$ads = "SELECT * FROM ads ORDER BY RAND()LIMIT 1";
$adsresult = mysql_query($ads);

while($row = mysql_fetch_array($adsresult)) echo"{$row['file']}&displaywidth={$row['displaywidth']}&displayheight={$row['displayheight']}";?>


This script does work but it just randomly chooses the ad to show.
Thanks

thetestingsite
03-21-2008, 12:01 AM
The only thing I could think of is either adding a new column to your db that holds a list of keywords, then you could call the ads like so:



$ads = "SELECT * FROM `ads` WHERE `keywords` LIKE '%".$_GET['keyword']."%' ORDER BY RAND() LIMIT 1";


Hope this helps.

queerfm
03-21-2008, 01:59 AM
I got it to work however it there away to make it = not like i tryed replacing the LIKE with = and it did not work

queerfm
03-21-2008, 01:40 PM
Ok got it working, Now another problem sorry

I have 20 items in jokes
i would like to show 6 items per page

so like
ID= 1><10
then at bottom of page it say
next

it reloads the same page but
ID=11><20

I hope that helps