Forum Moderators: coopster
// mysql structure
table: manufacturers
man_id
man_name
sort // order to be displayed among other manufacturers (INT)
table: series
series_id
series_name
series_man // associated man_id (INT)
sort // order to be displayed among other series (INT)
table: products
prod_id
prod_name
prod_series // associated series_id (INT)
sort // order to be displayed among other products (INT)
// end result for each manufacturer and related series, products. This block would replicate for each manufacturer
<h2>man_name</h2>
<div>
<h3>series_name</h3>
<div>
<ol>
<li>prod_name</li>
<li>prod_name</li>
</ol>
</div>
<h3>series_name</h3>
<div>
<ol>
<li>prod_name</li>
<li>prod_name</li>
</ol>
</div>
</div>
I suck at joins in the worst way
SELECT m.man_name, s.series_name, p.prod_name
FROM products AS p
INNER JOIN series AS s ON s.series_id = p.prod_series
INNER JOIN manufacturers AS m ON m.man_id = s.series_man
ORDER BY m.order, s.order, p.order ;
$result = mysql_query("
SELECT
products.prod_id,
products.prod_name,
products.prod_image,
products.prod_series,
series.series_id,
series.series_name,
series.series_man,
manufacturers.man_id,
manufacturers.man_name
"."
FROM
products,
series,
manufacturers
"."
WHERE
products.prod_image IS NOT NULL
"."
AND
products.prod_series = series.series_id
"."
AND
series.series_man = manufacturers.man_id
") or die(mysql_error());
SELECT
products.prod_id,
products.prod_name,
products.prod_image,
products.prod_series,
series.series_id,
series.series_name,
series.series_man,
manufacturers.man_id,
manufacturers.man_name
FROM
products
INNER JOIN series ON products.prod_series = series.series_id
INNER JOIN manufacturers ON series.series_man = manufacturers.man_id
WHERE
products.prod_image IS NOT NULL
// grab manufacturer info
$manresult = mysql_query("SELECT man_id, man_name FROM manufacturers") or die(mysql_error());
while($manrow = mysql_fetch_array( $manresult )) {
// start building menu with mans
echo '<h2>'.$manrow['man_name'].'</h2>
<div>'.PHP_EOL;
// grab series info
$seriesresult = mysql_query("SELECT series_id, series_name, series_man FROM series WHERE series_man = '".$manrow['man_id']."' ORDER BY sort ASC") or die(mysql_error());
while($seriesrow = mysql_fetch_array ( $seriesresult )) {
echo '<h3>'.$seriesrow['series_name'].'</h3>'.PHP_EOL;
echo '<div>
<ol>'.PHP_EOL;
// grab product info
$prodresult = mysql_query("SELECT prod_id, prod_name, prod_series FROM products WHERE prod_series = '".$seriesrow['series_id']."' ORDER BY sort ASC") or die(mysql_error());
while($prodrow = mysql_fetch_array ( $prodresult )) {
echo '<li><a href="products.php?id='.$prodrow['prod_id'].'">'.$prodrow['prod_name'].'</a></li>'.PHP_EOL;
}
echo '</ol>
</div>
</div>'.PHP_EOL;
}
}
SELECT m.man_name, s.series_name, p.prod_name
FROM products AS p
INNER JOIN series AS s ON s.series_id = p.prod_series
INNER JOIN manufacturers AS m ON m.man_id = s.series_man
ORDER BY m.order, s.order, p.order ;