AW: [SMARTY] Define SQL search queries with PHP
| From: | Thorsten Schmidt | Date: | Wed, 26 Mar 2003 09:21:22 +0000 |
| Subject: | AW: [SMARTY] Define SQL search queries with PHP | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-8914@lists.php.net to get a copy of this message | ||
> -----Ursprüngliche Nachricht-----
> Von: Alan Lam [mailto:alan@goodorient.com.cn]
> Gesendet: Mittwoch, 26. März 2003 10:01
> An: smarty-general@lists.php.net
> Betreff: [SMARTY] Define SQL search queries with PHP
>
>
> I'm afraid this is more of a php question than smarty, but
> I'm stuck on this problem with sql queries. Sorry to trouble
> you all with this.
>
> $result = func_query("SELECT categoryid, FROM
> $sql_tbl[categories] WHERE category LIKE
> '".addslashes($category_name)."%'");
Dear,
first of all, remove the "," after the categoryid : )
> I'm trying to search the query from $category_name (ie.
> Computer/Hardware/Joystick ) and return the string before the
> last "/"(ie. Computer, Computer/Hardware).*note queries can
> return Computer, Computer/Hardware,
> Computer/Hardware/Joystick, I need the search to return
> strings without slash as well...* I've modified it to this:
OK, lets see if I understood you right.
If you have a string "Computer/Hardware/Joystick" you need only the word
"Hardware" from it, right?
$string = "Computer/Hardware/Joystick";
$pos = strrpos($string, "/");
$string = substr($string, 0, $pos);
$pos = strrpos($string, "/");
$search = substr($string, $pos +1);
Then you could build up your SQL query
WHERE category LIKE '$search'
I hope this will help you
bye
Thorsten
> WHERE category LIKE '"strrev( strchr(strrev($category_name),"/")
> )'");
>
> I also tried !strstr($category_name,"/") as well, but no cigar...
>
> but displaying the page gives me a Parse error on top. What
> am I doing wrong with the code?
>
> Distressed, thanks in advance to all of you!
>
> Alan Lam
> alan@goodorient.com.cn
> Web Developer
> www.goodorient.com
>