Jump to content

Recommended Posts

Im trying to join two tables and the WHERE statment is true for all rows but it inserts only some new values into the video table, i think theres an error with the "while" portion of the script.

 

Does the while statement look at the first row of each table:

 

<?php
mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("name") or die(mysql_error());

// Construct a join
$query = "SELECT gallery_import.*, video.*".
"FROM gallery_import, video ".
"WHERE gallery_import.description = video.title";

////////////////////
$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){

$sql = "UPDATE video SET gallery_url2='".$row['gallery_url']."' ";
mysql_query($sql) or die(mysql_error());

$sql = "UPDATE video SET channel_real='".$row['categories']."' ";
mysql_query($sql) or die(mysql_error());


}

?>

 

video table has columns "title", "channel_real", "gallery_url2"

gallery_import table has columns "description", "gallery_url", "categories"

 

So this is TRUE for all rows in the video table:

 

"WHERE gallery_import.description = video.title";

 

But say row 5 in video is row 23 in gallery_import. Dont now if this is the reason

 

Link to comment
https://forums.phpfreaks.com/topic/141349-table-join-problem/
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.