World Wide Whale
Gender:
Posts: 154
651 credits Members referred : 0
Lets make lots of money!
« on: Dec 12, 2006, 08:22:23 PM »
Hi guys,
I've got a problem. I've been working on this for some time now and I just cannot figure it out, maybe it's my code or something.
Ok, I'm trying to list categories in order that goes so far then carries on into the next column.
So it will start off with the main categories then followed by its sub categories. So many is displayed (say 20), then any more to be displayed into the next column.
Here's the website page to give you an idea: click here
And the code I'm using:
Code:
<?php include("config.inc.php"); global $first, $second; // count how many rows $rowcount = 0; // row colour $odd = "#f5f5eb"; $even = "#f5f5cb"; $cid = $_GET['cid']; $back = $_GET['cid']; $allcats = array(); // add 14 days to expire delete $fourteenDays = strtotime("+ 14 days"); $expire_delete = date("Y-m-d", $fourteenDays); // todays date $todaysdate = date("Y-m-d"); // check to see if the advert has expired mysql_query("UPDATE gallery_photos SET photo_expired='1', photo_expire_delete='".$expire_delete."' WHERE NOW() >= photo_expire_date "); // check to see if the advert has expired 14 days after the expired date, if so delete mysql_query("DELETE FROM gallery_photos WHERE photo_expire_delete='".$todaysdate."' AND photo_expired='1' "); // Category Listings if( $cid && empty($pid) ) { // retrieve the main category name and id $resultcount = mysql_query( "SELECT COUNT(category_parent) as Nume FROM gallery_category WHERE category_parent = '".$cid."' "); // count all the first sub categories $num_rows = mysql_fetch_array( $resultcount ); $cate_num = $num_rows[0]; // retrieve the main category name and id $resultcat = mysql_query( "SELECT category_id, category_name, category_parent, category_des FROM gallery_category ORDER BY category_des");
while($maincatn = mysql_fetch_assoc( $resultcat )) { $allcats[] = array('ids' => $maincatn['category_id'], 'names' => $maincatn['category_name'], 'pars' => $maincatn['category_parent']); } foreach( $allcats as $dinner) { // check if $row_count equals $per_column if($cate_num > 2) { $width = 50; } else { $width = 100; } if($dinner['ids'] == $cid) { // display the main category echo "<table valign='top' width='100%' border='0' cellspacing='0' cellpadding='0'> <tr> <td width='11' height='33' valign='top'><img src='../images/index_07.gif' width='11' height='33' /></td> <td width='100%' valign='middle' bgcolor='#BFD475' class='style5'>".$dinner['names']."</td> <td width='12' valign='top'><img src='../images/index_10.gif' width='12' height='33' /></td> </tr> </table>"; $first = $dinner['ids']; } // display the first sub category table echo "<table valign='top' width='".$width."%' border='0' cellspacing='1' cellpadding='0'> <tr>"; // now, retrieve all first descendants of the main category if($dinner['pars'] == $first) { // display the first sub category echo "<td width='".$width."%' height='20' valign='middle' bgcolor='#CDCB98' class='style5'>".$dinner['names']."</td>"; $second = $dinner['ids']; } // display the first sub category end table echo "</tr> </table>"; // find how many adverts are in each sub category $how_many = mysql_query( "SELECT COUNT(*) as Num FROM gallery_photos WHERE photo_category = '".$dinner['ids']."' AND NOW() < photo_expire_date "); $howmany = mysql_fetch_array( $how_many ); // now, retrieve all other descendants from the first descendant category if($dinner['pars'] == $second) { $row_color = ($rowcount % 2) ? $odd : $even; // display the second sub category(s) echo "<table valign='top' width='".$width."%' border='0' cellspacing='1' cellpadding='0'> <tr> <td width='".$width."%' height='20' valign='middle' bgcolor='".$row_color."'> <img src='images/arrow.jpg'> <font face='Verdana, Arial, Helvetica, sans-serif' color='#000000' size='1'><a href='".$home_dir."catmain.php?cid=".$dinner['ids']."&back=".$back."' class='mnav'>".$dinner['names']." (".$howmany[0].")</a></span></font></td> </tr> </table>"; $rowcount++; } } } ?>
cheers,
spence
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 8037
41179 credits Members referred : 3
« Reply #1 on: Dec 12, 2006, 08:29:34 PM »
I think you need an extra query in this loop :
foreach( $allcats as $dinner)
where you will have to select and display all the categories that have category_parent = $dinner['ids']