Jump to content

table JOIN problem


dreamwest

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

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.