Jump to content


Photo

Select records based on value


  • Please log in to reply
4 replies to this topic

#1 markspec87

markspec87
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 07 September 2006 - 11:48 PM

I know this is really simple (i think) but i cant remember the code.

How do i show records based on the value of another?

i.e select the record where username = "spec" so i can then assign specs age and location etc to different variables.

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 07 September 2006 - 11:49 PM

$query = "SELECT * FROM table WHERE fieldname LIKE '%value%'";

Is this what u meant?
Tell me the problem, I will try tell you the solution

#3 markspec87

markspec87
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 07 September 2006 - 11:50 PM

yeh i know the code to start with

i.e

$sql = "SELECT * FROM members WHERE username="spec"


But then how can i use this to say output specs age or location? (seperatly ofc)



#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 07 September 2006 - 11:57 PM

$sql = "SELECT * FROM members WHERE username="spec";
$result = mysql_query($sql) or die("Error: ". mysql_error(). " with query ". $sql);
$row = mysql_fetch_array($result);
echo $row['age']. " and ". $echo['location']; // or whatever

The above assumes a single match to the query.
Legend has it that reading the manual never killed anyone.
My site

#5 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 08 September 2006 - 12:22 AM

is there is more than one

$query = "SELECT * FROM members WHERE username = 'spec'";
$result = mysql_query($query);
if($result){
while($row = mysql_fetch_assoc($result)){
echo "Age: ".$row["age"]."<br />\n";
}

}else{
echo "There has been an error<br />\n"
.mysql_error();
}
Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users