Jump to content

Echo Specific Column


Solar

Recommended Posts

Say I have a forum with tables that look like this in the mysql database;

 

fidforumdesccat

1GeneralTalk About Anythinggeneral

2HobbiesTalk About Hobbiesgeneral

3HTML HelpGet help on HTMLhelp

 

How can I use this;

$sql="SELECT * FROM $tbl_name ORDER BY fid";

By grabbing just the one column for example general?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/199920-echo-specific-column/
Share on other sites

$sql="SELECT '<column_name>' FROM $tbl_name ORDER BY fid";

for instance

$sql="SELECT 'forum' FROM $tbl_name ORDER BY fid";

and if you want more than one column, concatenate them with a comma:

$sql="SELECT 'fid', 'forum' FROM $tbl_name ORDER BY fid";

Why did you place the column names in quotes? That's not needed, perhaps you meant to use backticks (`)? Backticks aren't even required, and not suggested, unless you're using reserved words for your column names which you really shouldn't be doing in the first place.

Why did you place the column names in quotes? That's not needed, perhaps you meant to use backticks (`)? Backticks aren't even required, and not suggested, unless you're using reserved words for your column names which you really shouldn't be doing in the first place.

 

you are right...

they are not needed...

sorry about that

 

 

Oops, I understand that. Doh, silly me.

 

I know how to echo the specific column, what I meant was...

 

Echo the table I provided (Which I have coded) but only show the forum with the specific category for example;

 

fidforumdesccat

1GeneralTalk About Anythinggeneral

2HobbiesTalk About Hobbiesgeneral

3HTML HelpGet help on HTMLhelp

 

Will result into php coding;

fidforumdesccat

1GeneralTalk About Anythinggeneral

2HobbiesTalk About Hobbiesgeneral

 

<td bgcolor="#FFFFFF"><? echo $rows['forum']; ?><BR><span class="style1"><? echo $rows['desc']; ?></span></td>

 

But using;

$sql="SELECT * FROM $tbl_name ORDER BY fid";

Do I use a whereas in this statement?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.