patheticsam Posted November 29, 2010 Share Posted November 29, 2010 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 Quote Link to comment Share on other sites More sharing options...
Rifts Posted November 29, 2010 Share Posted November 29, 2010 <?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] ?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 29, 2010 Share Posted November 29, 2010 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. Quote Link to comment Share on other sites More sharing options...
patheticsam Posted November 29, 2010 Author Share Posted November 29, 2010 I don't get any errors with the concetate (".$info['username'].") ....but at the end no data is displayed...... Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 29, 2010 Share Posted November 29, 2010 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. Quote Link to comment Share on other sites More sharing options...
patheticsam Posted November 30, 2010 Author Share Posted November 30, 2010 variables are correctly populated...i tried the script with only the first SELECT command and works perfectly...it's only when I add the second to get the data from table forum_members that dosen't work.... 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.