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
using pics from my database.[Solved]
Moderator: General Moderators
-
nutstretch
- Forum Contributor
- Posts: 104
- Joined: Sun Jan 11, 2004 11:46 am
- Location: Leicester
using pics from my database.[Solved]
Last edited by nutstretch on Mon Jan 12, 2004 4:03 pm, edited 1 time in total.
i would probably do it like this
Don't forget to change the field heading i have used to the ones that you have used in your DB.
Mark
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);
?>Mark
-
nutstretch
- Forum Contributor
- Posts: 104
- Joined: Sun Jan 11, 2004 11:46 am
- Location: Leicester
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
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
sorry mate, my mistake
change this line
to...
Mark
change this line
Code: Select all
while ($row = mysql_fetch_row($resultID))Code: Select all
while ($row = mysql_fetch_array($resultID, MYSQL_ASSOC)) {-
nutstretch
- Forum Contributor
- Posts: 104
- Joined: Sun Jan 11, 2004 11:46 am
- Location: Leicester
resolved
Many thanks
just got to work out how to display it nicely now lol!!!!!
just got to work out how to display it nicely now lol!!!!!