markspec87 Posted September 7, 2006 Share Posted September 7, 2006 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. Quote Link to comment Share on other sites More sharing options...
onlyican Posted September 7, 2006 Share Posted September 7, 2006 $query = "SELECT * FROM table WHERE fieldname LIKE '%value%'";Is this what u meant? Quote Link to comment Share on other sites More sharing options...
markspec87 Posted September 7, 2006 Author Share Posted September 7, 2006 yeh i know the code to start withi.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) Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 7, 2006 Share Posted September 7, 2006 [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. Quote Link to comment Share on other sites More sharing options...
onlyican Posted September 8, 2006 Share Posted September 8, 2006 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();} Quote Link to comment 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.