PDA

View Full Version : Kick Start Basics



AceTutor
01 Jun 2006, 09:02 AM
Greetings - am a absolute newbie to PHP/MySQL and would appreciate kickstart help

I have attempted tutorial at DMX Zone but failed without success.
See http://www.dmxzone.com/showDetail.asp?TypeId=2&NewsId=4937

Basic Setup:

Database: MySQL
id Name
0 Fruit
1 Banana
1 Pineapple
1 Kiwi Fruit
1 Apples
0 Vegetable
6 Tomatoes
6 Peas
6 Carrots


Output required:
Fruit
Apples
Banana
Kiwi Fruit
Pineapple
Vegetable
Carrots
Peas
Tomatoes

Requirement:
Depending on designated id, all items starting with 0 become bold category headings listed in alphbetical order and all associated products matching that category would be listed - also in alphabetical order.

A working code sample - or suggested tutorial sites would be greatfully received

Thanks in anticipation

Bless ya heaps

AceTutor

cdwhalley.com
01 Jun 2006, 12:08 PM
I noticed on that tutorial that the column sid was the one used, not id, but never mind.



<?php
$selected_id = 0;//The id to make bold
$query = "SELECT * FROM table";//Create the SQL query
$result = mysql_query($query);//Run the query
$while ($row = mysql_fetch_assoc($result)) {//Go through each row from the result, creating an array each time, with column names as the array keys
if ($row['id'] == $selected_id) {//If the id for that row is the same as the selected id
echo "<b>".$row['name']."</b>";//Output the name column for that row in bold
} else {
echo $row['name'];//Output the name column
}
echo "<br/>";//Put a line break, whatever happens
}//End of loop
?>