This looks like a pretty decent query to me... To figure out more about the errors mysql is producing, you can try to put a
print mysql_error(); After ever call to a mysql function .. From there you should be able to learn more about the errors, and if not: don't bother posting what mysql_error() produces. Ow, and one question: does it give the errors if there's no rows in any table, or also if there's no rows in one of the tables? And in the second option, does it give you the errors less often? Wouter -----Original Message----- From: Ryan A [mailto:[EMAIL PROTECTED] Sent: Monday, September 15, 2003 12:49 AM To: esctoday.com | Wouter van Vliet Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Program works only when there are records :-( Hey, Thanks for replying. sorry, i thought i explained what $tt was, but here it is in program code if you want to be clear on it. $tt = "SELECT COUNT(*), 'Count1' FROM shared WHERE user ='".$mmmy_user."' and ccno=".$mmmy_ccno." UNION SELECT COUNT(*), 'Count2' FROM dedicated WHERE user='".$mmmy_user."' and ccno=".$mmmy_ccno." UNION SELECT COUNT(*), 'Count3' FROM reseller WHERE user ='".$mmmy_user."' and ccno=".$mmmy_ccno." UNION SELECT COUNT(*), 'Count4' FROM colocated WHERE user ='".$mmmy_user."' and ccno=".$mmmy_ccno." UNION SELECT COUNT(*), 'Count5' FROM freehosting WHERE user ='".$mmmy_user."' and ccno=".$mmmy_ccno; I'll try those things you outlined till then. Cheers, -Ryan > 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:[EMAIL PROTECTED] > Sent: Sunday, September 14, 2003 11:45 PM > To: [EMAIL PROTECTED] > 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 > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php