Skip to content

MySQL SELECT

As I mentioned first,

table_id name gender age
1 PersonX male 21
2 PersonY female 20
3 PersonZ female 22

i’ll show how to select the records from the tabel,

Query

SELECT name FROM table_name;

output
name
PersonX
PersonY
PersonZ

Now, i’ll show you how to retrieve and display in php,

<?php 
// SELECT * FROM table_name 
// SELECT name FROM table_name WHERE table_id = '1';
// SELECT gender, age FROM table_name WHERE name = 'PersonX';
$sql = mysql_query("SELECT name FROM table_name"); 
echo $count = mysql_num_rows($sql);
// print count of records
while($res = mysql_fetch_array($sql));
{
    echo "<pre>"; print_r($res);
}
?>
Output
/* i've used mysql_fetch_array() so it retrieves */
Array ( [0] => PersonX [name] => PersonX ) 
Array ( [1] => PersonY [name] => PersonY ) 
Array ( [2] => PersonZ [name] => PersonZ ) 
/* mysql_fetch_row() it retrieves*/
Array ( [0] => PersonX ) 
Array ( [1] => PersonY ) 
Array ( [2] => PersonZ ) 
/* mysql_fetch_assoc() it retrieves*/
Array ( [name] => PersonX ) 
Array ( [name] => PersonY )
Array ( [name] => PersonZ ) 

More MySql Functions

<< Back

MySql Join

One Comment
  1. Aravind permalink

    yeahhh sure..
    thnx a lot….:)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: