Forum Moderators: coopster

Message Too Old, No Replies

Alphabetize by state, add checkbox

         

danielm28

6:33 pm on Apr 2, 2005 (gmt 0)

10+ Year Member



I need to display a list of dealers on screen that are grouped by state and alphabetized. All states need to be shown.

For Example,

Column1--> AK
Result 1--> alphabetized list of dealers in AK

Column2--> AL
Result 2--> alphabetized list of dealers in AL

In addition, each dealer needs to have a checkbox next to delaer name.

What query do I need to send to the database?
How can I format the page results so that all states appear on screen in an easy to read format?

thanks

ergophobe

5:41 pm on Apr 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I can't say what query to send without knowing more aobut your DB, but it would be something like one of these

SELECT state_name, dealer_name FROM dealers ORDER BY state_name, dealer_name

or, if you have a bit more complex DB

SELECT s.state_name, d.dealer_name
FROM dealers d, states s
WHERE d.state_id=s.state_id
ORDER BY s.state_name, d.dealer_name

danielm28

11:13 pm on Apr 3, 2005 (gmt 0)

10+ Year Member



the field names are in the following query:

"select dealer_id, name, city,zip FROM `dealer` order by state,name"

I need to be able to show all states and associated dealers alphabetized. I would like state to be the column header
and dealers with a checkbox next to name underneath.

Thanks for your assistance

ergophobe

4:53 pm on Apr 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Loop through your result set and check to see whether or not the "state" field changes. When it does, start a new column.

danielm28

1:37 am on Apr 7, 2005 (gmt 0)

10+ Year Member



could you provide an example of that looping code?

ergophobe

8:39 pm on Apr 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sure,

Let's say, for example, that you have done the SELECT mentioned and your result set has $row['dealer'' and $row['state']

$num_cols = 4; // or however many you have
$state = '';
$table = '<table>';
while ($row = mysql_fetch_assoc($result))
{

if ($state!= $row['state'])
{
$table .= '<tr><td class="state_header" colspan="' . $num_cols . '">' . $row['state'] . '</td></tr>';
}
$table .= '<tr class="dealer">
<td>'. $row['dealer_name'] . '</td>
<td>'. $row['dealer_street'] . '</td>
<td>'. $row['dealer_city'] . '</td>
<td>'. $row['dealer_zip'] . '</td>
</tr>';
}

$table .= '</table>';

Something along those lines

danielm28

8:02 pm on Apr 9, 2005 (gmt 0)

10+ Year Member



that worked thanks.