Jump to content

Need help with an INSERT


twsowerby

Recommended Posts

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

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

}

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.