Beginner, needing help splitting results into two columns.
Posted: Thu Sep 07, 2006 3:20 am
Hello,
I'm new to php, I don't know a lot yet about php but I can edit existing code, play around with it. What I need to do today is take a script I have which outputs a list of categories and subcategories. I want to make it list the categories in 2 columns side-by-side.
Like this: <div class="left_side">Categories</div> <div class="right_side">Categories</div>
The template uses <?=$categories?> to call the list of categories.
I need to edit my existing code to be able to do this, there is no defined number of categories, as more may be added as time goes by, so it just needs to split it exactly in the middle. This is the code I am working with.
The code works fine, I just need to make it show 2 columns, if anyone could help me out that would be great. I've been searchihng for days and trying things I find but don't quite know how to implement it into my code.
Thanks.
I'm new to php, I don't know a lot yet about php but I can edit existing code, play around with it. What I need to do today is take a script I have which outputs a list of categories and subcategories. I want to make it list the categories in 2 columns side-by-side.
Like this: <div class="left_side">Categories</div> <div class="right_side">Categories</div>
The template uses <?=$categories?> to call the list of categories.
I need to edit my existing code to be able to do this, there is no defined number of categories, as more may be added as time goes by, so it just needs to split it exactly in the middle. This is the code I am working with.
Code: Select all
//create categories
$qc = "select * from dd_categories order by CategoryName";
$rc = mysql_query($qc) or die(mysql_error());
if(mysql_num_rows($rc) > '0')
{
while($ac = mysql_fetch_array($rc))
{
//get the items number at this category
$qin = "select count(*) from dd_items where ItemCategory = '$ac[CategoryID]' and ItemStatus = 'approved' ";
$rin = mysql_query($qin) or die(mysql_error());
$ain = mysql_fetch_array($rin);
$categories .= "<p><img src=\"images/arrow.gif\" alt=\">\" /><a class=\"title\" href=\"ShowCategory.php?CategoryID=$ac[CategoryID]\"><b>$ac[CategoryName]</b></a><br />\n\t\t\t";
//get the subcategories
$qsc = "select * from dd_subcategories where CategoryID = '$ac[CategoryID]' order by SubcategoryName Limit 3";
$rsc = mysql_query($qsc) or die(mysql_error());
if(mysql_num_rows($rsc) > '0')
{
$categories .= "<span>";
while($asc = mysql_fetch_array($rsc))
{
// add comma after subcategory
if(!is_null($subcategories))
$subcategories .= ", ";
//get the items number at this subcategory
$qin2 = "select count(*) from dd_items where ItemCategory = '$ac[CategoryID]' and ItemSubcategory = '$asc[SubcategoryID]' and ItemStatus = 'approved' ";
$rin2 = mysql_query($qin2) or die(mysql_error());
$ain2 = mysql_fetch_array($rin2);
$subcategories .= "<a href=\"ShowCategory.php?CategoryID=$ac[CategoryID]&SubcategoryID=$asc[SubcategoryID]\">$asc[SubcategoryName]</a>";
}
$categories .= $subcategories;
$categories .= "...</span></p>";
$subcategories = NULL;
}
}
}Thanks.