Jump to content

Recommended Posts

Hi, I was wondering how I can select all the different colours in a database if no specific colour is entered?

 

Here is my code;

 

//Colour Search Box
if($_POST['Colour'] != "") {
$Colour = $_POST['Colour'];
} else {
$Colour = "ALL COLOURS";
}

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/173890-how-to-select-all-entires-in-a-column/
Share on other sites

You just wouldn't specify a condition, for example:

 

$sql = "select * from colours";

if (isset($_POST['Colour']))
{
    $colour = mysql_real_escape_string($_POST['Colour']);
    $sql .= " where colour='{$colour}'";
}

// run query

You just wouldn't specify a condition, for example:

 

$sql = "select * from colours";

if (isset($_POST['Colour']))
{
    $colour = mysql_real_escape_string($_POST['Colour']);
    $sql .= " where colour='{$colour}'";
}

// run query

 

Thanks for the reply although im not sure how to implement is :S This is my query so far its quite big

 

$query_rsVehicle = "SELECT ID, `Vehicle Registration`, Make, Model, Color, Transmission, `Fuel Type`, Mileage, `Reg Year`, `Image Prefix`, `Key Point 1`, `Key Point 2`, `Key Point 3`, `Key Point 4` FROM vehicles WHERE Model LIKE \"%$Search%\" AND Wheelbase IN ('$Wheelbase') AND `Roof Height` IN ('$RoofHeight') AND Color LIKE ('$Colour')";   

Try this:

 

$colour_condition = '';
if (isset($_POST['Colour']))
{
    $colour = mysql_real_escape_string($_POST['Colour']);
    $colour_condition = "and Color='$colour'";
}

$query_rsVehicle = "SELECT ID, `Vehicle Registration`, Make, Model, Color, Transmission, `Fuel Type`, Mileage, `Reg Year`, `Image Prefix`, `Key Point 1`, `Key Point 2`, `Key Point 3`, `Key Point 4` FROM vehicles WHERE Model LIKE \"%$Search%\" AND Wheelbase IN ('$Wheelbase') AND `Roof Height` IN ('$RoofHeight') $colour_condition";

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.