Results 1 to 2 of 2

Thread: Kick Start Basics

  1. #1
    Join Date
    Mar 2006
    Location
    Queensland, Australia
    Posts
    5

    Kick Start Basics

    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.as...=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

  2. #2
    Join Date
    Apr 2006
    Posts
    74
    I noticed on that tutorial that the column sid was the one used, not id, but never mind.

    PHP Code:
    <?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
    ?>

Similar Threads

  1. Easy Way to Start an Online Business
    By nakosy in forum General Questions
    Replies: 0
    Last Post: 11 Apr 2006, 01:38 AM
  2. Where to start?
    By ProcalX in forum General Questions
    Replies: 1
    Last Post: 20 Jan 2006, 06:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •