Jump to content

Join Tables Question


rscott7706

Recommended Posts

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

}

?>

 

8) Thanks!

Ron

Link to comment
https://forums.phpfreaks.com/topic/176092-join-tables-question/
Share on other sites

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

 

8) Ron

Link to comment
https://forums.phpfreaks.com/topic/176092-join-tables-question/#findComment-927897
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/176092-join-tables-question/#findComment-927901
Share on other sites

<?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?

Link to comment
https://forums.phpfreaks.com/topic/176092-join-tables-question/#findComment-927909
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/176092-join-tables-question/#findComment-928512
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.