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. Link to comment https://forums.phpfreaks.com/topic/20065-select-records-based-on-value/ 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? Link to comment https://forums.phpfreaks.com/topic/20065-select-records-based-on-value/#findComment-88056 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) Link to comment https://forums.phpfreaks.com/topic/20065-select-records-based-on-value/#findComment-88059 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. Link to comment https://forums.phpfreaks.com/topic/20065-select-records-based-on-value/#findComment-88066 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();} Link to comment https://forums.phpfreaks.com/topic/20065-select-records-based-on-value/#findComment-88078 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.