![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Programmer
Join Date: Aug 2007
Location: Ohio
Posts: 46
Rep Power: 0
![]() |
Re: SELECT statement
thanks every one i will look up the fetch function tonight at work
__________________
Good better best, never let it rest, untill your good is better and your better is the best. |
|
|
|
|
|
#12 | |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Re: SELECT statement
Quote:
$name = 'PFO'; // Outputs: PFO echo $name; // Outputs: PFO echo "$name"; // Outputs: Hello PFO echo "Hello $name"; // Outputs: Hello $name echo 'Hello $name'; So you were correct in a way, since the double quotes are completely pointless. $host is the exact same as "$host". |
|
|
|
|
|
|
#13 |
|
Programmer
Join Date: Jun 2007
Posts: 93
Rep Power: 2
![]() |
Re: SELECT statement
I suggest working with this tutorial so you understand the basics of database functionality
http://www.phpfreaks.com/tutorials/142/0.php php Syntax (Toggle Plain Text)
I haven't checked the above code but it should work. |
|
|
|
|
|
#14 |
|
codemaniac
Join Date: Dec 2007
Posts: 9
Rep Power: 0
![]() |
here's what your SELECT statement should look like:
$sql = "SELECT name FROM " . $table_name . " WHERE gender='male';"; |
|
|
|
|
|
#15 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Re: SELECT statement
09jyoung... his select statement was fine. Read before posting. Discussion over.
|
|
|
|
|
|
#16 |
|
PHP God
|
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"); |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SQL Select Statement Performance | King | Other Scripting Languages | 6 | Dec 1st, 2006 5:12 PM |
| Allow user to select a directory | MegaArcon | HTML / XHTML / CSS | 11 | Jun 5th, 2006 8:38 AM |
| reloading html select boxs...is there a better way? | MegaArcon | Python | 13 | May 26th, 2006 3:06 AM |
| sockets, problem with select() | Wizard1988 | C++ | 0 | Jan 15th, 2006 4:09 PM |
| Trouble with a swith statement | cjaime | C | 10 | Nov 8th, 2005 11:09 AM |