abch624 Posted July 4, 2008 Share Posted July 4, 2008 Hi guys I have the code bellow which works just fine <?php $tbl_personal="personaldetails"; // Table name for personal details $tbl_profile="profiledetails"; // Table name for profile details $tbl_cities="tblcities"; // Table name for city name $tbl_countries="tblcountries"; // Table name for country name $tbl_branches="tblbranches"; // Table name for branch name $tbl_hidden="hidden"; // Table name for hidden values // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); //Variable from url $query = $_GET['query']; // Variables sent from form $searchfield=$_POST['searchField']; echo $sql = "SELECT P.firstName, P.lastName, P.bid, P.lid, D.profilePicture FROM $tbl_personal P JOIN $tbl_profile D ON (P.profileDetailsID = D.profileDetailsID) JOIN $tbl_cities C ON (P.lid = C.lid) JOIN $tbl_branches B ON (P.bid = B.bid) WHERE P.firstName LIKE '%$query%' OR P.lastName LIKE '%$query%' OR D.activity LIKE '%$query%' OR D.interests LIKE '%$query%' OR D.aboutMe LIKE '%$query%' OR D.languagesSpoken LIKE '%$query%' OR D.countries LIKE '%$query%' OR B.name LIKE '%$query%' OR C.name LIKE '%$query%'"; echo "<hr>"; if ($result = mysql_query($sql)) { $row=mysql_fetch_array($result); foreach ($row['firstName'] as $t) {echo $t; echo "<hr>";} $profilepicture = $row['profilePicture']; } else { echo mysql_error(); } ?> My problem is the foreach loop. If you have a look at the attached picture of PHPmyAdmin I have attached it shows there are 9 coloums resulted with this. I want to get and display all these fields I get into a table. Please help how can I loop through this so to get all results not just the first one. Please help Cheers - Zahid [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/113274-solved-looping-through-a-set-of-database-results/ Share on other sites More sharing options...
themistral Posted July 4, 2008 Share Posted July 4, 2008 Have you considered using a while loop? if (mysql_num_rows($sql) > 0) { while ($row=mysql_fetch_array($sql)) { echo $row[firstName]; echo "<hr>"; $profilepicture = $row['profilePicture']; } } else { echo mysql_error(); } Link to comment https://forums.phpfreaks.com/topic/113274-solved-looping-through-a-set-of-database-results/#findComment-581986 Share on other sites More sharing options...
abch624 Posted July 4, 2008 Author Share Posted July 4, 2008 Hi, Thanks na I didnt even think of that Just got a mental block lol Thanks a lot m8 - That works Thanks Link to comment https://forums.phpfreaks.com/topic/113274-solved-looping-through-a-set-of-database-results/#findComment-581989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.