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

problem in program for counting no of chars using pointers
Hi all, I was trying to make a program which counts number of chars in a string using concpt of poin

MySQL noob question
hi guys

I have a simple mysql table set up, along the lines of

Col 1 - Col 2 - Date_l

Credit card verification
I have a client who wants to process credit card transactions from his web site rather than the goin

update sql when refresh - php
hi
I have made a table (attachement)

the users can update the sql database using + or x bu

Namespace Problem
I'm having problem with a section of code with a variable namespace.

This code works fine:

highlighting search terms
well, I started this in the regular PHP section, but it no longer fits there. Suffice it to say, I'm

Table sorting
Hi,

I'm trying to modify the following in order to make the output table sorted alphabeticall

Shuffle between users ??
I have multiple $users in table. I need to send them $message.

I need to send the next messag

Users and Groups with PHP Classes
Hi,

I have setup what I hope to be a good working User class. Now I want to introduce group m

Two fgetcsv related questions ;D
First of im trying to get a file from a merchants server but the directory is protected, I know the

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