Solved

Using php need the following

Posted on 2011-03-23
4
268 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 SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
.htaccess 5 38
Determining creation & modification dates on MySQL tables 4 40
Download tables into separate sheets 3 28
Presenting past 6 months bug 7 30
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

803 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