Solarpitch Posted October 21, 2007 Share Posted October 21, 2007 Hey, The past 2 hours I've been trying to figure this out and I cant. Below, I have a foreach loop which will retrieve the results of a query held in a db_handling.php file. #### Foreach loop code... $result = editproperty($property_id); foreach($result as $e) { $county = $e[1]; $location = $e[2]; $prop_type = $e[3]; $address = $e[16]; $price = $e[4]; $bedrooms = $e[18]; $sale_type = $e[17]; $description = $e[5]; $features = $e[6]; $accomodation = $e[7]; } ### DB query function editproperty($property_id) { $row2 = array(); $sql = "select * from property_info where property_id=".$property_id.""; $result = mysql_query($sql); while(($row = mysql_fetch_row($result)) != false) { $row2[] = $row; } return $row2; } All the parameters seem to be passing through fine, but the code wont execute anything inside the loop. I even tired putting a echo "hello"; inside the loop and that didnt print out either. Having said that.. when I put echo $location; outside the loop noting will display. So it seems that the loop is not getting the values for each.. $county = $e[1]; $location = $e[2]; .. etc Thanks. Link to comment https://forums.phpfreaks.com/topic/74206-solved-problem-calling-a-foreach-loop/ Share on other sites More sharing options...
MadTechie Posted October 21, 2007 Share Posted October 21, 2007 Add the line below <?php $result = editproperty($property_id); print_r($result);//<-Add this foreach($result as $e) { $county = $e[1]; $location = $e[2]; $prop_type = $e[3]; $address = $e[16]; $price = $e[4]; $bedrooms = $e[18]; $sale_type = $e[17]; $description = $e[5]; $features = $e[6]; $accomodation = $e[7]; } if you get array(); then check your SQL statement.. also change $result = mysql_query($sql); to $result = mysql_query($sql) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/74206-solved-problem-calling-a-foreach-loop/#findComment-374799 Share on other sites More sharing options...
Solarpitch Posted October 21, 2007 Author Share Posted October 21, 2007 Thanks a mill! All sorted ) Link to comment https://forums.phpfreaks.com/topic/74206-solved-problem-calling-a-foreach-loop/#findComment-374830 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.