Forum Moderators: coopster

Message Too Old, No Replies

SQL: LIKE to select url?

         

carsten888

6:36 pm on Dec 3, 2009 (gmt 0)

10+ Year Member



I need to select certain links in a content table.

this works


$non_sef_url_old = 'id=2537';
$database->setQuery("SELECT id, introtext FROM #__content WHERE introtext LIKE '%".$non_sef_url_old."%' ");

obviously, this does not only return the content with the links, but also other content which happen to contain 'id=2537'. So to refine this to just select the link, so I search for the whole link:


$non_sef_url_old = 'index.php?option=com_content&view=article&id=2537:test-content&catid=39:news&Itemid=70';
$database->setQuery("SELECT id, introtext FROM #__content WHERE introtext LIKE '%".$non_sef_url_old."%' ");

but this returns nothing. even thou the exact string is clearly in the content. I copy-paste the string to make sure.

What am I overlooking?

rocknbil

10:37 pm on Dec 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you say exact, are you sure? I ask because of this little critter.

&

When you query a database, it resolves to the browser as &, even in form fields. If you apply htmlentities to a value before inserting you can get

&

I'll suggest something else, storing a big query string like this is going to give you many many headaches. Instead of

index.php?option=com_content&view=article&id=2537:test-content&catid=39:news&Itemid=70

consider

rec_id¦script...¦option.....¦action.¦art_id¦cat¦item
1.....¦index.php¦com_content¦article¦2537..¦39 ¦70

or something. It may be a hassle to set up, but would be far easier to manage and less of a burden on your database.

carsten888

7:36 am on Dec 4, 2009 (gmt 0)

10+ Year Member




When you say exact, are you sure?

truns out I made a typo. got it working now.


consider

rec_id¦script...¦option.....¦action.¦art_id¦cat¦item
1.....¦index.php¦com_content¦article¦2537..¦39 ¦70


maybe easyer on the database, but then each time the content is displayed it needs to be translated into html, which adds server load. Anyway, this is the html as used in any editor in Joomla, so I won't change any of that.

Thanks for reply.

rocknbil

9:39 pm on Dec 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, all good. A small change to your PHP doesn't add to server load. Programmer work load, maybe. :-)