5, September 2008

Two column rpoblem - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: Two column rpoblem
« previous next »
Pages: [1] Print

Author Topic: Two column rpoblem  (Read 631 times)
World Wide Whale
***
Gender: Male
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 Visit through proxy


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."'>&nbsp;&nbsp;<img src='images/arrow.jpg'>&nbsp<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  Smiley
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
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']

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
World Wide Whale
***
Gender: Male
Posts: 154
651 credits
Members referred : 0


Lets make lots of money!


« Reply #2 on: Jan 06, 2007, 12:00:42 AM »

Just to let you all know, I've managed to sort it out with a bit of help and through another direction.

spence
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=5182
Tags : php two column Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: Two column rpoblem
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Sep 05, 2008, 07:29:08 AM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 36.290
Total Topics: 7.476
Total Members: 3.897
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: FlorianHofmann

20 Guests, 4 Users online :

14 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.