Jump to content

2 sql statements in one function


sanderphp

Recommended Posts

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));

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.