[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 383
  • Last Modified:

PHP create a wildcard string if GET empty

Hi,

I have this chunk of PHP that I needed to create a wildcard % to be used in a query if no $_GET was found:


 
<?php
if (!isset($_GET["Sub_Category"]) || empty($_GET["Sub_Category"])) {
     $scat = '%';
	} else {
	 $scat = ($_GET['Sub_Category']);
}
?>

Open in new window


Any thoughts
Thanks
Tony
0
tonypearce
Asked:
tonypearce
  • 2
1 Solution
 
FinecCommented:
If you're looking for a shorter solution:

$scat = empty($_GET['Sub_Category']) ? '%' : $_GET['Sub_Category'];

Open in new window


Or what's the question? :)
0
 
Ray PaseurCommented:
What is the question?  The code posted here will set $scat to be a string of length=1 and content=% if the URL does not have the Sub_Category argument.  Is that what you want?
0
 
tonypearceAuthor Commented:
perfect despite my bad question!!
0
 
Ray PaseurCommented:
Just a thought.. You might want to leave the questions open a little longer and maybe give a little more expository content with the question.  For example, I sense that you might be wanting to use the $scat variable in a data base query (this is a common design pattern).  Before you do that you might want to post a question here about something like, "What are the well-known best security practices that can help me keep my data base from getting destroyed or stolen by hackers?"
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now