hamzatki Posted February 22, 2007 Share Posted February 22, 2007 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. Quote Link to comment Share on other sites More sharing options...
btherl Posted February 23, 2007 Share Posted February 23, 2007 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 } ?> Quote Link to comment Share on other sites More sharing options...
btherl Posted February 23, 2007 Share Posted February 23, 2007 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()); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.