View Single Post
Old Dec 4th, 2007, 3:54 PM   #16
FireflyX
PHP God
 
FireflyX's Avatar
 
Join Date: Nov 2007
Location: Stockton, England
Posts: 15
Rep Power: 0 FireflyX is on a distinguished road
Send a message via MSN to FireflyX
Re: SELECT statement

<?
$host="localhost";
$username="----------";
$password="*******";
$db_name="kelvoron_testscripts";
$table_name="test1";

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tabLE_name WHERE gender='male'";
$result=mysql_query($sql);

while ($row = mysql_fetch_array($result)){

echo $row['name'];

}

mysql_close();
?>

Ok above is what i believe to be the simplest way to what you are trying to achieve. I changed SELECT name FROM to just SELECT * FROM because as you can see i am only selecting the name row. If you needed to output any other rows like you wanted to display the name then the gender you could put

echo $row['name']." - ".$row['gender'];

Hope that cleared things up a bit. I recommend reading here for further info http://www.tizag.com/mysqlTutorial/mysqlfetcharray.php
__________________
mysql_query("DELETE chavs FROM earth") or die("chavs");
FireflyX is offline   Reply With Quote