Have an account? Sign in
Login  Register  Facebook
How To Merge 2 Tables In 1 Table
i have a mysql table titled `films2` has
`id` | `name` | `categorie` | `synopsis` | `type` | `s`
and the new table that i want to merege it has `liens`
`idlien` | `lien` | `name` 

i want the table 2 in the `films2` table if the name of the film in the table one equal the name of the film in the table 2
Started: September 18, 2011 Latest Activity: September 18, 2011 php mysql
1 Answer
first you have to make new field in the `films2` and name it `lien`, ok?
then you have to use this code:
you have to connect with your mysql first
$db = @mysql_connect(\'localhost\', \'root\', \'\');
@mysql_select_db(\'filmdest_data\', $db);
and then use this code
$liens = @mysql_query(\"select * FROM `liens` order by idlien desc\");

while($lien = mysql_fetch_array($liens)) {
    $name = str_replace(\"@\", \"\'\", $lien[\'name\']);
    $films2 = @mysql_query(\"select * FROM 
                                    `films2` where
                                         `name` LIKE \'%$name%\'\");
    $film = mysql_fetch_array($films2);
        if ($film) {
            if(mysql_query(\"update `films2` 
                            set `lien` = \'\".$lien[\'lien\'].\"\'
                                where id = \'\".$film[\'id\'].\"\'\")){
                                    echo \'the film no(\'.$film[\'id\'].\') is updated <br>\';
                                }	
        }else{
            echo \'there is an error with \'.$name.\' and \'.mysql_error();
        }
	
}

Posted: MacOS
In: September 18, 2011

great !!! it's working now !! thank you very much
September 18, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer