Jump to content

Mysql problem


david4ie

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.