RE: [PHP] Program works only when there are records :-(
| From: | esctoday.com | Wouter van Vliet | Date: | Sun, 14 Sep 2003 22:08:37 +0000 |
| Subject: | RE: [PHP] Program works only when there are records :-( | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-162578@lists.php.net to get a copy of this message | ||
Start by giving us the value of $tt, ... That'll probably tell more about
the problem. Or you can do something like this:
if ($res = mysql_query($tt)) {
$num_rows = mysql_num_rows($res); //This is line 25
$x=1;
for($i=0; $i<5; $i++) {
$a = mysql_result($res, $i); //This is line 30
$bb[$x]=$a;
$x++;
}
} else {
print "sorry, no results found";
};
Also, for:
=====
for($i=0; $i<5; $i++) {
$a = mysql_result($res, $i); //This is line 30
=====
I'd suggest: while($a = mysql_fetch_array($res)) {
Wouter
-----Original Message-----
From: Ryan A [mailto:ryan@jumac.com]
Sent: Sunday, September 14, 2003 11:45 PM
To: php-general@lists.php.net
Subject: [PHP] Program works only when there are records :-(
Hi,
I have a select statment with a UNION so that i am getting 5 COUNT(*)'s from
a table.
After that I have this code:
*****************************
$res = mysql_query($tt);
$num_rows = mysql_num_rows($res); //This is line 25
$x=1;
for($i=0; $i<5; $i++)
{
$a = mysql_result($res, $i); //This is line 30
$bb[$x]=$a;
$x++;
}
$one = $bb[1];
$two = $bb[2];
$thr = $bb[3];
$fou = $bb[4];
$fiv = $bb[5];
$tot=$one + $two + $thr + $fou + $fiv;
*****************************
When i have some records in the database this works fine and i get all the
values in $one,$two etc but when a new account is created and i the
COUNT(*) gets back just 0 I get these ugly errors/warnings on my page:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource in /usr163/home/b/e/bestweb/public_html/co.details.php on line 25
Warning: mysql_result(): supplied argument is not a valid MySQL result
resource in /usr163/home/b/e/bestweb/public_html/co.details.php on line 30
Warning: mysql_result(): supplied argument is not a valid MySQL result
resource in /usr163/home/b/e/bestweb/public_html/co.details.php on line 30
Warning: mysql_result(): supplied argument is not a valid MySQL result
resource in /usr163/home/b/e/bestweb/public_html/co.details.php on line 30
Warning: mysql_result(): supplied argument is not a valid MySQL result
resource in /usr163/home/b/e/bestweb/public_html/co.details.php on line 30
Warning: mysql_result(): supplied argument is not a valid MySQL result
resource in /usr163/home/b/e/bestweb/public_html/co.details.php on line 30
What should i do and wheres the problem? I searched on google but just found
some sites outputting this, no real help.
Totally confused, please help.
Thanks,
-Ryan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php