gears Posted April 25, 2006 Share Posted April 25, 2006 Guys,I've written a really quick and rather crappy script which compares two tables. It does this because my content management system on www.coolsmartphone.com puts news stories in one table, but the commenting system uses another table. Anyhoo, I wrote a script that compares the two fields in two tables and fires out the result as a URL, so that users can click the appropriate link. All is well until I enter a news item with a subject like "It's here" or "That's the way to do it" etc etc - you get the picture. Although the "LIKE" command in MySQL is doing it's job, the "mysql_result($leigh2, 0);" isn't working when a -- ' -- is in the subject line. How do I get it to select it and IGNORE that ? The -- ' -- symbol can't be changed in the database, so I need some way of saying, "grab this field as a whole".Here's the script. Yes, crap.. yes, there's probably a neater way of doing it.. but I was drunk at the time I wrote it.. :)<?php$titlenew = htmlspecialchars("$title[$i]");$leigh="SELECT * from phpbb_topics where topic_title LIKE '$titlenew'";$leigh2=mysql_query($leigh) or die("Could not select it");$leigh3=mysql_fetch_array($leigh2);$thelinky=mysql_result($leigh2, 0);$thecounter=mysql_result($leigh2, 0, 6);if(!$leigh3){ echo "No link yet";}else{ print "<a href=\"http://www.coolsmartphone.com/forum/posting.php?mode=reply&t=$thelinky\"><B>Add</a></b> or <a href=\"http://www.coolsmartphone.com/forum/viewtopic.php?t=$thelinky\"><B>view comments ($thecounter)</a></b>";}?> Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted April 25, 2006 Share Posted April 25, 2006 You need to look into strip_slashes and add_slashes.The database my have the titles stored as:That\'s the way to do itand you query is looking for:That's the way to do itor vice versa. Quote Link to comment Share on other sites More sharing options...
gears Posted April 25, 2006 Author Share Posted April 25, 2006 [!--quoteo(post=368355:date=Apr 25 2006, 11:10 AM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ Apr 25 2006, 11:10 AM) [snapback]368355[/snapback][/div][div class=\'quotemain\'][!--quotec--]You need to look into strip_slashes and add_slashes.The database my have the titles stored as:That\'s the way to do itand you query is looking for:That's the way to do itor vice versa.[/quote]Excellent ! What a muppet I am for not finding that :) Changed it to ...<?php$titlenew = addslashes(htmlspecialchars("$title[$i]"));......and everything works fine! :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.