I am quite new to php but def not to programming so alot of the logic is fairly straight fwd (?) considering my background.. I only have one problem and then i've finished my 1st php/sql web dev project! The follwing code displays two loops one being subcategory and then under each subcategory a list of companies lised in that category from a completely seperate db table. Thismay not be the easiest or most effiecent way of acomplishing this but it works.
**My problem comes into play bc it displays them each in their own table or in one single table column, I want to try to get these to diplay in one table with multiple rows and colums controled by the total number of subcategory results divided by two with out affecting the companies following each subcategory(table field). I've seen this done before but i just can't seem to get it into this code for some reason does anyone have any idea how to throw this into the loop?
Thanks in advance! Respect!
A copy of this script works @:
print '<table width="500" align="center" border="1" cellpadding="5" cellspacing="0"><tr><td>';
if(isset($GET['id'])) {
// clean up sql string
$ID = htmlspecialchars($GET['id']);
$sql = "SELECT
*
FROM resource_subcategory
WHERE cat_id = '$ID'
";
$result = mysql_query($sql)
or die("Invalid query: " . mysql_error());
while( $row = mysql_fetch_array($result, MYSQL_ASSOC) ){
$sub_id = $row['sub_id'];
$cat_id = $row['cat_id'];
$subcategory = $row['subcategory'];
$num = @mysql_num_rows($result);
$count = $result - $num;
if ($num >= 0){
echo "$subcategory<br><br>";
$sql2 = "SELECT
*
FROM resource_directory
WHERE 1
";
$result2 = mysql_query($sql2)
or die("Invalid query: " . mysql_error());
while( $row = mysql_fetch_array($result2, MYSQL_ASSOC) ){
$subcat_id = $row['subcat_id'];
$company = $row['Company'];
if ($sub_id == $subcat_id) {
echo "$company<br>";
}
}
echo "</td></tr></table>";
print '<table width="500" align="center" border="1" cellpadding="5" cellspacing="0"><tr><td>';
$num = $num - 1;
}
}
}
echo "</td></tr></table>"; ?>