Jump to content

Have problem with while ($row=mysql_fecth_assoc($resultprop)) embedded in For Lo


hamzatki

Recommended Posts

Hi All,

 

I have problem using while() inside a For Loop in the code below.

 

<?php

 

 

 

$allprop_id = explode(",", $prop_id1);

 

for($i = 0; $i < $selected; $i++)

 

{

 

$test = $allprop_id[$i];

 

echo "$test <br />";

 

// displaying the correct values of $test for the current values of $i

 

$sqlprop = "SELECT * FROM property where prop_id ='$test'";

$resultprop = mysql_query($sqlprop);

 

while ($row=mysql_fetch_assoc($resultprop))

 

{

$email=$row["$email"]; $prop_id = $row["$prop_id"] ...........;

 

$sqlfn_new = "INSERT INTO enquiry (email, prop_id, ......) VALUES('$email, '$prop_id', ......)";

 

$resultfn_new = mysql_query($sqlfn_new);

 

// inserting the same first values all again

echo "$test <br />";

// keep on displaying the same value of $test for $i = 1

 

}

 

echo "$test <br />";

// display the correct values of $test for the current values of $i

 

 

}

 

?>

 

The impression I had was that the pointer was not return to the top and when I used mysql_data_seek($resultprop, 0), it dispalyed error "Offset 0is invalid for Mysql result iondex 16 (or the query data is unbuffered)".

 

Please I need your help.

 

Reposting with formatting..

 

<?php
$allprop_id = explode(",", $prop_id1);

for($i = 0; $i < $selected; $i++)
{
  $test = $allprop_id[$i];
  echo "$test
";

  // displaying the correct values of $test for the current values of $i

  $sqlprop = "SELECT * FROM property where prop_id ='$test'";
  $resultprop = mysql_query($sqlprop);

  while ($row=mysql_fetch_assoc($resultprop))
  {
    $email=$row["$email"]; $prop_id = $row["$prop_id"] ...........;
    $sqlfn_new = "INSERT INTO enquiry (email, prop_id, ......) VALUES('$email, '$prop_id', ......)";
    $resultfn_new = mysql_query($sqlfn_new);

    // inserting the same first values all again
    echo "$test
";
    // keep on displaying the same value of $test for $i = 1
  }
  echo "$test
";
  // display the correct values of $test for the current values of $i
}
?>

Ok.. I don't understand what you are asking.  What do you expect to happen?  What is actually happening?

 

Some advice:  Check all your mysql_query() for errors like this:

 

if ($resultprop === false) {
  die("Error in $sqlprop: " . mysql_error());
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.