Resource id #2

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
eggoz
Forum Commoner
Posts: 43
Joined: Fri Dec 27, 2002 8:51 pm

Resource id #2

Post 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
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post 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.
eggoz
Forum Commoner
Posts: 43
Joined: Fri Dec 27, 2002 8:51 pm

Post 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.
elipollak
Forum Newbie
Posts: 22
Joined: Sun Jan 19, 2003 10:23 pm

Post 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&#1111;1];
eggoz
Forum Commoner
Posts: 43
Joined: Fri Dec 27, 2002 8:51 pm

Post 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.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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&#1111;'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
Post Reply