dynamicgfx Posted December 29, 2011 Share Posted December 29, 2011 i have this code but it shows the password of the user to... <?php $database="dynamicg_sites"; mysql_connect ("localhost","dynamicg_sites","boom123"); @mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query( "SELECT * FROM sites order by votes DESC" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "<br>\n"; print "There are $num_rows News Articles"; print "<br>\n"; print "<table width=457 border=0>\n"; print "<tr>\n"; print "<td>\n"; echo "Title:"; print "</td>\n"; print "<td>\n"; echo "Description:"; print "</td>\n"; print "<td>\n"; echo "Votes:"; print "</td>\n"; print "</tr>\n"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; foreach ($get_info as $field) print "\t<td><font face=arial size=2/>$field</font></td>\n"; print "</tr>\n"; } print "</table>\n"; print "<br />\n"; print "<br />\n"; ?> i was wondering how do i make this only show certain columns... thanks in advance... Quote Link to comment https://forums.phpfreaks.com/topic/254022-need-help-to-show-only-certain-columns/ Share on other sites More sharing options...
Muddy_Funster Posted December 29, 2011 Share Posted December 29, 2011 Don't use SELECT * for a start. You should also make your mind up whether you want to use print or echo (instread of mixing them both through the code), and deffinately get rid of the @ at the start of your mysql_select_db() line. Quote Link to comment https://forums.phpfreaks.com/topic/254022-need-help-to-show-only-certain-columns/#findComment-1302203 Share on other sites More sharing options...
dynamicgfx Posted December 29, 2011 Author Share Posted December 29, 2011 Don't use SELECT * for a start. You should also make your mind up whether you want to use print or echo (instread of mixing them both through the code), and deffinately get rid of the @ at the start of your mysql_select_db() line. thts not wat im asking learn to read Quote Link to comment https://forums.phpfreaks.com/topic/254022-need-help-to-show-only-certain-columns/#findComment-1302208 Share on other sites More sharing options...
litebearer Posted December 29, 2011 Share Posted December 29, 2011 Easy there ... Rude responses to people trying to help you for FREE is not likely to endear you. Quote Link to comment https://forums.phpfreaks.com/topic/254022-need-help-to-show-only-certain-columns/#findComment-1302209 Share on other sites More sharing options...
Pikachu2000 Posted December 29, 2011 Share Posted December 29, 2011 Don't use SELECT * for a start. You should also make your mind up whether you want to use print or echo (instread of mixing them both through the code), and deffinately get rid of the @ at the start of your mysql_select_db() line. thts not wat im asking learn to read That is the answer to what you're asking. Perhaps it's you who needs to learn to read. Quote Link to comment https://forums.phpfreaks.com/topic/254022-need-help-to-show-only-certain-columns/#findComment-1302210 Share on other sites More sharing options...
Muddy_Funster Posted December 29, 2011 Share Posted December 29, 2011 actualy it is. using SELECT * you are selecting every record in the table. Not only is it more information that you want, thus grossly inefficient, it is also a stupid security risk when the table holds password information. Limit the select statement to only the fields that you need to output and then you will only output the fileds that you want. alternativly - ignore me again, leave your code in a horrible mess, put up another flippant remark and then wait for someone with a little more patience to handle your childishness to come along and tell you how to write bad code. Quote Link to comment https://forums.phpfreaks.com/topic/254022-need-help-to-show-only-certain-columns/#findComment-1302211 Share on other sites More sharing options...
dynamicgfx Posted December 29, 2011 Author Share Posted December 29, 2011 actualy it is. using SELECT * you are selecting every record in the table. Not only is it more information that you want, thus grossly inefficient, it is also a stupid security risk when the table holds password information. Limit the select statement to only the fields that you need to output and then you will only output the fileds that you want. alternativly - ignore me again, leave your code in a horrible mess, put up another flippant remark and then wait for someone with a little more patience to handle your childishness to come along and tell you how to write bad code. sos didnt understand wat u said at first. btw how do i select a certain column could u perhaps give me an example code. and again im sorry... Quote Link to comment https://forums.phpfreaks.com/topic/254022-need-help-to-show-only-certain-columns/#findComment-1302214 Share on other sites More sharing options...
Muddy_Funster Posted December 29, 2011 Share Posted December 29, 2011 no harm, no foul. to select spific columns from your table you simply name them in a comma sepporated list where you are currently using the *. so to show fist name, last name, and user name it could look something like this: SELECT first_name, last_name, user_name FROM my_user_list where my_user_list is the name of the table that you have stored the information in. Also worth noting is that you can select the fields in any order, although your current code will show the fields only in the order that you select them in. so this would output: First Name | Last Name | User Name If you wanted to show it in a different order you can just select the fields in a different order. ps, you should think about looking into my other points as well, perticularly the use of the @ symbol Quote Link to comment https://forums.phpfreaks.com/topic/254022-need-help-to-show-only-certain-columns/#findComment-1302217 Share on other sites More sharing options...
dynamicgfx Posted December 29, 2011 Author Share Posted December 29, 2011 no harm, no foul. to select spific columns from your table you simply name them in a comma sepporated list where you are currently using the *. so to show fist name, last name, and user name it could look something like this: SELECT first_name, last_name, user_name FROM my_user_list where my_user_list is the name of the table that you have stored the information in. Also worth noting is that you can select the fields in any order, although your current code will show the fields only in the order that you select them in. so this would output: First Name | Last Name | User Name If you wanted to show it in a different order you can just select the fields in a different order. ps, you should think about looking into my other points as well, perticularly the use of the @ symbol tyvm and i removed the @ dnt why i had it in Quote Link to comment https://forums.phpfreaks.com/topic/254022-need-help-to-show-only-certain-columns/#findComment-1302266 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.