Solved

Using php need the following

Posted on 2011-03-23
4
266 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
  • 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 500 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now