Now I need to create an array of links of guages (value) linking to a list of brands (both in table yarn_brand) held in a db. brand_id is the primary key. The array will be calculated from low_gauge and high_gauge .
This is table yarn_brand:
| brand_id
| brand_name
| manufacturer
| fiber_id
| low_gauge
| high_gauge
| price |
| description
I need the query to capture all yarns with gauges in a particular range e.g. all brands with guages between 1 and 2, or all brands with guages between 3 and 4.
I have written some functions that do similar things (below) but I need to build an array that isn't directly in the db. The array should look something like this //I realize this isn't correct
(1-2, 2-3, 3-4, 4-5, 5-6, 6-7)
Any suggestions?
Thanks
function get_brands($fiber_id)
{
// query database for the books in a category
if (!$fiber_id || $fiber_id=="")
return false;
$conn = db_connect();
$query = "select * from yarn_brand where fiber_id='$fiber_id'";
$result = @($query);
if (!$result)
return false;
$num_books = @mysql_num_rows($result);
if ($num_books ==0)
return false;
$result = db_result_to_array($result);
return $result;
}
//the following is a simplified version
function display_brands($brand_array)
{
//display all books in the array passed in
if (!is_array($brand_array))
{
echo "<br>No brands currently available in this category<br>";
}
else
{
//create table
echo "<table width = \"100%\" border = 0>";
//create a table row for each book
foreach ($brand_array as $row)
{
$url = "show_book.php?brand_id=".($row["brand_id"]);
echo "<tr><td>";
$title = $row["brand_name"]." by ".$row["manufacturer"];
do_html_url($url, $title);
echo "</td></tr>";
}
echo "</table>";
}
echo "<hr>";
}
//contained in the php template
// get the book info out from db
$brand_array = get_brands($fiber_id); //
display_brands($brand_array);