Results 1 to 2 of 2

Thread: PHP and mySql question..

  1. #1
    Cheeko
    Guest

    PHP and mySql question..

    Ok,

    Say I have a mySql database called MyDB and a table called MyTBL. It contains a persons name, age and an id for them. Like so:

    1 Peter 33
    2 Jason 36
    3 Mickey 49

    My question is, can someone give me a snippet of code that would access that db and tbl, then retrieve all entires, display them in a table one by one but is ordered by age, youngest first?

    Muchly Appereciated,

    Cheeko

  2. #2
    scoutt
    Guest
    well this is a shot in the dark as I have not tested it to see if it works.
    PHP Code:
      mysql_connect(location,  usernamepassword) or die("error opening the MySQL server");

      
    mysql_select_db(MyDB) die("error opening the MySQL Database");
      
    $result=mysql_query("select * from  MyTBL " order by age desc") or die("error querying the MySQL table");

          while (
    $row = mysql_fetch_array($result)) {
                       
            echo 
    $row["id"] $row["name"] $row["age"];
         } 

Posting Permissions

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



Click Here to Expand Forum to Full Width