Welcome to WebmasterWorld Guest from 50.17.114.227

Forum Moderators: open

Message Too Old, No Replies

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..

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

Junior Member

5+ Year Member

joined:July 27, 2010
posts: 54
votes: 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!
3:50 pm on July 30, 2010 (gmt 0)

Moderator from US 

WebmasterWorld Administrator lifeinasia is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 10, 2005
posts:5550
votes: 24


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?
10:52 pm on July 30, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:July 27, 2010
posts: 54
votes: 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\")";
11:04 pm on July 30, 2010 (gmt 0)

Moderator from US 

WebmasterWorld Administrator lifeinasia is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 10, 2005
posts:5550
votes: 24


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.
1:39 am on July 31, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:July 27, 2010
posts: 54
votes: 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";
}
3:50 pm on Aug 2, 2010 (gmt 0)

Moderator from US 

WebmasterWorld Administrator lifeinasia is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 10, 2005
posts:5550
votes: 24


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?
3:08 am on Aug 3, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:July 27, 2010
posts: 54
votes: 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!
3:27 am on Aug 3, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:July 27, 2010
posts: 54
votes: 0


its ok..i've done it..thanks!
3:28 pm on Aug 3, 2010 (gmt 0)

Moderator from US 

WebmasterWorld Administrator lifeinasia is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 10, 2005
posts:5550
votes: 24


Can you post your fix so that it will help others who might have the same issue?
10:58 pm on Aug 3, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:July 27, 2010
posts: 54
votes: 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!