Page 1 of 1

Display content from a specific cell

Posted: Fri May 29, 2009 2:59 pm
by J0kerz
Hey guys,

I dont seem to understand how can I display the content of a specific cell in one of my table...

My table setup is as follow:

Image

There are only one element in each column ( + column title )

I know the name of the column and I want to retrieve the content of the cell under it. So let's say I call name 4, I want to have the content of the cell under it.

I have no problem connecting to the database.

My table name is: storage_date

I am using this as first but how can I display the content of the cell, or store it into a variable.

Code: Select all

$result = mysql_query("SELECT name1 from storage_data")or die(mysql_error());
Thanks alot! :wink:

Re: Display content from a specific cell

Posted: Fri May 29, 2009 3:09 pm
by J0kerz
I can do such things:

Code: Select all

$result = mysql_query("SELECT name1 FROM storage_data")or die(mysql_error()); 
while ($content = mysql_fetch_array($result)) 
{
    echo "$content[name1]";
}
It works, but I dont wanna do a loop when I already know the column..

Re: Display content from a specific cell

Posted: Fri May 29, 2009 3:23 pm
by VladSun
J0kerz wrote:I can do such things:

Code: Select all

$result = mysql_query("SELECT name1 FROM storage_data")or die(mysql_error()); 
while ($content = mysql_fetch_array($result)) 
{
    echo "$content[name1]";
}
It works, but I dont wanna do a loop when I already know the column..
You are looping through rows, not columns. So, instead of a while() you can use if(), if it's only one cell (i.e. on row) to display.