Link to home
Start Free TrialLog in
Avatar of stargateatlantis
stargateatlantis

asked on

Using php need the following

Lets say you have a MySQL table called “users”  that contains the following fields  
“Name”,  “Age”,  “email”,  “address” with the following data Also the database name would be myCustomers

Mike Smith,  29,  msmith@mydomain.com,   My Street
John Doe,  42,  bfranklin@mydomain.com,  My Street
Kevin, Smith, 32, mjones@mydomain.com,   My Street
Kathy Bates, 55, ttomlinson@mydomain.com, My Street



Using MySQL statements and PHP,  please display a list of first names and ages,  sorted by age.
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

Not tested, but try like this

$link = mysql_connect("host","user","pass") or die(mysql_error());
mysql_select_db() or die(mysql_error());
$query = "select * from users order by age asc";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){
 $name = explode(" ",$row[Name]);
 echo"$name[0], $row[Age]<br />";
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stargateatlantis
stargateatlantis

ASKER

Is everything good now ?
You tell me :) Should be, mind that you need to enter your mysql connection data, usualy host is localhost, your username and pass - well you know them.