...

View Full Version : while() help



sergxp
12-19-2007, 10:07 PM
I have a table generated from a mysql table. One of the fields in the table has urls of images. I want the generated html table show the image instead of just the url how would I go about this. Here is my code:


while($rows = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<tr>';
foreach($rows as $data) {
echo '<td>'.$data.'</td>';
}
}

king2k5
12-19-2007, 10:16 PM
<?while($rows = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<tr>';
foreach($rows as $data) {
echo '<td><img src=\"$data\"></td>';
}
}
?>


That should work.. i think?

sergxp
12-19-2007, 11:16 PM
nevermind i figured it out. I needed to use an if statement with a regular expression to find that its a image url.

So it looks like this:


while($rows = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<tr>';
foreach($rows as $data) {
if(ereg("^\/images", $data)) {
echo '<td><img src="/phptest/user'.$data.'"></td>';
}else{
echo '<td>'.$data.'</td>';
}
}

}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum