Forum Moderators: open

Message Too Old, No Replies

MySQL get info from specific column

lil help

         

eaglesfreak

1:51 pm on May 27, 2007 (gmt 0)

10+ Year Member



I know you can use WHERE with SELECT to get row info from a table but i need to get an entire column of info, ignoring other columns. This is probaly a simple thing, but I have been searching and searching with no success. I am using PHP to communicate with my MySQL DB.

Basically, what i want to do is get all the info in one column of my DB and see if it matches to a PHP script that will display an html page based on the info in the column. Am i making sense?

Specific code would be great, i have found many tutorials that scratch at what i want to do(i think), but am having trouble applying it.

is it just as simple as

$result = mysql_query("SELECT * FROM example")
or die(mysql_error());

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

if so what do i do next? How can I only look at data from one column? How can my php script compare itself to the mysql column info? sorry for the stupid question.

Thanks in advanced for any help

barns101

7:38 pm on May 27, 2007 (gmt 0)

10+ Year Member



I think you want something like this:


$result = mysql_query("SELECT `column` FROM example")or die (mysql_error()); // Select only the relevant column

while($row = mysql_fetch_array( $result ))
{
if ($row[column_name] == 'whatever')
{
// Do whatever
}
}

eaglesfreak

9:29 pm on May 31, 2007 (gmt 0)

10+ Year Member



thats great! thanks alot