Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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:


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

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:
$uniresult = mysql_query("SELECT uni_card_no FROM tbl_osiris WHERE uni_card_no = \"$unicardnum\"");

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:

while($row=mysql_fetch_array($uniresult)) {
                 echo("Uniresult: - ".$row["uni_card_no"]."<br>");}

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

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 and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho