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

Taylor Series Function
So I am working a a project for my intro C++ class, and I am having some trouble with a function for

that old Malformed Headers problem again!!!!! HELP!!!!!!
I've read the http://www.phpfreaks.com/forums/index.php/topic,37442.0.html

I don't think my c

header redirect problems? please help
Ok i am making a site that generates youtube thumbnails and i am generating an image that displays 1

php call servlet
I have done a php backup application .
So there is a form that user pick some files to zip and d

php or sql?
Sorry not sure if this is a sql problem or php the following code is supposed to delete data from th

FROM_UNIXTIME($phpdate);
Hello,

I tried to use this :

$date = FROM_UNIXTIME($phpdate);

ANd I was t

Bandwidth monitoring?
Hi guys,

I need a little information I have written a php app and I occurred to that I need

array_diff weirdness
I'm using the following bit of code

$diff = array_diff($pids, $pidlist);
$diff = array_va

captcha error
I have been trying to implement a captcha in php...

here is the code..
Code: (php) [Select

PHP mail() with images
I'm trying to get images to send along with my HTML e-mail sent through PHP mail(). I only tried vie

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