Jump to content

[SOLVED] Mysql Data...


phpSensei

Recommended Posts

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.

Link to comment
Share on other sites

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'] . '
';}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  $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  ;D

Link to comment
Share on other sites

$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

Link to comment
Share on other sites

  $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  ;D

 

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.

Link to comment
Share on other sites

  $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  ;D

 

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.