Jump to content

Recommended Posts

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

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());

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.