homepage Welcome to WebmasterWorld Guest from 54.211.0.191
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
comment table and tutorial table -->how to publish the two?
two tables will (merge-like)to be able to view and comment from the user..
sanji41




msg:4178973
 3:54 am on Jul 30, 2010 (gmt 0)

hi! i have comment_table and tutorial_table, i need to publish the two at the same time, same call..so if i want tutorial#1 comment#1 will also publish..i did the JOIN and while the tutorial ID insert to comment_id_fk, the rest of the row becomes null..so if someone comment on that topic, it won't be connected to the tutorial 'coz of the id_auto_increment..hope you guys know a better way to do this..thanks!

 

LifeinAsia




msg:4179251
 3:50 pm on Jul 30, 2010 (gmt 0)

Hi sanji41 and welcome to WebmasterWorld [webmasterworld.com]!

I don't quite understand your problem. Can you provide some more details, like the table structure and some sample data?

sanji41




msg:4179485
 10:52 pm on Jul 30, 2010 (gmt 0)

well, im creating a tutorial site. so i'm not quite sure how the comment form and post tutorial work(database relationship)basically if i post a tutorial, comment form will be there too.my question is how can i call the two tables and every comment for the said tutorial should be inserted for that post only..
here it is:
POST TUTORIAL 1 = COMMENT 1 > every comment for this post only.
POST TUTORIAL 2 = COMMENT 2 > every comment for this post 2.
here is my query:to call them>
$query = "SELECT *FROM tutorials INNER JOIN comment on tutorials.title = comment.tutorialsid_fk ORDER by tutorials.id DESC";
here is to insert them:
$myquery = sprintf("INSERT into tutorials(title, content, author, Sentdate) VALUES ('%s', '%s', '%s', '%s')",
$myquery ="INSERT into comment (tutorialsid_fk) values (\"$id1\")";

LifeinAsia




msg:4179489
 11:04 pm on Jul 30, 2010 (gmt 0)

Not sure why you're joining on "tutorials.title = comment.tutorialsid_fk"
Joining on " tutorials.id = comment.tutorialsid_fk" makes more sense.

Also, "INSERT into comment (tutorialsid_fk) values (\"$id1\")" only adds the id to the row. You need to add the comment as well.

sanji41




msg:4179539
 1:39 am on Jul 31, 2010 (gmt 0)

the last post, last query:
$myquery = sprintf("INSERT into tutorials(title, content, author, Sentdate) VALUES ('%s', '%s', '%s', '%s')",
mysql_real_escape_string($title),
mysql_real_escape_string($content),
mysql_real_escape_string($author),
mysql_real_escape_string($Sentdate));
mysql_query($myquery) or die(mysql_error());
echo "Success!";

if(isset($_POST['save'])){
if(isset($_POST[id]));
$id1 = $_POST['id'];echo $id1;
$title1=mysql_insert_id();
$myquery ="INSERT into comment (tutorialsid_fk) values (\"$id1\")";
$result = mysql_query($myquery);
$result = mysql_query($sql);
echo "<br>Update Complete";
}

LifeinAsia




msg:4180647
 3:50 pm on Aug 2, 2010 (gmt 0)

Did you ECHO your inputs to make sure that you're actually inputting what you expected? Is the data actually being added to the table? Any errors?

sanji41




msg:4180916
 3:08 am on Aug 3, 2010 (gmt 0)

hi! thanks for quick reply, i can get the data and everything that i needed, my question is "how can i insert the comment designed for the specific tutorial and display them as well", when i insert a new tutorial it only fills the Foreign key row, and NULLs the other row..this is a post and comment like site..thanks again!

sanji41




msg:4180928
 3:27 am on Aug 3, 2010 (gmt 0)

its ok..i've done it..thanks!

LifeinAsia




msg:4181211
 3:28 pm on Aug 3, 2010 (gmt 0)

Can you post your fix so that it will help others who might have the same issue?

sanji41




msg:4181495
 10:58 pm on Aug 3, 2010 (gmt 0)

sure! im not gonna explain everything though:
//to select form the comments that have been approved
//$query = "SELECT *FROM comment where com_isapprove = 1 ORDER by com_id ASC";
//always initialise your variables
$id = "";
$id = $_GET['id'];

//insert the comments-and the FK as well
$query="select * from comment where com_tut_id_fk='{$id}' and com_isapprove !=0";
$result = mysql_query($query) or die('Error : ' . mysql_error());

$myquery = sprintf("INSERT into comment(com_name,com_email, com_website, com_enquiry, com_tut_id_fk, com_Sentdate) VALUES ('%s', '%s', '%s', '%s', '$id', '%s')",
mysql_real_escape_string($name),
mysql_real_escape_string($email),
mysql_real_escape_string($website),
mysql_real_escape_string($enquiry),
mysql_real_escape_string(time()));
mysql_query($myquery) or die(mysql_error());

}

//the only problem i have is to ajax the data, and i don't know ajax--to refresh the data in db. any suggestions? thanks!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved