phpSensei Posted July 11, 2007 Share Posted July 11, 2007 I have setup a forum and all I need is the pagination to display data by pages. I am currently showing the thread names within a topic using this code: <?php $id=$_GET['id']; $data_p=mysql_query("SELECT * FROM message_msg INNER JOIN forums ON idtop_msg='$id'"); $row=mysql_query($data_p)or die('Error, query failed'); while($row = mysql_fetch_array($row)){ echo $row['subject_msg'] . '<br>';} ?> The id is the id of the forum you click on, and idtop_msg holds the id of the forum when you post a message. Everytime I use that code, my data repeats itself three times. I.E: I am posting a message with the title of "Cars", and if I posts this message in the Automobile section it will display my title three times like this; Cars Cars Cars instead of just Cars... I checked my Database to see if the data has been duplicated three times but its fine. It has been stored in my table just once. How do you make it so it shows the Topic Name just once. Any help is greatly appreciated. Quote Link to comment Share on other sites More sharing options...
paul2463 Posted July 11, 2007 Share Posted July 11, 2007 I dont know if this is the root cause of your problem but you are using $row to hold the result resource # and also the fetched array from the said results resource # try changing you code to the following $id=$_GET['id']; $data_p=mysql_query("SELECT * FROM message_msg INNER JOIN forums ON idtop_msg='$id'"); $result=mysql_query($data_p)or die('Error, query failed'); while($row = mysql_fetch_array($result)){ echo $row['subject_msg'] . ' ';} Quote Link to comment Share on other sites More sharing options...
phpSensei Posted July 11, 2007 Author Share Posted July 11, 2007 I dont know if this is the root cause of your problem but you are using $row to hold the result resource # and also the fetched array from the said results resource # try changing you code to the following $id=$_GET['id']; $data_p=mysql_query("SELECT * FROM message_msg INNER JOIN forums ON idtop_msg='$id'"); $result=mysql_query($data_p)or die('Error, query failed'); while($row = mysql_fetch_array($result)){ echo $row['subject_msg'] . ' ';} I tried what you said, and it seems to have come up with the error 'Error, query failed'. greatly appreciated your help though. Quote Link to comment Share on other sites More sharing options...
per1os Posted July 11, 2007 Share Posted July 11, 2007 $id=$_GET['id']; $data_p=mysql_query("SELECT * FROM message_msg INNER JOIN forums ON idtop_msg='$id'") or die('Error: ' . mysql_error()); $result=mysql_query($data_p)or die('Error, query failed<br />' . mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['subject_msg'] . ' ';} Report the error message. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted July 11, 2007 Author Share Posted July 11, 2007 $id=$_GET['id']; $data_p=mysql_query("SELECT * FROM message_msg INNER JOIN forums ON idtop_msg='$id'") or die('Error: ' . mysql_error()); $result=mysql_query($data_p)or die('Error, query failed<br />' . mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['subject_msg'] . ' ';} Report the error message. I created that error message, there is something wrong with my query. Quote Link to comment Share on other sites More sharing options...
per1os Posted July 11, 2007 Share Posted July 11, 2007 Umm yea what was the error message, you notice my code is different than the other guys. Mine actually spits out the actual error. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted July 11, 2007 Author Share Posted July 11, 2007 Sorry, didnt quiet gotcha.. Error, query failed You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #4' at line 1 Quote Link to comment Share on other sites More sharing options...
per1os Posted July 11, 2007 Share Posted July 11, 2007 $id=$_GET['id']; $result=mysql_query("SELECT * FROM message_msg INNER JOIN forums ON idtop_msg='$id'") or die('Error: ' . mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['subject_msg'] . ' ';} That should work for ya. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 11, 2007 Share Posted July 11, 2007 $data_p=mysql_query("SELECT * FROM message_msg INNER JOIN forums ON idtop_msg='$id'")\ that is an error INNER JOIN forums ON idtop_msg='$id' that should condition the equality of two table that should be forums ON idtop_msg='this should be a filed ' and idtop_msg='$id'")" ) try doing it like this Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 11, 2007 Share Posted July 11, 2007 $id=$_GET['id']; $result=mysql_query("SELECT * FROM message_msg INNER JOIN forums ON idtop_msg='$id'") or die('Error: ' . mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['subject_msg'] . ' ';} That should work for ya. are you sure the query is right ???? look how you join is that the right way ???? cheers Quote Link to comment Share on other sites More sharing options...
per1os Posted July 11, 2007 Share Posted July 11, 2007 $data_p=mysql_query("SELECT * FROM message_msg INNER JOIN forums ON idtop_msg='$id'")\ that is an error INNER JOIN forums ON idtop_msg='$id' that should condition the equality of two table that should be forums ON idtop_msg='this should be a filed ' and idtop_msg='$id'")" ) try doing it like this What you stated there really makes no sense to me. $id=$_GET['id']; $result=mysql_query("SELECT * FROM message_msg INNER JOIN forums ON idtop_msg='$id'") or die('Error: ' . mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['subject_msg'] . ' ';} That should work for ya. are you sure the query is right ???? look how you join is that the right way ???? cheers I am pretty sure it works because it didn't produce an error. The only query that produced an error was when he tried to query a mysql resource id. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 11, 2007 Share Posted July 11, 2007 $data_p=mysql_query("SELECT * FROM message_msg INNER JOIN forums ON idtop_msg='$id'")\ that is an error INNER JOIN forums ON idtop_msg='$id' that should condition the equality of two table that should be forums ON idtop_msg='this should be a filed ' and idtop_msg='$id'")" ) try doing it like this What you stated there really makes no sense to me. $id=$_GET['id']; $result=mysql_query("SELECT * FROM message_msg INNER JOIN forums ON idtop_msg='$id'") or die('Error: ' . mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['subject_msg'] . ' ';} That should work for ya. are you sure the query is right ???? look how you join is that the right way ???? cheers I am pretty sure it works because it didn't produce an error. The only query that produced an error was when he tried to query a mysql resource id. look this part of the query $result=mysql_query("SELECT * FROM message_msg INNER JOIN forums ON idtop_msg='$id'") answer this are you sure that the joining there is right? INNER JOIN forums ON idtop_msg='$id' this means join or combine two tables with similar fields but here what the both of you do you join the $id fron that table coming from url so what are joining even if runs it wont give you an output needed now that does make sense Quote Link to comment Share on other sites More sharing options...
phpSensei Posted July 11, 2007 Author Share Posted July 11, 2007 $id=$_GET['id']; I got this from the URL.... Link: http://localhost/?mode=viewforum&page=1&id=1 Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 11, 2007 Share Posted July 11, 2007 yes i know that when you join that means combine so the condition on that join is field=filed2 not field=record like the id you get maybe it should be this way join table1 on table1field=table2field where table1.fields= "your id here pr any" SELECT * FROM message_msg INNER JOIN forums ON idtop_msg='"put here the equal fields on the other table" where idtop_msg=anything you can ad and / or if you still have condition Quote Link to comment Share on other sites More sharing options...
phpSensei Posted July 11, 2007 Author Share Posted July 11, 2007 yes i know that when you join that means combine so the condition on that join is field=filed2 not field=record like the id you get maybe it should be this way join table1 on table1field=table2field where table1.fields= "your id here pr any" SELECT * FROM message_msg INNER JOIN forums ON idtop_msg='"put here the equal fields on the other table" where idtop_msg=anything you can ad and / or if you still have condition THANKYOU SO MUCH!!!! <?php $id=$_GET['id']; $result=mysql_query("SELECT * FROM message_msg INNER JOIN forums ON idtop_msg=id WHERE idtop_msg='$id'") or die('Error: ' . mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['subject_msg'] . '<br> ';} ?> I know what you ment now, just wasnt clear to me. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 11, 2007 Share Posted July 11, 2007 if you think that sort your prob then mark this solve Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.