rscott7706 Posted September 30, 2009 Share Posted September 30, 2009 For some reason, the following query works fine (QUERY 1), but the one further down (QUERY 2) that attempts to join tables does not. It would solve a lot of problems for me if I can get the "join tables" concept down pat. I left out username and password from code. Here is a link to QUERY 1 that works (does not join tables): https://communityrecoveryteam.org/volunteer%20form/apForm1_List.php Here is a link to QUERY 2 that does not work (seeks to join tables): https://communityrecoveryteam.org/volunteer%20form/apForm1_List2.php QUERY 1 <?php echo "<font face=\"verdana\">"; echo "<br />"; $db = mysql_connect("localhost", "", ""); mysql_select_db(""); $query = "SELECT * FROM ap_form_1 ORDER BY id desc"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "<br />ID: "; echo $row['id']; echo " Date Volunteered: "; echo $row['date_created']; } ?> QUERY 2 <?php echo "<font face=\"verdana\">"; echo "<br />"; $db = mysql_connect("localhost", "", ""); mysql_select_db(""); $query = "SELECT id, date_created FROM ap_form_1, ap_element_options WHERE ap_form_1.id = ap_element_options.form_id ORDER BY date_created DESC; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "<br />ID: "; echo $row['id']; echo " Date Volunteered: "; echo $row['date_created']; } ?> Thanks! Ron Quote Link to comment Share on other sites More sharing options...
cags Posted September 30, 2009 Share Posted September 30, 2009 The format I've always used for JOIN'ing tables, is this... $query = "SELECT id, date_created FROM ap_form_1 JOIN ap_element_options ON ap_form_1.id = ap_element_options.form_id ORDER BY date_created DESC; Quote Link to comment Share on other sites More sharing options...
rscott7706 Posted September 30, 2009 Author Share Posted September 30, 2009 I still get an error. I am not now sure if the query is proper although it works fine without the join table request. Parse error: syntax error, unexpected T_STRING in /home6/crtsdorg/public_html/volunteer form/apForm1_List3.php on line 12 Line 12 is: echo "ID: "; But, if I take the title out, and leave just: echo $row['id']; echo $row['date_created']; } I still get an error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home6/crtsdorg/public_html/volunteer form/apForm1_List3.php on line 12 I don't don't know, PHP just kicks my tail - I just don't seem to get it. Why would a query work fine on one Select statement, but not another... Ron Quote Link to comment Share on other sites More sharing options...
cags Posted September 30, 2009 Share Posted September 30, 2009 I really should read posts better, not watch TV. In your second query, you don't have a close double quote " at the end of it before the semicolon. If you'd have posted with the PHP code tags, you might have seen that <?php <?php echo "<font face=\"verdana\">"; echo "<br />"; $db = mysql_connect("localhost", "", ""); mysql_select_db(""); $query = "SELECT id, date_created FROM ap_form_1, ap_element_options WHERE ap_form_1.id = ap_element_options.form_id ORDER BY date_created DESC; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "<br />ID: "; echo $row['id']; echo " Date Volunteered: "; echo $row['date_created']; } ?> ?> Quote Link to comment Share on other sites More sharing options...
Evilace Posted September 30, 2009 Share Posted September 30, 2009 <?php echo "<font face='verdana'><br />" $db = mysql_connect("localhost", "", "") or die("Connection Failed"); mysql_select_db("") or die("Database Failed"); $query = "SELECT id, date_created FROM ap_form_1, ap_element_options WHERE (ap_form_1.id = ap_element_options.form_id) ORDER BY date_created DESC"; $result = mysql_query($query) or die("Query Failed"); while($row = mysql_fetch_array($result)){ echo "<br />ID: ".$row['id']." Date Volunteered: ".$row['date_created'].""; } ?> Try that? Quote Link to comment Share on other sites More sharing options...
rscott7706 Posted September 30, 2009 Author Share Posted September 30, 2009 Thanks for all your quick response. I have to go out right now, but will work this a little alter today or tonight. Again a big THANK YOU!! I will let you know how it goes. Ron Quote Link to comment Share on other sites More sharing options...
rscott7706 Posted October 1, 2009 Author Share Posted October 1, 2009 Thanks for all your quick response. I have to go out right now, but will work this a little alter today or tonight. Again a big THANK YOU!! I will let you know how it goes. Ron cags and Evilace Thanks for your input, I worked on it late last night and got it going due to your great input. cags, in the future, I will use PHP tags - my bad. Ron 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.