db entry based on primary key


Posted on 16th Feb 2014 07:03 pm by admin

My "topics" table contains 10 entires
*--------------*
topicid topic
------
Did you know?Explore Trending and Topic pages for more stories like this.
*--------------*
01 Bye
02 Hi
03 Hello
.....
10 Morning
*--------------*


<?php //topics.php
require_once("includes/connection.php");
....
....
ttopics[]= //I have 10 strings here which have changed by now.

foreach ($ttopics as $ttkey)
{

//I am trying to update my "topics" table whenever these strings change, based on the topicid (primary key).

//Please correct my code.

$id = mysql_real_escape_string('topicid');
$topic = mysql_real_escape_string('topic');
$result = mysql_query("SELECT topicid, topic FROM table WHERE topicid='{$id}' and topic='{$topic}' ");
if($result)
{
$num = mysql_num_rows( $result );
if ($num == 0)
{
$querypost = mysql_query ("INSERT INTO trendingtopics (topic) VALUES ('$ttkey')");
}


}


I am getting an error. Lets say the position of Morning is first and Bye is last. It should update the database accordingly. If there is a new entry, say "phpfreaks" in first position. It should update according.
No comments posted yet

Your Answer:

Login to answer
76 Like 17 Dislike
Previous forums Next forums
Other forums

* Gridview and Detailsview in UpdatePanel, insert mode problem
I have a GridView and DetailsView working together. When a record from Gridview is selected, Detail

Count number of records in all the tables with a querry URGENT PLEASE...
I downloaded ORACLE 9I DATA DUMP into my comp. There are number of tables. I need to find out the

Downloading file (Headers)
I'm trying to make users download a file, but they must wait 60 seconds before it begins.

But

Does deleting the spmlog directory critical?
Hi Everyone,

Please, hope you could help me. We're having problems with the SAP backup. I

Deleting a record php
Attempting to setup delete a record page. The below code I put together doesn't seem to work.

add to sql result
ok see rite now my sites hit counter is counted from the mysql visitor log i need to clear it aft

Binding 2 UDP sockets on same port, connected to different destinations, 1 receives
Hello,
My application wants to send/recv data to 2 different UDP ports on a remote computer, us

Backflush
I am looking for a report in SAP that would give me a list of all parts that are populated with a ba

form help
this doesn't work. i want the form action to go the location.href of the submit button chosen.. how

Logic question
im wondering what's the best method to do the above list:

it is for alliance @ MMORPG game

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash