Resource id #3 - no data from simple queries
Posted by JimL (JimL), 28 January 2004I am working with a MySQL database and am writing simple queries to extract data from it. However, when I print out the results of the queries all I am getting are the following values:
Resource id #3
Resource id #4
Resource id #5
Here is my code:
mysql_connect("localhost","adminuser","adminpass") or die ("Could not connect: " . mysql_error());
mysql_select_db("osirispwd") or die ("Could not select db: " . mysql_error());
$uniresult = mysql_query("SELECT uni_card_no FROM tbl_osiris WHERE uni_card_no = \"$unicardnum\"");
Any ideas anyone?
Posted by Chris_Isaac (Chris Isaac), 28 January 2004Hi
I tried something similar on something I'm working on, 2 things I did differently to get mine to work were:
1. on the following line:
I changed the '=' to a like statement, but I'm using parts of strings, not numbers.
also to print out I put in the following:
hope this helps.
Posted by admin (Graham Ellis), 29 January 2004Hi, Jim, welcome ...
Chris is basically heading you in the right direction.
mysql_query returns a reference to a result set rather than the result set itself, so you get rubbish if you print it out. You need to call a function such as mysql_fetch_array or mysql_fetch_assoc to read a result itself from the result set object (and what you get will be an array). If your query can return more that 1 row, keep calling it until there are no more rows to get back.
In many ways, a result set is like a file handle that you read from, and just like a file handle it's used to let you iterate over what can be a huge data set in easy steps rather than having you presented with too much data all at the same time
Posted by JimL (JimL), 29 January 2004Ahh!
All becomes clear!
I now remember that we used mysql_fetch_assoc() on the PHP course.
Thanks for clarifying this for me!
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: email@example.com • WEB: http://www.wellho.net • SKYPE: wellho