Jump to content


Photo

sql query to show only some fields


  • Please log in to reply
3 replies to this topic

#1 nadz

nadz
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 08 October 2006 - 12:13 PM

hi, i need an sql query i can execute in a table so that it only shows 2 of the fields. any help would be appreciated. thankyou.

#2 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 08 October 2006 - 12:56 PM

In php:
<?php

$select = mysql_query("SELECT field_1, field_2 FROM table") or die(mysql_error());
while($col = mysql_fetch_array($select, MYSQL_ASSOC)
{
foreach($col as $fieldname => $value)
{
${$fieldname} = $value;
}

echo $field_1;
echo $field_2;
}

?>


#3 nadz

nadz
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 08 October 2006 - 09:43 PM

hi, thanks alot for your help  ;)

unfortunately im getting errors. im using phpmyadmin, the 2 fields i want to see are "members" and "date" in the table "users". i hope this helps.

thanks again for the help.

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 09 October 2006 - 05:52 AM

DATE is a reserved keyword -- change your column name; in the meanwhile, you can use `date`.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users