Solar Posted April 27, 2010 Share Posted April 27, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/199920-echo-specific-column/ Share on other sites More sharing options...
dgoosens Posted April 27, 2010 Share Posted April 27, 2010 $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"; Quote Link to comment https://forums.phpfreaks.com/topic/199920-echo-specific-column/#findComment-1049316 Share on other sites More sharing options...
Alex Posted April 27, 2010 Share Posted April 27, 2010 $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. Quote Link to comment https://forums.phpfreaks.com/topic/199920-echo-specific-column/#findComment-1049319 Share on other sites More sharing options...
dgoosens Posted April 27, 2010 Share Posted April 27, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/199920-echo-specific-column/#findComment-1049320 Share on other sites More sharing options...
Solar Posted April 27, 2010 Author Share Posted April 27, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/199920-echo-specific-column/#findComment-1049325 Share on other sites More sharing options...
Alex Posted April 27, 2010 Share Posted April 27, 2010 You need to use a where clause. Example: $sql="SELECT * FROM $tbl_name WHERE cat='general' ORDER BY fid"; Quote Link to comment https://forums.phpfreaks.com/topic/199920-echo-specific-column/#findComment-1049328 Share on other sites More sharing options...
Solar Posted April 27, 2010 Author Share Posted April 27, 2010 Haha thanks! Works like a charm, of course when I tried I missed out the ' Quote Link to comment https://forums.phpfreaks.com/topic/199920-echo-specific-column/#findComment-1049334 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.