Jump to content

Problem with SQL select into multiple table


patheticsam

Recommended Posts

Hi, I'm a little bit new to php and i'm having a small problem. Let me explain with the script :

 

<?php

//connect to mysql

$data = mysql_query("SELECT * FROM forum_topic WHERE topic_id='$topic'") 
or die(mysql_error());

while($info = mysql_fetch_array( $data ))

$dete = mysql_query("SELECT * FROM forum_topic WHERE login='$info['username']'") 
or die(mysql_error());

while($info2 = mysql_fetch_array( $dete ))

     {

echo "......";
     }
?>

 

So I have the first SELECT command that will get the data from table forum_topic and array the data and after that I have a second SELECT that will get the data from table_members but this time time the WHERE clause equals to some data "arrayed" in the first SELECT command...And the end I need to output the data from both tables....

 

Here's the error I get :

 

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/m/a/z/mazemontana/html/login/forum_viewtopic.php on line 73

 

 

...I know that my syntax is probably not good but can't figure out how to do it.....

 

Any help will be greatly appreciated!

 

Thanx

Link to comment
Share on other sites

<?php

//connect to mysql

$data = mysql_query("SELECT * FROM forum_topic WHERE topic_id='$topic'") 
or die(mysql_error());

while($info = mysql_fetch_array( $data ))
[b]{[/b]
$dete = mysql_query("SELECT * FROM forum_topic WHERE login='$info['username']'") 
or die(mysql_error());

while($info2 = mysql_fetch_array( $dete ))

     {

echo "......";
     }

[b]}[/b]
?>

 

Link to comment
Share on other sites

Associative array elements are a little different when used in that context. You'll need to either concatenate them into the string:

WHERE login='" . $info['username'] . "'")

 

Or you can enclose them in curly braces:

WHERE login='{$info['username']}'")

 

Personally, I find the curlies to be more readable, but either is equally valid.

Link to comment
Share on other sites

Then you have a query failing, or returning an empty result set, most likely. Have you echoed your variables to make sure they're populated? I don't see where $topic is ever assigned a value. Also, executing a query in a loop like that is a resource hog from hell.

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.