Jump to content

Trouble combining two where statements with mysql & where


Recommended Posts

Where would I need to put a MySql statement in the following script (combine the two to get one output statement):

 

///////////////////////////////////////////////////////////////////////////////////

      $sql="select cid from provider where pid=\"$id\"";

      $result=@mysql_query($sql,$con) or die(death($sql));

      while ($row = @mysql_fetch_array($result)) {

          $cid = $row["cid"];

      echo("<option>" . $cid . "</option>");$cid . "<br>";

      }

 

/////////////////////////////////////////////////////////////////////////////////////

      $sql="select * from people where id=\"$cid\";";

      $result=@mysql_query($sql,$con) or die(death($sql));

            while ($row = @mysql_fetch_array($result)) {

          echo "$sql<P>";

              echo("<option>" . $row["first_name"] . " " . $row["last_name"] . "</option>");

      }

////////////////////////////////////////////////////////////////////////////////////////////

 

 

Whenever I change one little thing it seems to create a syntax error for some reason (provider is a xref table) ???  any advice on how to fix my issue, or code to do it ;D.

I figured it out with the help of PHPmyadmin 2.10.1 query editor  :P.

 

now I just need to fix it up a little but here is the basic script:

$sql = "SELECT `provider`.`cid`,

`people`.`id`,

`people`.`first_name`,

`people`.`last_name`

 

FROM provider, people

WHERE cid = id

ORDER BY `people`.`id` ASC;";

      $result=@mysql_query($sql,$con) or die(death($sql));

 

      while ($row = @mysql_fetch_array($result)) {

          $cid = $row["cid"];

          $first_name = $row["first_name"];

          $last_name = $row["last_name"];

          echo ("$first_name $last_name<br>");

 

You might try:

 

$provider=array();
$people=array();
$sql = "SELECT provider.cid, people.* FROM provider JOIN people ON provider.cid = people.cid WHERE provider.pid = {$id};";
$result=@mysql_query($sql,$con) or die(death($sql));
while($row = @mysql_fetch_assoc($result)) {
    $provider[] = "<option value=\"{$row['cid']}\">{$row['cid']}</option>";
    $people[] = "<option>{$row['first_name']} {$row['last_name']}</option>";
}

//Now you can reuse provider and people as you wish.
foreach($provider as $value) {
    echo $value;
}

foreach($people as $value) {
    echo $value;
}

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.