Forum Moderators: coopster
It queries the DB for subcategories and if present list them seperated by "¦"
$pol = mysql_query("select * from categories where parent = '$catid' order by name");
if (mysql_num_rows($pol) > 0) {
while ($scat = mysql_fetch_object($pol)) {
$subcatimg = rand(1,5);
$subcathtml .= "<img src=\"".$_SERVER["HOST_NAME"]."/images/cat-".$subcatimg.".gif\" border=\"0\" align=\"absmiddle\"><a href=\"".str_replace(" ", "_", $scat->name)."/".getindex($scat->name).".$pext\">".$scat->name."</a> ¦ ";
}
$subcathtml = substr($subcathtml, 0, -2);
}
else $subcathtml = "Geen";
I've tried several web suggestions, but cannot seem to assimilate it with the exsisting code above.
Thanks for any support!
Steve
// Start the table
$subcathtml = "<table>";
// Start the loop
while ($scat = mysql_fetch_object($pol)) {
$subcatimg = rand(1,5);
// Start the row
$subcathtml .= "<tr>";
// The first column
$subcathtml .= "<td><img src=\"".$_SERVER["HOST_NAME"]."/images/cat-".$subcatimg.".gif\" border=\"0\" align=\"absmiddle\"></td>";
// The second column
$subcathtml .= "<td><a href=\"".str_replace(" ", "_", $scat->name)."/".getindex($scat->name)."$pext\">".$scat->name."</a></td>";
// The third column... not sure what goes in here
$subcathtml .= "<td> </td>";
// End the row
$subcathtml .= "</tr>";
}
// End the table
$subcathtml .= "</table>";
Hopefully I'm not too far off the mark and this is what you were after :)
The image before the link is just a design thingie, it should reside into the same table cell like this:
<table>
<tr>
<td>[image][subcategorie] </td>
<td>[image][subcategorie] </td>
<td>[image][subcategorie] </td>
</tr>
<tr>
<td>[image][subcategorie] </td>
<td>[image][subcategorie] </td>
<td>[image][subcategorie] </td>
</tr>
</table>
Thanks!
// Start the table
$subcathtml = "<table>";// Store an internal counter for the loop
$counter = 1;// Store a number of rows
$numRows = mysql_num_rows($pol);// Start the loop
while ($scat = mysql_fetch_object($pol)) {
$subcatimg = rand(1,5);// Start the first row
if ($counter == 1)
{
$subcathtml .= "<tr>";
}// column
$subcathtml .= "<td><img src=\"".$_SERVER["HOST_NAME"]."/images/cat-".$subcatimg.".gif\" border=\"0\" align=\"absmiddle\">a href=\"".str_replace(" ", "_", $scat->name)."/".getindex($scat->name)."$pext\">".$scat->name."</a></td>";// End the row
if (($counter % 3) == 0 && $counter!= $numRows)
{
$subcathtml .= "</tr><tr>";
} else if ($counter == $numRows) {
for ($i = 1; $i <= ($counter % 3); $i++)
{
$subcathtml .= "<td> </td>";
}
$subcathtml .= "</tr>";
}
$counter ++;
}
// End the table
$subcathtml .= "</table>";
I haven't been able to test this, but it should give you a starting point.
The internal counter is tested against the number of columns that you want and the total number of rows, so it should give you a well formed table with empty columns if it doesn't fit within your 3 column structure.