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.

 

Link to comment
Share on other sites

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
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.