Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resource id #1 ??? Where did that come from?

Status
Not open for further replies.

QAteste

Technical User
Jun 14, 2002
23
US
New to the game and hoping someone can help me. I have a simple mysql database. Tring to build a one column table of hostnames in a web page frame. The table is built fine but instead of the hostname, I get Resource id #x in each of the table cells.


Here is my simple db:
+------------+----------+-------------+-----------+-----------+
| machine_id | hostname | ip_addr | os | dbms |
+------------+----------+-------------+-----------+-----------+
| 1 | aurora | 1.2.3.4 | Win2KAS | Oracle9.2 |
| 2 | sahara | 51.52.53.54 | Win2KAS | DB2 7.2 |
| 3 | cznaix | 11.12.13.14 | AIX 4.3.3 | DB2 7.2 |
+------------+----------+-------------+-----------+-----------+

Here is my code:

<?php

//Connect to the database server
$dbcnx = @mysql_connect(&quot;raindrop&quot;,&quot;root&quot;);
if (! $dbcnx) {
echo( &quot;<P>Unable to connect to the &quot; . &quot;database server at this time.</P>&quot; );
exit();
}

// Select the database
if (! @mysql_select_db(&quot;machines&quot;) ) {
echo( &quot;<P>Can not connect to the machines db</P>&quot; );
exit();
}
$result = mysql_query(&quot;SELECT * FROM machines&quot;, $dbcnx);
$num_rows = mysql_num_rows($result);


for ($i = 0; $i < $num_rows; $i++) {
if ($i == 0) echo (&quot;<table width='100%' tableborder='YES' border='1'>&quot;);
echo (&quot;<tr>&quot;);
$sql = &quot;select hostname from machines where machine_id = '$i'&quot;;
$result = mysql_query($sql, $dbcnx);
echo (&quot;<td ALIGN=center BGCOLOR='#99CCFF'>$result</td>&quot;);
echo (&quot;</tr>&quot;);
if ($i == $num_rows-1) echo (&quot;</table>&quot;);
}

?>
 
mysql_query() returns a resource handle to the data, not the data itself. For that you need to use mysql_fetch_array() or something like it.

Take a look at the simple example code about a third of the way down this page: ______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top