david4ie Posted June 30, 2008 Share Posted June 30, 2008 Hello I am creating a script which allows users to buy advertising space on my website. The script allows users to buy a certain ammount of clicks. The below script selects a random banner from the DB if the banner has clicks left. the Clicks table is the ammount of clicks bought ... eg 100, 500, 100 the Hits table is how many times the banner has been clicked so far. This is display.php : <?php $mysql_db = "ads"; $mysql_u = "root"; $mysql_p = "" ; MYSQL_CONNECT("localhost","$mysql_u","$mysql_p"); mysql_select_db("$mysql_db"); $result = mysql_query("SELECT * FROM ads"); $num_rows = mysql_num_rows($result); $rand = rand(1,$num_rows); $query1 = "SELECT image_url FROM ads WHERE id = \"$rand\" AND WHERE hits < clicks"; $result1 = mysql_query($query1); while ($row = mysql_fetch_row($result1)) { $image = $row['0']; echo "<a href=\"clicks.php?id=$rand\"><img src=\"$image\" border=\"0\" /></a>"; } ?> The above script gives this error : Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\display.php on line 19 But when I take away AND WHERE hits < clicks the script works fine. Im sure im missing something simple here but I cant seem to find it. Does anybody know the problem? Thanks Link to comment https://forums.phpfreaks.com/topic/112644-mysql-problem/ Share on other sites More sharing options...
micah1701 Posted June 30, 2008 Share Posted June 30, 2008 take out the second "WHERE" in your query statement. "SELECT image_url FROM ads WHERE id = '$rand' AND hits < clicks" Link to comment https://forums.phpfreaks.com/topic/112644-mysql-problem/#findComment-578459 Share on other sites More sharing options...
david4ie Posted June 30, 2008 Author Share Posted June 30, 2008 Works Thanks for the help Link to comment https://forums.phpfreaks.com/topic/112644-mysql-problem/#findComment-578464 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.