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 Link to comment https://forums.phpfreaks.com/topic/107599-need-help-with-an-insert/ 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); } Link to comment https://forums.phpfreaks.com/topic/107599-need-help-with-an-insert/#findComment-551493 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.