Jump to content

[SOLVED] Organize By Type Only if Type Specified


gamerzfuse

Recommended Posts

The old forum post solved my problem entirely, but it just introduced another one.

Rather than having a 3 page post with a new problem, I decided to start over here.

 

Situation:

 

I have the code:

$sSql = $vehicles->SelectSQL();

 

I edited that function to include:

// Table level SQL

function SqlSelect() { // Select
return "SELECT * FROM `vehicles`";


}

function SqlWhere() { // Where Type
return "type= '". mysql_real_escape_string($_GET['type']) . "'";              //Used to say just return "";

}

function SqlGroupBy() { // Group By
return "";

}
function SqlHaving() { // Having
return "";

}
function SqlOrderBy() { // Order By
return "";

}

 

Now I have a working sort on all of my pages that have a specified type (in example: http://www.example.com/inventory.php?type=car )

 

The problem is that if I have no type, then it lists no vehicles.

How can I use an if/then statement or the empty() to make it not display a type if there is no type listed?

 

Thanks again everyone!

  Quote

How can I use an if/then statement or the empty() to make it not display a type if there is no type listed?

 

Pretty much as you describe there. The logic is: if the variable is not empty, search using the variable. If it's not, dont add a where clause.

  Quote

  Quote

How can I use an if/then statement or the empty() to make it not display a type if there is no type listed?

 

Pretty much as you describe there. The logic is: if the variable is not empty, search using the variable. If it's not, dont add a where clause.

 

The closest I can come is:

function SqlWhere() { // Where Type	

return (!empty($_GET['type'])) ? "type = '". mysql_real_escape_string($_GET['type']) . "' : "";

}

What gamerzfuse means, is, below...

function SqlWhere() { // Where Type
  return (!empty($_GET['type'])) ? "type = '". mysql_real_escape_string($_GET['type']) . "'" : "";
//return (!empty($_GET['type'])) ? "type = '". mysql_real_escape_string($_GET['type']) . "' : "";
}

Look closely, you weren't closing out your final single quote after the mysql_real_escape_string().

I've left yours in as commented out so you can see what you missed.

Hope that helps.

  Quote

What gamerzfuse means, is, below...

function SqlWhere() { // Where Type
  return (!empty($_GET['type'])) ? "type = '". mysql_real_escape_string($_GET['type']) . "'" : "";
//return (!empty($_GET['type'])) ? "type = '". mysql_real_escape_string($_GET['type']) . "' : "";
}

Look closely, you weren't closing out your final single quote after the mysql_real_escape_string().

I've left yours in as commented out so you can see what you missed.

Hope that helps.

 

I used that and now I get an unexpected T_Var?

Thanks though, if you could just advise me on this one last thing.. I'll be done with this site almost.

 

Noob mistake. Left in an extra }

Works great.

Hopefully this fixes all my problems!

Thanks for the tolerance Ken ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.