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
Solved

Using php need the following

Posted on 2011-03-23
4
269 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Currency in SQL? 2 30
Split wordpress loop 35 56
Extracting store locations from Google maps or site 2 22
TCPDF - Create PDF from Form Values and Link to PDF Download 7 25
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
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…
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.

856 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