I have a field called "types" that holds record using , as delimiter. When I loop through the records I have tried to explode the type field and look using in_array for a match, for each match found show an image ..
The code I have below seems to image for every record even tho only some of the records have a match. Here is what I have:
Code: Select all
$numcols = 3;
$numcolsprinted = 0;
$sql = mysql_query("SELECT * FROM portfolio");
echo '<table width=100%" align="center" border="0" cellspacing="2" cellpadding="2">';
while($row = mysql_fetch_array($sql)) {
if($numcolsprinted == $numcols) {
echo "<tr></tr>";
$numcolsprinted = 0;
}
if(isset($_SESSION['userid'])){
$delportf = '<br /><font size="1"><a class="second" href="'.$_SERVER['PHP_SELF'].'?action=addportfolio">Add</a> - <a class="second" href="'.$_SERVER['PHP_SELF'].'?action=addportfolio&edit=edit&portfolioid='.$row['portfolioid'].'">Edit</a> - <a class="second" href="'.$_SERVER['PHP_SELF'].'?action=deleteportfolio&portfolioid='.$row['portfolioid'].'">Delete</a></font>';
}
echo '<td align="right" bgcolor="#DCDCD1">';
$types = explode(",",$row['types']);
foreach($types as $type) {
if(in_array("Print", $types)) {
$w = 'link to print image here';
}
if(in_array("Website", $types)) {
$p = 'link to website image here';
}
}
echo ''.$w.' '.$p.'<img src="./images/portfolio/multimedia.gif" /> <img src="./images/portfolio/web.gif" /> <img src="./images/portfolio/cms.gif" /> <img src="./images/portfolio/ecommerce.gif" />';
echo '</td>';
echo '<td valign="top" width="25%" bgcolor="#DCDCD1">';
echo "<b><a class=\"second\" href=\"javascript: AjaxRequest('main','./includes/portfoliodisplay.php?id=".$row['portfolioid']."')\">".$row['name']."</a> ".$delportf."</b>";
echo '</td>';
$numcolsprinted++;
}
$colstobalance = $numcols - $numcolsprinted;
for($i=1; $i<=$colstobalance; $i++) {
}
echo "</table>";
Thanks
