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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.