Been working on this script for 5 days, got one issue fixed, but the solution has caused a new problem that I’ve been pulling my hair out over. When the Subcategory is showing, I’m trying to get all the selected data from from each listing that has the same Subcategory to be in the same column. Right now, it works fine as long as there is only one listing, but if there are 2 or more it puts the data in the next column.
Pretty sure I need to loop through the data until there are no more listings for that Subcategory. But I have tried a for loop, a foreach (which I’ve never been able to get working) and a nested while loop, all with funky results. Which is probably because I did something wrong. Not sure if I’m putting it in the wrong place or if I’m constructing it wrong, But I could sure use some help with this!
This is the code I think I need to loop through
[CODE]////Data to shown for each business listing of the same Subcategory if ($row[‘udURL’] == “”){ echo “<font face=”Verdana”>{$row[‘Bname’]}</font>”; }else{ echo “<a href=”http://{$row[‘udURL’]}”><font face=”Verdana”>{$row[‘Bname’]}</font></a>”; } echo “<br>”; if ($row[‘Slogan’] != ”) { echo “<font face=”Verdana” size=2><i>{$row[‘Slogan’]}</i></font><br>”; } if (($row[‘TFPhone’] != “”) && ($row[‘LPhone’] != “”)){echo “<font face=”Verdana” size=2>{$row[‘TFPhone’]} / {$row[‘LPhone’]}<br></font>”; }else{ echo “<font face=”Verdana” size=2>{$row[‘TFPhone’]} {$row[‘LPhone’]}<br></font>”; } if ($row[‘CLSmap’] == ‘Y’){ echo “<font face=”Verdana” size=2><a href=”maps/maps.php?IDENT={$row[‘ID’]}” target=”_blank”>Map/Directions</a></font>”; } ////END of data to be shown for each business with the same Subcategory
ENTIRE SCRIPT to show the current interactions (I have it online for testing at [URL=”http://www.citylifesites.com/services.php?CLSfolder=pinehurst-nc&City=Pinehurst&State=NC”]http://www.citylifesites.com/services.php?CLSfolder=pinehurst-nc&City=Pinehurst&State=NC
[CODE]$last_subcategory = ”;
$last_category = ”; // initialize variable to detect a change in the category. Set to a value that will never exist as data
$columns = 3; // number of columns in a table row
$count = 0; // counter to track current column in the table row
$sub = mysql_query(“SELECT * FROM $DBTABLE WHERE (CLSfolder=’$selectedCLSfolder’) && (Active=’Y’) ORDER BY Category, Subcategory”);
echo “<table width=”98%” align=”center”>n”; // overall table (whatever you current have…)
while($row = mysql_fetch_array($sub)){
// check for a new Category and output the heading when the Category changes –
if($last_category != $row[‘Category’]){
// if $count is not 0, finish any previous partial row/section of Subcategory data
if($count != 0){
// finish the current row
while($count % $columns != 0){
echo “<td> </td>”;
$count++;
}
// close the row/section
echo “</tr>n</table>n”;
}
// output the Category heading
echo “<tr><td colspan=3> </td></tr><tr><td valign=”top” bgcolor=”#FDD9BA”>”;
echo “<font face=”Verdana”><b>{$row[‘Category’]}</b></font></td></tr>n”;
$last_category = $row[‘Category’]; // remember the new Category
$count = 0; // reset the count (new set of rows)
}
// at this point, you have Subcategory data to display
// if $count == 0, need to start a new section for the Subcategory data
if($count == 0){
echo “<tr><td><TABLE width=”100%” border=0 align=”center”>n<tr>”;
} elseif($count % $columns == 0) {
// if count is not 0 and $count % $columns == 0, need to finish previous row and start a new one
echo “</tr>n<tr>”;
}
// display the actual Subcategory data –
echo “<td width=”33%” align=”left” valign=”top”>”;
if ($row[‘Subcategory’] == ‘None’){
$row[‘Subcategory’]=”View All “.$row[‘Category’];}
if($last_subcategory != $row[‘Subcategory’]){
echo “<ul id=”{$row[‘Subcategory’]}” class=”treeview”>
<font face=”Verdana” size=2><li><b>{$row[‘Subcategory’]}</b></font><br><br>
<ul>”;
}
////Data to shown for each business listing of the same Subcategory
if ($row[‘udURL’] == “”){
echo “<font face=”Verdana”>{$row[‘Bname’]}</font>”;
}else{
echo “<a href=”http://{$row[‘udURL’]}”><font face=”Verdana”>{$row[‘Bname’]}</font></a>”;
}
echo “<br>”;
if ($row[‘Slogan’] != ”)
{
echo “<font face=”Verdana” size=2><i>{$row[‘Slogan’]}</i></font><br>”;
}
if (($row[‘TFPhone’] != “”) && ($row[‘LPhone’] != “”)){echo “<font face=”Verdana” size=2>{$row[‘TFPhone’]} / {$row[‘LPhone’]}<br></font>”;
}else{
echo “<font face=”Verdana” size=2>{$row[‘TFPhone’]} {$row[‘LPhone’]}<br></font>”;
}
if ($row[‘CLSmap’] == ‘Y’){
echo “<font face=”Verdana” size=2><a href=”maps/maps.php?IDENT={$row[‘ID’]}” target=”_blank”>Map/Directions</a></font>”;}
///END of data to be shown for each business with the same Subcategory
echo”</li></ul> </li></ul>”;
echo ”
<script type=”text/javascript”>
ddtreemenu.createTree(“{$row[‘Subcategory’]}”, false)
</script></td>
“;
$last_subcategory = $row[‘Subcategory’];
$count++; // count one Subcategory
} // end of while loop
// if $count is not 0, finish any previous partial row/section of Subcategory data
if($count != 0){
while($count % $columns != 0){
echo “<td> </td>”;
$count++;
}
// close the row/section
echo “</tr>n</table>”;
}
echo “</table>n”; // close overall table