Display content from a specific cell

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
J0kerz
Forum Commoner
Posts: 37
Joined: Fri May 29, 2009 2:51 pm

Display content from a specific cell

Post 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:
User avatar
J0kerz
Forum Commoner
Posts: 37
Joined: Fri May 29, 2009 2:51 pm

Re: Display content from a specific cell

Post 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..
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Display content from a specific cell

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply