0

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>
	";
?>

Edited by accra: n/a

3
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by accra
0

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.

Edited by accra: n/a

0
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.

Edited by pritaeas: n/a

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.