简体   繁体   中英

how to update database from get user_timeline twitter multiple rows using php mysql

i'm trying to create database with a table filled in twitter api, facebook api, and instagram api.

this is what i tried

  foreach($string as $items)
        {
            $date = new DateTime($items['created_at']);
        for($id=1;$id<=5;$id++){
            echo $id;
        }
        $socmed = array(
        'socmed_id'         => $id,
        'socmed_type'       => 'twitter',
        'socmed_time'       => $date->format('Y-m-d H:i:s'),
        'socmed_caption'    => $items['text']);

            echo $socmed['socmed_id'];
            echo "Time and Date of Tweet: ".$socmed['socmed_time']."<br />";
            echo "Tweet: ". $socmed['socmed_caption']."<br />";
            echo "Screen name: ". $socmed['socmed_type']."<br /><hr />";    



    updateSocmed($socmed['socmed_type'],$socmed);
}

in this case i dont know how to update multiple rows without id so i using social media type to update all but it didn't work.

this is displaying my function updateSocmed:

function updateSocmed($type, $updateData){
    $update = array();
    array_walk($updateData, 'array_sanitize');

    foreach($updateData as $fields => $data){
        $update[] = '`' . $fields . '` = \'' . $data .'\'';
        }
        mysql_query("UPDATE `socmed` SET" . implode(', ',$update) . "WHERE `socmed_type` =  '$type'") or die(mysql_error());
    }

please help..

You are missed single quote ' for $type in where condition

mysql_query("UPDATE `sosmed` SET" . implode(', ',$update) . "WHERE `socmed_type` =  '$type'") or die(mysql_error());

Note: mysql_query was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.Alternatives to this function include: mysqli_query() or PDO::query()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM