sanderphp Posted May 23, 2008 Share Posted May 23, 2008 I'm trying to run 2 sql statements in one function. Is this where I am supposed to use a join? I haven't ever needed to do run 2 statements before but I'm trying to display the name on the same page. $sql_user_data="SELECT * FROM info WHERE rider_id = '$rider_id' ORDER by date "; $sql_rider_name = "SELECT cyclist FROM riders WHERE id ='$rider_id'"; // this statement actually executes the sql $result = mysql_query($sql_user_data) or die("ERROR! user_data".mysql_error($dataConn)); $result_name = mysql_query($sql_rider_name) or die("ERROR! rider_name".mysql_error($dataConn)); Quote Link to comment Share on other sites More sharing options...
.josh Posted May 23, 2008 Share Posted May 23, 2008 What you have there is perfectly legitimate, however, depending on what your goal is, you could conceivably use something like JOIN to streamline your results. Offhand, it looks like you have two separate tables, one for account info and one for "game" or "content" info and the info from each table for the user has the common denominator of if rider_id and id (it looks like each table holds the same information). So, you could possibly use something like JOIN, INNER JOIN, LEFT JOIN, etc.. (lookup relational databases) to streamline. I'm going to go ahead and move this to the sql forum though, as those guys over there are much more knowledgeable in that area. Quote Link to comment Share on other sites More sharing options...
fenway Posted May 29, 2008 Share Posted May 29, 2008 SELECT r.cyclist FROM info AS i INNER JOIN riders AS ON ( r.id = i.rider_id ) WHERE i.rider_id = '$rider_id' ORDER by i.date Though I would change the name of your date field, since DATE is a reserved keyword. 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.