Home > php > Getting Duplicate data in database table after executing the code

Getting Duplicate data in database table after executing the code

December 9Hits:4
Advertisement

Hi I am getting duplicate data in database table after executing the code.I am not able to find the reason. Please help me out

$total_posts = array();     ini_set('display_errors', true);     try {         $stmt = $db->prepare("INSERT INTO timeline_row_wise (`fbname`, `token`, `message_id`, `message`) VALUES (?, ?, ?, ?);");         //$stmt = $db->prepare("insert into `<table>` (`id`,`message`) values(?,?);");         foreach ($total_posts as $row) {             if (isset($row['message'])) {                 // any record with 'message' is allowed                 // whenever has it 'story' or no                 $message_id = $row['id'];                 $story      = $row['message'];                     $stmt->bind_param('ssss',$name, $accessToken, $message_id, $story);                 if ($stmt->execute()) {                     //echo "Thank you! New record created successfully !!!!!!!";                 } else {                     // error handler                     $error = $stmt->error;                     // debug                     echo $error.PHP_EOL;                     die();                 }             } else {                 if (isset($row['story'])) {                     // only story                 } else {                     // no message & no story                 }             }         }         echo "Thank You ";     } catch (\Exception $e) {         // debug         echo $e->getMessage();     }      $stmt->close();     // End code - To store the Message and corresponding id in the database row wise per message and id----------------      // Start code - To store the Message and corresponding id in the database, each field all messages and another field all corresponding id      ini_set('display_errors', true);     try {         $stmt = $db->prepare("INSERT INTO timeline_single_row (`fbname`, `token`, `message_id`, `message`) VALUES (?, ?, ?, ?);");        /* $message_ids = array();         $stories = array();*/         foreach ($total_posts as $row) {             if (isset($row['message'])) {                 // any record with 'message' is allowed                 // whenever has it 'story' or no                 $message_ids[] = $row['id'];                 $stories[]      = $row['message'];              } else {                 if (isset($row['story'])) {                     // only story                 } else {                     // no message & no story                 }             }         }          $message_id = implode("\n",$message_ids);         $story      = implode("\n",$stories);         $stmt->bind_param('ssss',$name, $accessToken, $message_id, $story);         if ($stmt->execute()) {             // success             echo "very much for you valuable time and patience!";         } else {             // error handler             $error = $stmt->error;             // debug             echo $error.PHP_EOL;             die();         }          // or output to console         // echo 'id: '.$message_id.PHP_EOL;         // echo 'message: '.$story.PHP_EOL;         // echo PHP_EOL;         } catch (\Exception $e) {         // debug         echo $e->getMessage();     }      // End code - To store the Message and corresponding id in the database, each field all messages and another field all corresponding id          $stmt->close();         $db->close(); 
Tags:php, mysql, mysqli

Related Articles

  • Getting Duplicate data in database table after executing the codeDecember 9

    Hi I am getting duplicate data in database table after executing the code.I am not able to find the reason. Please help me out $total_posts = array(); ini_set('display_errors', true); try { $stmt = $db->prepare("INSERT INTO timeline_row_wise (`fbn

  • Remove duplicate data in revision tables in database

    Remove duplicate data in revision tables in database August 27

    Possible Duplicate: How to disable the revision feature completely? How can I disable duplicate data in database. one example is this image: --------------Solutions------------- You can't unfortunately. The concept of storing field data and revision

  • php script enters duplicate data in databaseJanuary 21

    I have php script which runs stored procedure from sql server and enters data in table present in database. when i run php script it enters the duplicate date even same data is present in the database. i need to get rid of these duplicate data. the s

  • insert data in database table from plugin with WP3.1March 27

    I am quite new in WP Plugin World. I am trying to develop a plugin in WP 3.1 when I am trying to insert data into my table named "wp_enam" in the following way: $wpdb->insert($wpdb->enam, array('username' => "enam" , 'useremai

  • simplest way to read and write data in database table. July 10

    I am new to drupal. I need to know what is the basic way to read and write content to a table of drupal database. also, can we add/update/delete data from a table inside the same drupal database which was not the part of drupal installation. Thanks.

  • Duplicate data in a table given table nameMarch 2

    For a performance testing application we need to have lot more data in our tables than what we have now. How do I duplicate the data in a table. In the process of duplicating I also need to set new values for primary key column. I'm thinking getting

  • SharePointOnline/Office365 getting data from Database table to SharePoint ListMay 15

    Does anyone know how we can get data from SQL Server database table to SharePointOnline list? Its not a one time thing, but data should get updated from Database table to SharePoint list continuously once every 24 hrs. One way sync from DB to List? I

  • PHP, mysql - get data in database table with for-loop in json_encodeJanuary 25

    sorry if my question-title is confusing..i don't know exactly how to put it. but here's what: so..im trying to get the data in my database, put it in <select><option> tag. and echo it. addtocart.php this is my first code and this is working fi

  • Fulltext index - Not getting result after inserting new row of data to database tableFebruary 10

    I have used fulltext index mysql for searching. After I inserted new row to table and I tried to search that product name I am not getting the result. Please tell me how to reindex or update the index, so that when new row is inserted,immediately whe

  • Which webpart to use to add, delete, update data from a database table.April 24

    I have a table in database I want to use a webpart to add, delete and udate data from database table I can create a custom webpart with a gridview but is there out of box webpart in 2007 sharepoint I can use ??? --------------Solutions------------- I

  • How to insert data into postgis database table?September 13

    I am a newbie in spatial database, so I am having lots of issues even in small tasks and now I am having some issue with inserting data to the table. I have followed the postgis documentation but however, I'm getting some error while inserting data t

  • Remove all duplicate data in mysqlJuly 3

    I want remove all duplicate data from my table. anyone help me. my table : biblio one one two three three four five i want to get result like this biblio two four five --------------Solutions------------- Given this table mysql> USE test Database cha

  • Can't insert data to database on form submitApril 8

    I am trying to insert some datas into database table on form submit like this: function form_example_submit($form, &$form_state) { if ($form_state['values']['select']=='1') $gender = 'male'; else $gender = 'female'; db_insert('form_example_table')->

  • Managing database tables in WordPress multisiteJanuary 28

    I'm working on plugin that creates and stores some data in database table (using global $wpdb->base_prefix). In WordPress multisite I want sub-website owners to have access only to data that they've created. What is the best way to handle this? Shoul

  • I Want to show the alert of fetched row from database table on body load eventFebruary 2

    I want to compare current system date with my database table date as shown. If both matched then corresponding member Name will be shown in alert on body load. My Code <?php $now=date("Y/m/d"); $sql = "select MemName from payment where $

  • same php program can't pull data from database on some computers February 9

    I have written a private php program which connects to another software's database (Sybase). It works completely fine in my office (windows 7, php_5.2.0). Set up information: All our office computers are networked together with one computer as a serv

  • Non-fatal Exception: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database February 3

    This question already has an answer here: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database trouble 1 answer Actually I am storing GCM notifications in local DB on GCM notification receiver, but

  • Should a database table(s) structure match its intended data structure(s) in the logic?January 4

    This question branches out of this question, What are the differences between algorithms using data structures and algorithms using databases?. The General Question Should a database table(s) structure match its intended data structure(s) in the logi

  • Pulling data from identical tables in different databasesJanuary 23

    I'm dealing with a situation in SQL Server 2008 where each client is setup as their own database, with each database having identical table structures. I have a query that selects from across ~20 different tables within a database, and inserts the re

  • Getting last modification date of a PostgreSQL database tableFebruary 4

    I'm trying to get when my table was modified by checking its file modification date as it is described in this answer. But the result is not always correct. The file modification date updates in several minute after I update my table. Is it correct b

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 1.021 s.