Jump to content

need help to show only certain columns


dynamicgfx

Recommended Posts

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... 8):D

Link to comment
Share on other sites

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 :anim_reading:

 

That is the answer to what you're asking. Perhaps it's you who needs to learn to read.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.