dreamwest Posted January 18, 2009 Share Posted January 18, 2009 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 More sharing options...
fenway Posted January 19, 2009 Share Posted January 19, 2009 Why not use a multi-table update? Link to comment https://forums.phpfreaks.com/topic/141349-table-join-problem/#findComment-740241 Share on other sites More sharing options...
dreamwest Posted January 19, 2009 Author Share Posted January 19, 2009 You mean an INSERT, i dont know how to UPDATE using multi table queries mysql_query("INSERT INTO video (gallery_url2, channel_real) VALUES('".$row['gallery_url']."', '".$row['categories']."' ) ") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/141349-table-join-problem/#findComment-740270 Share on other sites More sharing options...
fenway Posted January 19, 2009 Share Posted January 19, 2009 No, i don't mean insert --- i saw select/update in your code. Link to comment https://forums.phpfreaks.com/topic/141349-table-join-problem/#findComment-740333 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.