Page 1 of 1
Resource id #2
Posted: Wed Jan 22, 2003 2:45 pm
by eggoz
I started changing a script around trying to list just one row of my database into a table. When I go to php page, i get
this. I am not sure what I am doing wrong. I should be getting values after every : in each line. here is a small part of the script:
Code: Select all
$a_code = mysql_query ( "SELECT $table.Code FROM $table" );
<tr>
<td width="33%">Item Number: <? echo $a_code; ?></td>
</tr>
Thats baisclly my code, minus the table, connections, etc. Thanks
Posted: Wed Jan 22, 2003 4:12 pm
by Rob the R
mysql_query returns a resource. You need to use another function, like
mysql_fetch_assoc, to actually get at the data that's contained in the resource. The
PHP manual has all the details.
Posted: Wed Jan 22, 2003 5:51 pm
by eggoz
Can I replace the mysql_query with mysql_fetch_assoc or mysql_fetch_field? I tried that and it didn't work. Just comes up blank.
Posted: Wed Jan 22, 2003 6:17 pm
by elipollak
u need to fetch components
eg.
mysql_fetch_array() or
mysql_fetch_row() .... etc
Code: Select all
$result = mysql_query("SELECT $table.Code FROM $table");
$row = mysql_fetch_array($result);
print $rowї1];
Posted: Wed Jan 22, 2003 6:26 pm
by eggoz
I understand that. I have gotten the values of a row before. But this time, I just need to get the value of one field.
Code: Select all
$result2 = mysql_query ( "SELECT $table.Description FROM $table" );
$a_des = mysql_fetch_field ($result2);
<table border="1" width="100%">
<tr>
<td width="33%">Description: <? echo $a_des; ?></td>
</tr>
</table>
Thats what I have right now.
Posted: Wed Jan 22, 2003 9:47 pm
by hob_goblin
The row will be an array.
if your table has the column 'Description'
Code: Select all
$result2 = mysql_query ( "SELECT $table.Description FROM $table" );
$a_des = mysql_fetch_assoc ($result2);
echo $a_desї'Description'];
Then it should print the description. Don't use fetch_field, use fetch_array, or fetch_assoc.
And, please, read the manual.
http://www.php.net/mysql_fetch_assoc