Re: [PHP-DB] boolean instead of array
On Sun, 2002-11-03 at 15:01, Jason Wong wrote: > On Sunday 03 November 2002 20:58, John Coder wrote: > > > Try adding some error checking into your code (see manual examples) and > > > using mysql_error() to find out what's going. > > > > What error checking to insert into this code I'm clueless. I found out > > Again, have a look at the examples in the manual (the MySQL functions > section). The example which starts the chapter shows quite explicitly how you > should > > (i) establish a connection to the mysql server > (ii) select a database to query > (iii) perform a query > (iv) display the results of the query > > And for good measure you should alter the die() statements to incorporate a > mysql generated error message: > > die("" . mysql_error()); This all I have done and it generates no errors since it returns a value althogh a boolean type as opposed to Array. Out of 4 different queries this one is the one that returns a boolean. when I said I have no idea how to generate an error message I meant how to generate a error message concerning wrong type of return not no return. Sorry if I wasn't clear enough before. John Coder PS everything goes at it should without this query. it's actually shoes the same with or without the query. but this query is just to generate a list of names for a graph. the graph itself is generated but the names aren't -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] boolean instead of array
On Sunday 03 November 2002 20:58, John Coder wrote: > > Try adding some error checking into your code (see manual examples) and > > using mysql_error() to find out what's going. > > What error checking to insert into this code I'm clueless. I found out Again, have a look at the examples in the manual (the MySQL functions section). The example which starts the chapter shows quite explicitly how you should (i) establish a connection to the mysql server (ii) select a database to query (iii) perform a query (iv) display the results of the query And for good measure you should alter the die() statements to incorporate a mysql generated error message: die("" . mysql_error()); Once you get that example working, you can modify (one step at a time) to suit your needs. -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* Spock: The odds of surviving another attack are 13562190123 to 1, Captain. */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] boolean instead of array
It's hard to tell which output is from which loop, you might be getting confused (if anything, you might be confusing anyone that might help)... the Boolean was probabally due to a bad result, for whatever reason (maybe your connect code was wrong? I'm not sure but I think you get a valid resource id even when your connection fails or you don't get any returs on your query), and the arrays were more than likely empty before if they didn't contain your results, because mysql_fetch_row returned an array of nulls (try looping through those arrays, and checking is_null on the values). I'll skip the lecture on naming conventions, especially the lengthy section about other people reading your code. Without seeing the rest of your script, or your talbe structure, you might want to try a LEFT JOIN in your query, that will preserve values that are null. You might also want to use mysql_fetch_array (or mysql_fetch_object), which I've always used, and never had a problem getting results from. I'd be nice to at least see your table structure, then I or anybody else here could give you a more precise answer. I'd suggest looking at the mysql manual entries for SUM, JOIN, LEFT JOIN, and the php manual entries for mysql_fetch_row, mysql_fetch_array, and mysql_query. Hope this is helpful! -- Josh -Original Message- From: John Coder [mailto:jcoder@;insightbb.com] Sent: Saturday, November 02, 2002 9:23 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] boolean instead of array I seem to somehow get an boolean instead of an array from a mysql_fetch_row function and I have no idea how. Here's the code; $names=mysql_query("select name from dept join picdata where dept.deptid=picdata.deptid limit 5"); print $names.""; //offending query $resets=mysql_query("select sum(reset) from Tmp group by deptid order by deptid limit 5"); while($c=mysql_fetch_row($names)); { //$a[]=$c[0]; commented out for troubleshooting $y=gettype($c); print $y.""; } while($e=mysql_fetch_row($resets)) { $z=gettype($e); print $z.""; //$b[]=$e[0]; commented out for troubleshooting } Here's the output from a terminal: select name from dept join picdata where picdata.deptid=dept.deptid limit 5; +-+ | name| +-+ | BodyWatch | | BreakThroughGallery | | TempGallery | | KidZone | | Lobby | +-+ 5 rows in set (0.01 sec) here's the output from the browser: Resource id #3 boolean array array array array array Any suggestions as to what I'm doing wrong? John Coder -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] boolean instead of array
On Sun, 2002-11-03 at 01:44, Jason Wong wrote: > On Sunday 03 November 2002 10:23, John Coder wrote: > > I seem to somehow get an boolean instead of an array from a > > mysql_fetch_row function and I have no idea how. > > Here's the code; > > Try adding some error checking into your code (see manual examples) and using > mysql_error() to find out what's going. > What error checking to insert into this code I'm clueless. I found out why I wasn't getting an array by inserting gettype and finding out it's a boolean type instead of array but past that checking out why It's boolean type I have no idea how to begin. John Coder -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] boolean instead of array
On Sunday 03 November 2002 10:23, John Coder wrote: > I seem to somehow get an boolean instead of an array from a > mysql_fetch_row function and I have no idea how. > Here's the code; Try adding some error checking into your code (see manual examples) and using mysql_error() to find out what's going. -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* My friend has a baby. I'm writing down all the noises he makes so later I can ask him what he meant. -- Steven Wright */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] boolean instead of array update
the deptid in both Tmp and picdata are the same so it nakes no diff which I use the output is the same Boolean each time I just noticed that the tables were diff names but data and structure is the same. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] boolean instead of array
I seem to somehow get an boolean instead of an array from a mysql_fetch_row function and I have no idea how. Here's the code; $names=mysql_query("select name from dept join picdata where dept.deptid=picdata.deptid limit 5"); print $names.""; //offending query $resets=mysql_query("select sum(reset) from Tmp group by deptid order by deptid limit 5"); while($c=mysql_fetch_row($names)); { //$a[]=$c[0]; commented out for troubleshooting $y=gettype($c); print $y.""; } while($e=mysql_fetch_row($resets)) { $z=gettype($e); print $z.""; //$b[]=$e[0]; commented out for troubleshooting } Here's the output from a terminal: select name from dept join picdata where picdata.deptid=dept.deptid limit 5; +-+ | name| +-+ | BodyWatch | | BreakThroughGallery | | TempGallery | | KidZone | | Lobby | +-+ 5 rows in set (0.01 sec) here's the output from the browser: Resource id #3 boolean array array array array array Any suggestions as to what I'm doing wrong? John Coder -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php