RE: [PHP-DB] Removing first word from a string?
| From: | Bastien Koert | Date: | Tue, 04 Jan 2005 05:20:23 +0000 |
| Subject: | RE: [PHP-DB] Removing first word from a string? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-37963@lists.php.net to get a copy of this message | ||
one simple trick is to use a clause that always evaluates correctly. For example, in my site I don't delete data, but flag it with a field (record_deleted) which defaults to 'No' (actually 0) and can be set to 'Yes' (again 1) so that all queries are built with the requirement to use AND
ie
$sql = "select * from tablename where record_deleted = 0 "
//code to delevop additional where paramters goes here
if (!empty($_POST['city'])){
$sql .= " AND city like '{$_POST['city']}%' ";
}//end if
you could also use the same mechanism that PHPMYAdmin does which is to 1
select * from tablename where 1
since one always evaluates to true and does not affect the query, its a simple way of doing the same as above
bastien
From: "Chris Payne" <cjp@planetoxygene.com> To: <php-db@lists.php.net> Subject: [PHP-DB] Removing first word from a string? Date: Mon, 3 Jan 2005 21:46:03 -0500 Hi there everyone, I am building a dynamic MySQL query for a project I am working on, but there are instances where it products WHERE AND instead of WHERE city etc .. due to the nature of the system I am developing. My question is, how can I remove the FIRST AND from a string if it is present, but leave all other AND statements in the string? I would really appreciate any help on this. I can do a find and replace on a string no problem, but just want it to be removed IF it is the FIRST word in the string. Oh and Happy New Year everyone. Chris -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.296 / Virus Database: 265.6.7 - Release Date: 12/30/2004