| |||||||||||
| |||||||||||
Resource id #3 - no data from simple queries Posted by JimL (JimL), 28 January 2004 I 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: <?php 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\""); print("Uniresult: $uniresult<br>"); ?> Any ideas anyone? Cheers, Jim Posted by Chris_Isaac (Chris Isaac), 28 January 2004 HiI 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: Code:
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: Code:
hope this helps. Posted by admin (Graham Ellis), 29 January 2004 Hi, 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 2004 Ahh!All becomes clear! I now remember that we used mysql_fetch_assoc() on the PHP course. Thanks for clarifying this for me! Cheers, Jim ![]() This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |