twsowerby Posted May 28, 2008 Share Posted May 28, 2008 Hi Guys, I think I'm being a bit dim here but I can't get this to work how I want it to. I've got this code: $sql = "SELECT villas.*,resorts.* FROM villas, resorts WHERE villas.resortID = resorts.resID AND villas.ID = $recVilla"; $query = mysql_query($sql); $time = date("Y/m/d G:i:s"); while ($row = mysql_fetch_array($query)) { $Name=$row["Name"]; $Resort=$row["resortName"]; $Price=$row["price"]; $ID=$row["ID"]; $IDarray[] = $row["ID"]; echo "<a href=\"incVillaDesc.php?id=$ID&rec=1\">$Name</a>, $Resort, £$Price <br />"; $insertsql = "INSERT INTO recommendations (userID, villaID, useful, used, dateTime) Values ($user, $ID, '', '', '$time')"; $query2 = mysql_query($insertsql); } I need the INSERT to insert every result returned from the select query but it is only inserting 1 result. Any help would be great! Cheers, Tom Quote Link to comment Share on other sites More sharing options...
Rebelrebellious Posted May 28, 2008 Share Posted May 28, 2008 How many result rows are there? If you want to debug it \, it may help to try something in the spirit of : echo mysql_num_rows($query); also, it will work better if you say $row = mysql_fetch_array($query); while($row != False) { //your actions then $row = mysql_fetch_array($query); } 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.