feyd,
Thanks for the reply and the links. Sorry about not conforming to proper techniques. I have been trying to muck throuhg this for some time now. I am just a hobbiest when it comes to programming. The basics I can handle but once I get into loops and variables I get lost. Some day I hope to get some formal training. Anyway, I was trying basically what was in that second link under
Useful Posts.
It seems that I get all the results from the first query followed by the results from the second query.
My database looks something like this:
Code: Select all
+---+------------------------+----------+--------------+
|id | group_name | town | address |
+---+------------------------+----------+--------------+
|16 | MID-ISLAND | BABYLON | United Method|
|17 | OFF MAIN STREET | BABYLON | Christ Episco|
|18 | BRIDGE GROUP | BAYSHORE | Captree State|
|19 | GOODY GUYS | BAYSHORE | Bay Shore YMC|
|20 | HOLBROOK GROUP | HOLBROOK | Christ Episco|
|21 | NUTS & BOLTS GROUP | HOLBROOK | Cross of Chri|
|22 | CRAZY MEN | HOLBROOK | Christ Episco|
|23 | FRIENDSHIP | HOLBROOK | Robert Moses |
+---+------------------------+----------+--------------+
I started with output like this:
Code: Select all
TOWN: BABYLON
GROUP: MID-ISLAND
ADDRESS: UNITED METHOD
----------------------------------------------------
TOWN: BABYLON
GROUP: OFF MAIN STREET
ADDRESS: CHRIST EPISCO
----------------------------------------------------
TOWN: BAYSHORE
GROUP1 IN BAYSHORE
----------------------------------------------------
TOWN: BAYSHORE
GROUP2 IN BAYSHORE
----------------------------------------------------
TOWN: BAYSHORE
GROUP3 IN BAYSHORE
----------------------------------------------------
TOWN: BAYSHORE
GROUP1 IN HOLBROOK
----------------------------------------------------
TOWN: BAYSHORE
GROUP2 IN HOLBROOK
-----------------------------------------------------
ETC...
I am trying to get the output to look like this:
Code: Select all
TOWN: BABYLON
-----------------------------------------------------------------
-----------------------------------------------------------------
GROUP: MID-ISLAND
ADDRESS: UNITED METHOD
--------------------------------------------------------
GROUP: OFF MAIN STREET
ADDRESS: CHRIST EPISCO
--------------------------------------------------------
TOWN: BAYSHORE
-----------------------------------------------------------------
-----------------------------------------------------------------
GROUPS IN BAYSHORE
--------------------------------------------------------
TOWN: HOLBROOK
-----------------------------------------------------------------
-----------------------------------------------------------------
GROUPS IN HOLBROOK
-----------------------------------------------------------------
ETC...
Using code from the link you provided which is basically what I was trying before I posted by output was in the form of:
Code: Select all
BABYLON
--------------------
BAYSHORE
--------------------
HOLBROOK
--------------------
GROUP
--------------------
GROUP
--------------------
GROUP
--------------------
Here is my php code:
Code: Select all
// $b is a value from a drop down menu. value = town name
$query = sprintf( "SELECT * FROM `meeting` WHERE town = '$b' order by town");
$query2 = sprintf( "SELECT town FROM `meeting` WHERE town = '$b' group by town");
// Perform Query
$result = mysql_query($query);
$result2 = mysql_query($query2);
$num_rows = mysql_num_rows($result2);
$i=0;
///////////////////////////////////////////////////
while ($row = mysql_fetch_assoc($result2)) {
$town_name = $row['town'];
$i++;
//
if ($i == $num_rows) {
echo "<b>$town_name</b>:"; }
else
//
{echo "<b>$town_name</b>:"; }
}
////////////////////////////////////////////////////
echo "<BR><BR>";
///////////////////////////
while ($row = mysql_fetch_array($result)) {
$town_name1 = $row['town'];
$group_name = $row['group_name'];
$address = $row['address'];
$array_town = ($row['town']);
if ($array_town != $town_name) {
$town_name = $array_town;
echo "GROUP:$group_name";
echo "<BR>";
echo "ADDRESS:$address";
echo "<HR>";
}
else
echo "<HR>";
}
I appreciate any insite to this. I understand that the first while is being fully completed. This gives me a list of towns. Then the second while runs and gives me all the groups. What I want is the first while to give the the first town and then something to give me all the groups in that town, go back to the first while get the next town and all the groups for that town, etc...
If coding was only as easy as english

.
Thanks again. I am totally willing to read and learn.
Steve