Page 1 of 1

using pics from my database.[Solved]

Posted: Mon Jan 12, 2004 9:08 am
by nutstretch
I have a datebase which holds at present 1 table with 6 fields. the last field 'image' holds the path and name of the pic (gifs/1122.jpg) that belongs to the rest of that record. I have done this so that the database doesn't get too big when completely populated.

i am using the following code to output my query to a table on a webpage. how can i adapt this so that i can incorporate img src="$field" and the image be displayed instead of the name of the image. Is this possible or am i thinking pie in the sky
<?
$linkID = @mysql_connect("localhost", "root", "");
mysql_select_db("DBShoes", $linkID);

$resultID = mysql_query("SELECT * FROM tblShoes where gender like '$gender'", $linkID);
print "<table border=1><tr><th> ID</th>";
print "<th>Name></th><th>Gender</th><th>Brand</th><th>Colour</th><th>Picture</th>";

while ($row = mysql_fetch_row($resultID))
{
print "<tr>";
foreach ($row as $field)
{
print "<td>$field</td>";
}
print "</tr>";

}
print"</table>";

mysql_close($linkID);
?>

Any help appreciated

Posted: Mon Jan 12, 2004 9:25 am
by JayBird
i would probably do it like this

Code: Select all

<? 
$linkID = @mysql_connect("localhost", "root", ""); 
mysql_select_db("DBShoes", $linkID); 

$resultID = mysql_query("SELECT * FROM tblShoes where gender like '$gender'", $linkID); 
print "<table border=1><tr><th> ID</th>"; 
print "<th>Name></th><th>Gender</th><th>Brand</th><th>Colour</th><th>Picture</th>"; 

while ($row = mysql_fetch_row($resultID)) 
{ 
print "<tr>"; 
print "<td>".$row['gender']."</td>";
print "<td>".$row['brand']."</td>"; 
print "<td>".$row['colour']."</td>"; 
print "<td><img src="".$row['picture'].""></td>"; 
print "</tr>"; 

} 
print"</table>"; 

mysql_close($linkID); 
?>
Don't forget to change the field heading i have used to the ones that you have used in your DB.

Mark

Posted: Mon Jan 12, 2004 9:46 am
by nutstretch
I tried that but got the following. I assumed i needed to put the real names of the fields in single quote marks i.e.['Name']

this is part of the error message

Warning: Undefined index: ID in c:\program files\apache group\apache\htdocs\retrieve1.php on line 21

Warning: Undefined index: Name in c:\program files\apache group\apache\htdocs\retrieve1.php on line 22

it continued for all the fields

Posted: Mon Jan 12, 2004 10:00 am
by JayBird
sorry mate, my mistake

change this line

Code: Select all

while ($row = mysql_fetch_row($resultID))
to...

Code: Select all

while ($row = mysql_fetch_array($resultID, MYSQL_ASSOC)) {
Mark

resolved

Posted: Mon Jan 12, 2004 10:24 am
by nutstretch
Many thanks

just got to work out how to display it nicely now lol!!!!!