I have a dynamic number of "category_names.table2, optionvalue.table2" in my query.
These "category_names" are joined with the dynamic "type.table1, name.table1, street.table1, city.table1, state.table1, zip.table1, phone.table1."
The type.table1 & optionvalue.table2 are the common between the 2 tables. The type and optionvalue are always a letter and a number (i.e.) 'K1', 'K2', etc. but the number of them is not always the same. There could be 1 or 20.
This code will echo them exactly as I have instructed, but it's not what I need.
Code:
$result = mysql_query($query) or print mysql_error();
$num_results = mysql_num_rows($result);
for ($i=0; $i < $num_results; $i++)
while ($row = mysql_fetch_array($result))
{
$type=$row["type"];
$name=$row["name"];
$street=$row["street"];
$city=$row["city"];
$state=$row["state"];
$zip=$row["zip"];
$phone=$row["phone"];
$category_name=$row["category_name"];
echo "$num_results<br>";
echo "<u>$category_name</u><br>";
echo "$name<br>" .
"$street<br>" .
"$city, $state $zip<br>" .
"$phone<br>";
}
Produces the following....
173
Italian Restaurants
Joe's Pizza
1234 Sauce Street
Pizzatown, NY 90000
(212) 555-1212
Italian Restaurants
Cicilia's Italian Restaurant
333 S. Cheese Lane
Lasagna, IL 95000
(432) 555-1212
Chinese Restaurants
Fortune Cookie Heaven
4321 Chow Mein Rd.
Chopstix, CA 92001
(310) 555-1212
Chinese Restaurants
Wang Ling Palace
4444 Beef Broccoli Way
Pork, TX 92001
(414) 555-1212
With all 173 results echoing respectively below their "$category_name."
What I need is..
Italian Restaurants
Joe's Pizza
1234 Sauce Street
Pizzatown, NY 90000
(212) 555-1212
Cicilia's Restaurant
333 S. Cheese Lane
Lasagna, IL 95000
(432) 555-1212
Chinese Restaurants
Fortune Cookie Heaven
4321 Chow Mein Rd.
Chopstix, CA 92001
(310) 555-1212
Wang Ling Palace
4444 Beef Broccoli Way
Pork, TX 92001
(414) 555-1212
I have tried moving the echo outside the loop, however I ONLY get the final record.
I have tried mixing code - exiting php, listing the category in HTML then re-entering php, but the same thing happens.
I have tried several other rudimentary ideas by searching the WWW, and reading "PHP & MySql" - (Luke Willing & Laura Thompson) as well as "Learning PHP & MySql" (Michele Davis & John Phillips). I have been able to follow various coding ideas which ultimately parse properly and echo results, but CANNOT get the category_names to echo ONCE with their respective names, street, etc... below the categories.
Can anyone
POINT me in the right direction - I don't need anyone to DO this for me exactly -> however some guidance is requested as I am clearly not getting it.
I do beleive that what I need is a multi-dimensional array but I just can't wrap my head around creating it using dynamic $variables.
Thanks.