Using web links in variables |
I am having a particular problem working with web URLs in Codeigniter, and am not sure whether it is a Codeigniter problem or a php one.
Basically, I am retrieving an html email from an email marketing application database, searching it for links and looking up the links in another table in the application. I am retrieving the html from the table using: Code: $db_ac->where_in('id', $messageids); I originally used the link and another necessary identifier to count how many occurrences there are of this link in a table (we are basically talking how many people clicked on a link). Code: $q = 'SELECT `em_link`.`id`, `link`, count(em_link_data.id) as uniq, sum(em_link_data.times) as multi FROM (`em_link`) left JOIN `em_link_data` ON `em_link_data`.`linkid` = `em_link`.`id` WHERE `messageid` IN (' . $messageidsstr . ') AND `link` = "' . $link . '" GROUP BY `em_link`.`link`'; This did not work all the time, and some links returned no results, so I echo'd the last_query and if I pasted that into phpmyadmin the results incorrect in my code come back correct. I then chose a long-winded method, which got all links for the identifier . . . Code: $q1 = 'SELECT `em_link`.`id`, `link`, count(`em_link_data`.`id`) as uniq, sum(`em_link_data`.`times`) as multi FROM (`em_link`) LEFT JOIN `em_link_data` ON `em_link_data`.`linkid` = `em_link`.`id` WHERE `em_link`.`messageid` = ' . $id . ' GROUP BY `link`'; . . . and then ran through them comparing the link from the database with the link from the html: Code: foreach ($clicks_sin->result() as $sgl_row): However, even here the code will still not match the two links, which when they both are echo'd come out as: http://www.catchup.org/training/signup.a...=brochure1 http://www.catchup.org/training/signup.a...=brochure1 which as you can see are identical. The table I am getting the full html from holds that in a longtext(utf8_general_ci) field, and the link I am searching for is held in another table as a text(utf8_general_ci) field. As I said, it is happening randomly, the majority of links are searched for perfectly. The only specific difference I can see so far is that the ones that don't work are maybe a bit longer links. I feel like I'm going mad, does anyone have any ideas? The installation details are as follows:
Thanks for all replies! Gz
Maybe there are spaces after the links? try trimming the link just before comparing them.
Website: http://avenir.ro
There are several notes in the PHP manual regarding various issues with attempting to do string comparison, at least one of which mentions that strings may be zero-terminated if they are pulled from certain sources.
As Avenirer noted, in this case you probably want to trim the strings before doing the comparison. You should also use !== or === instead of != and consider using the strcmp() and/or strcasecmp() functions. |
Welcome Guest, Not a member yet? Register Sign In |