RE: [PHP] conditional within SELECT

From: Martin Towell (martin.towell_at_world.net)
Date: 10/30/03


To: "'rkerr@digitaliguana.com'" <rkerr@digitaliguana.com>,  php-general@lists.php.net
Date: Thu, 30 Oct 2003 12:03:32 +1100

Try something like this:

$sql = "SELECT robeson_inv.manufacturer, robeson_inv.model,";
$sql .= " robeson_inv.specs, robeson_inv.qty, robeson_inv.ID";
$sql .= " FROM robeson_inv";
$sql .= " WHERE robeson_inv.manufacturer = 'vManufacturer'";
if ($vKeywords)
  $sql .= " AND MATCH (robeson_inv.specs) AGAINST ('$vKeywords')";
$sql .= " ORDER BY robeson_inv.model";

Martin

-----Original Message-----
From: Robb Kerr [mailto:rkerr@digitaliguana.com]
Sent: Thursday, 30 October 2003 11:59 AM
To: php-general@lists.php.net
Subject: [PHP] conditional within SELECT

Here's another newbie question. The SELECT statement below gets its values
from the URL of the page. When something is entered for "vKeywords" the
SELECT works fine and returns the correct records. However, if nothing is
entered for "vKeywords" (which should return all records matching the other
criteria), the results are NO records. How do I make the "MATCH
(robeson_inv.specs) AGAINST ('vKeywords')" part of the SELECT statement
conditional?

SELECT robeson_inv.manufacturer, robeson_inv.model, robeson_inv.specs,
robeson_inv.qty, robeson_inv.ID
FROM robeson_inv
WHERE MATCH (robeson_inv.specs) AGAINST ('vKeywords') AND
robeson_inv.manufacturer = 'vManufacturer'
ORDER BY robeson_inv.model

Thanx,

-- 
Robb Kerr
Digital IGUANA
Helping Digital Artists Achieve their Dreams
http://www.digitaliguana.com
http://www.cancerreallysucks.org
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Relevant Pages

  • Re: [PHP] SQL Readability.. (was Re: most powerful php editor)
    ... Subject: [PHP] SQL Readability.. ... Your switchon the gettypeof the value misses the type 'boolean' so it falls through the default: case which then appends whatever was left from the previous pass. ... >> SELECT blah, blah, blah, blah, blah, blah, blah, blah, blah ...
    (php.general)
  • Re: Making groups
    ... It's actually the native array type in PHP. ... PHP is not SQL, Tcl is not SQL, C is not SQL, Python ... An ordered list is not a dict. ... Procedural and Object programmers can't ...
    (comp.lang.tcl)
  • Re: Techniques for Vulneability discovery
    ... in mind) so i searched the net for some free database driven software and came ... the first thing i did was grab some info about PHP programming and some MySQL ... I did some more reasearch on different types of web based "input validation" ... PHP and SQL docs, etc.. ...
    (Vuln-Dev)
  • Re: Techniques for Vulneability discovery
    ... in mind) so i searched the net for some free database driven software and came ... the first thing i did was grab some info about PHP programming and some MySQL ... I did some more reasearch on different types of web based "input validation" ... PHP and SQL docs, etc.. ...
    (Security-Basics)
  • fwd: Intresting case of SQL Injection
    ... we found an interesting case of SQL Injection. ... The application was developed under PHP 4.2.1, ... We started our tests by adding a ' (single quote) to the POST info. ... we wanted to insert a record on the "users" table (fields username ...
    (perl.dbi.users)