RE: [PHP] conditional within SELECT

From: Date: Thu, 30 Oct 2003 01:03:32 +0000
Subject: RE: [PHP] conditional within SELECT
Groups: php.general 
Request: Send a blank email to php-general+get-168096@lists.php.net to get a copy of this message
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

« previous php.general (#168096) next »