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

}

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.