Jump to content

SELECT


andy_b_1502

Recommended Posts

Hi everyone! 

 

I need to know how to write two $what_services variables in so it looks for both "R" AND "B"..

 

R and B are values within my db table, here's the code:

 

<?php
$what_services = "R";

    $query = "SELECT * FROM companies WHERE what_services = '$what_services' ORDER BY approved DESC, company_name ASC";
$result = mysql_query($query); ?>

 

iv'e tried the following but have gotten undesired results:

 

two what services like so;

 

$what_services = "R";

$what_services = "B";

 

separating with comma's;

 

$what_services = "R, B";

 

Using AND;

 

$what_services = "R AND B";

 

None of which works, what is the correct way to write this?

 

Thanks

Link to comment
Share on other sites

You want rows where what_services = 'R' or where what_services = 'B'. There's two ways -

 

A)

$query = "SELECT * FROM companies WHERE what_services = 'R' OR  what_services = 'B' ORDER BY approved DESC, company_name ASC";

 

B)

$query = "SELECT * FROM companies WHERE what_services IN('R','B') ORDER BY approved DESC, company_name ASC";

Link to comment
Share on other sites

Thanks,

 

Which one will work best with my while loop do you think?

 

    <?php
$what_services== "R";

    $query = "SELECT * FROM companies WHERE what_services = '$what_services' ORDER BY approved DESC, company_name ASC";
$result = mysql_query($query);

while ( $row = mysql_fetch_array($result)) {
$approved = $row['approved'];
$what_services = $row['what_services'];

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.