Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
eggoz
Forum Commoner
Posts: 43 Joined: Fri Dec 27, 2002 8:51 pm
Post
by eggoz » Wed Jan 22, 2003 2:45 pm
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 » Wed Jan 22, 2003 4:12 pm
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 » Wed Jan 22, 2003 5:51 pm
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 » Wed Jan 22, 2003 6:17 pm
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];
eggoz
Forum Commoner
Posts: 43 Joined: Fri Dec 27, 2002 8:51 pm
Post
by eggoz » Wed Jan 22, 2003 6:26 pm
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.
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Wed Jan 22, 2003 9:47 pm
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