Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 29th, 2007, 8:32 PM   #11
Kelvoron
Programmer
 
Kelvoron's Avatar
 
Join Date: Aug 2007
Location: Ohio
Posts: 46
Rep Power: 0 Kelvoron is on a distinguished road
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.
Kelvoron is offline   Reply With Quote
Old Nov 29th, 2007, 9:03 PM   #12
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: SELECT statement

Quote:
Originally Posted by pegasus001 View Post
The $host variable is a string by itself, try removing the double quotes.

Just a thought, though.
In PHP, double quotes are parsed for variable names.

$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".
Sane is offline   Reply With Quote
Old Nov 29th, 2007, 9:46 PM   #13
MiKuS
Hobbyist Programmer
 
Join Date: Jun 2007
Posts: 134
Rep Power: 2 MiKuS is on a distinguished road
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)
  1. $dbhost = 'localhost';
  2. $dbuser = 'your_user';
  3. $dbpass = 'user_password';
  4. $conn = mysql_connect($dbhost, $dbuser, $dbpass);
  5. mysql_select_db('your_database');
  6.  
  7. $sql="SELECT name FROM ".$table_name."WHERE gender='male'";
  8. $retval = mysql_query($sql, $conn );
  9. if (! $retval ) {
  10. print_r($sql);
  11. die('Could not get data: ' . mysql_error());
  12. }
  13. if ($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
  14. echo "<h1>{$row['gender']}</h1> ";
  15. }

I haven't checked the above code but it should work.
MiKuS is offline   Reply With Quote
Old Dec 2nd, 2007, 10:21 PM   #14
09jyoung
codemaniac
 
Join Date: Dec 2007
Posts: 9
Rep Power: 0 09jyoung is on a distinguished road
Smile Re: SELECT statement

here's what your SELECT statement should look like:
$sql = "SELECT name FROM " . $table_name . " WHERE gender='male';";
09jyoung is offline   Reply With Quote
Old Dec 2nd, 2007, 11:11 PM   #15
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: SELECT statement

09jyoung... his select statement was fine. Read before posting. Discussion over.
Sane is offline   Reply With Quote
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
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:53 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC