hi, i get this error when i run my script

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in E:\xampp\htdocs\autogh\admin\userindex\scripts\banner.php on line 13

this is my mysql statement

$banners_num = "select * FROM banners WHERE DATE_ADD(todate, INTERVAL numDay DAY) > NOW() AND position='top_banner'";

Am trying to place ads on my site based on days and not impression.

here is my banner script

<?php
$links = array();
$image_file = array(); 

$banners_num = "select * FROM banners WHERE DATE_ADD(todate, INTERVAL numDay DAY) > NOW() AND position='top_banner'";

$banners_num = mysql_num_rows($banners_result);
$i = 0;
while($i < $banners_num) 
{ 
   $bannertype[$i] = mysql_result($banners_result,$i,"bannertype");
   $numDay[$i] = mysql_result($banners_result,$i,"numDay");
   $links[$i] = mysql_result($banners_result,$i,"bannerurl");
   $image_file[$i] = mysql_result($banners_result,$i,"image_file");
   $i++;		
}

$count = count($links) -1;

$randnum = rand(0,$count);
if ($randnum == $_SESSION['randnum'])
{
	$randnum = rand(0,$count);
}
$_SESSION['randnum'] = $randnum;


echo "<a href='//$links[$randnum]' target='_blank'><img src='../../ads/$image_file[$randnum]' width='390' height='200' /></a>
	";
?>

Recommended Answers

All 7 Replies

Where do you give $banners_result a value?

pls. explain, i do not understand what you mean

You need to run the query before trying to parse the results. :D

Thanks for your time,if i get you right, it shd look like this

$banners_num = "select * FROM banners WHERE DATE_ADD(todate, INTERVAL numDay DAY) > NOW() AND position='top_banner'";

$banners_num = mysql_num_rows($banners_num);
$i = 0;
while($i < $banners_num)

if this is not what you mean, can you pls. show example, because i still get the same error ,thanks.

mysql_connect('localhost', 'user', 'password');
mysql_select_db('database');
$banners_query = "select * FROM banners WHERE DATE_ADD(todate, INTERVAL numDay DAY) > NOW() AND position='top_banner'";
$banners_result = mysql_query($banners_query);
$banners_num = mysql_num_rows($banners_result);

You should add error checking too, but perhaps you should start with the manual first, specifically the section about mysql.

thanks a million pritaeas, some time you need some one else to take a god look at your code.Am amazed i missed that.Am so grateful,Thanks,i think its working now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.