SELECT a specific value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
LuaMadman
Forum Commoner
Posts: 35
Joined: Tue Jul 20, 2010 6:58 am

SELECT a specific value

Post by LuaMadman »

I just started using mysql.
I manage to connect to the database just fine, but i got a problem getting a column.
First i ran the following sql statement to get my table.

Code: Select all

CREATE TABLE bytin(
notloggedin TEXT NOT NULL);
INSERT INTO (notloggedin) values ("My Text")
Then in my php file i try to retive My Text
I manged to get the value using

Code: Select all

		Not logged in...<br/>
<?php
		$sql = "SELECT * FROM bytin";
		$result = mysql_query($sql);
		print($result . '<br/>');
		while($line = mysql_fetch_array($result)) {
			print($line['notloggedin']);
		}
However, accoring to me this would print notloggedin text twice, if i was to add another column.
So no matter what, it's a bad and ugly soluion.
This gives

Code: Select all

Not logged in...
Resource id #369
My Text
If it would been an array, i figuer it would be like this
bytin(
notloggedin = "My Text",
)
Beacuse then i would just need to get the value of the notlogged in key. That is what i'm trying to accaomplis here.

Hope i made some sense on what i want.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: SELECT a specific value

Post by Jade »

Code: Select all

<?php
                $sql = "SELECT * FROM bytin"; //here's your query
                $result = mysql_query($sql) or die (mysql_error()); //this is a mysql resource ID, not the results
                 $row = mysql_fetch_array($result); //this is your result of your query
                print_r($row);
               echo $row['notloggedin'];
?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: SELECT a specific value

Post by John Cartwright »

Be careful when describing things in technical terms. Columns != rows.
User avatar
LuaMadman
Forum Commoner
Posts: 35
Joined: Tue Jul 20, 2010 6:58 am

Re: SELECT a specific value

Post by LuaMadman »

Thanks for the help.

As for the $result var, i pretty much copied the code from a book, so when it said result, I asumed it meant, that i was my result.
So thanks for explaining exactly what it was.
Post Reply