Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using php need the following

Posted on 2011-03-23
4
Medium Priority
?
274 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:stargateatlantis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35201632
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

0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 2000 total points
ID: 35201639
Sorry, missing the db name:

$link = mysql_connect("host","user","pass") or die(mysql_error());
mysql_select_db("myCustomers") 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

0
 

Author Comment

by:stargateatlantis
ID: 35201721
Is everything good now ?
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35201758
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.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question