Jump to content

Archived

This topic is now archived and is closed to further replies.

markspec87

Select records based on value

Recommended Posts

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.

Share this post


Link to post
Share on other sites
$query = "SELECT * FROM table WHERE fieldname LIKE '%value%'";

Is this what u meant?

Share this post


Link to post
Share on other sites
yeh i know the code to start with

i.e

[quote]$sql = "SELECT * FROM members WHERE username="spec"[/quote]

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

Share this post


Link to post
Share on other sites
[code]$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
[/code]

The above assumes a single match to the query.

Share this post


Link to post
Share on other sites
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();
}

Share this post


Link to post
Share on other sites

×

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.