beennn Posted July 22, 2011 Share Posted July 22, 2011 in my table i haveusername | age | --------------------1-------------202-------------253-------------30how can search for a users age by there username?like: find username 1's age and echo it Link to comment Share on other sites More sharing options...
beennn Posted July 22, 2011 Author Share Posted July 22, 2011 in case that didnt make sense iv done a diagramdiagram on imageShack Link to comment Share on other sites More sharing options...
Ingolme Posted July 22, 2011 Share Posted July 22, 2011 Do you have a database? Link to comment Share on other sites More sharing options...
beennn Posted July 22, 2011 Author Share Posted July 22, 2011 yes Link to comment Share on other sites More sharing options...
Ingolme Posted July 22, 2011 Share Posted July 22, 2011 OK. Have you looked at the PHP tutorial for databases on W3Schools? Link to comment Share on other sites More sharing options...
beennn Posted July 22, 2011 Author Share Posted July 22, 2011 a few days ago i did, cant remember there being the answer to this because i was looking for something else but ill read through it again Link to comment Share on other sites More sharing options...
HungryMind Posted July 22, 2011 Share Posted July 22, 2011 Hi.Try, This if($rs=mysql_fetch_array(mysql_query("SELECT * FROM table_name where username='Bob'"))){echo $rs['age'];}else{echo 'No Record Found';} But! If you've multiples same age values in database, Then what will you do? Link to comment Share on other sites More sharing options...
beennn Posted July 22, 2011 Author Share Posted July 22, 2011 So this will work so long as no 2 ages are the same? what happens then?EDIT: Ahh looks like i didnt read all the way through the tut.found what im looking for; altho before i start to implement it into my site, will this come accross any problems when it comes to having multiple values? <?php$con = mysql_connect("localhost","peter","abc123");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("my_db", $con);$result = mysql_query("SELECT * FROM PersonsWHERE FirstName='Peter'");while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; }?> Link to comment Share on other sites More sharing options...
Ingolme Posted July 22, 2011 Share Posted July 22, 2011 So this will work so long as no 2 ages are the same? what happens then?EDIT: Ahh looks like i didnt read all the way through the tut.found what im looking for; altho before i start to implement it into my site, will this come accross any problems when it comes to having multiple values?<?php$con = mysql_connect("localhost","peter","abc123");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("my_db", $con);$result = mysql_query("SELECT * FROM PersonsWHERE FirstName='Peter'");while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; }?> There's no problem if the names are unique. If the names aren't unique, then you will have to show a list of results. That's shown right there in the tutorial.A proper database table must always have at least one unique field. Link to comment Share on other sites More sharing options...
beennn Posted July 24, 2011 Author Share Posted July 24, 2011 thank you very much Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.