NealeWeb Posted September 10, 2012 Share Posted September 10, 2012 Hi guys i am trying to search results from a database using SELECT * FROM table_name WHERE event LIKE '%" . $search . "%' OR date LIKE '%" . $search . "%' This works fine in Firefox and in IE, but when i try it in safari, it seems to pull up the right results but then straight away changes and gives me all the results from the table. I am sure it has soomething to do with the LIKE operator because when i tried SELECT * FROM table_name WHERE date = (the date i was trying to search for) It worked fine. So the only difference was i just manually told it what to look for. And it worked Quote Link to comment https://forums.phpfreaks.com/topic/268213-mysql-like-operator-not-working-for-safari/ Share on other sites More sharing options...
cybernet Posted September 10, 2012 Share Posted September 10, 2012 1st of all i don't know the problem that you're experiencing, but php is executing the SQL statement, not Safari, so the problem is in your code let me give you a hint if the $search contains a-Z caracters you can't SELECT text on a numeric field ( int, TINYINT, MEDIUMINT, and BIGINT ) Quote Link to comment https://forums.phpfreaks.com/topic/268213-mysql-like-operator-not-working-for-safari/#findComment-1376665 Share on other sites More sharing options...
Jessica Posted September 10, 2012 Share Posted September 10, 2012 it seems to pull up the right results but then straight away changes and gives me all the results from the table. I can only assume you're doing an ajax powered search? Quote Link to comment https://forums.phpfreaks.com/topic/268213-mysql-like-operator-not-working-for-safari/#findComment-1376667 Share on other sites More sharing options...
scootstah Posted September 10, 2012 Share Posted September 10, 2012 SELECT * FROM table_name WHERE event LIKE '%" . $search . "%' OR date LIKE '%" . $search . "%' Assign your query to a variable, and then echo it out so that we can see the actual query being run (after the variables are evaluated). Like this: $query = "SELECT * FROM table_name WHERE event LIKE '%" . $search . "%' OR date LIKE '%" . $search . "%'"; echo $query; if the mysql field is *int ( which means numeric ) type you can't use % $search % especially if the $search contains a-Z caracters Eh, what? You can search INT fields... Quote Link to comment https://forums.phpfreaks.com/topic/268213-mysql-like-operator-not-working-for-safari/#findComment-1376670 Share on other sites More sharing options...
cybernet Posted September 10, 2012 Share Posted September 10, 2012 Eh, what? You can search INT fields... that's why i edited the post cause i tested my "advice" i replied like that cause i thought in a logical way / how can you search for a-Z in a numeric field / it's impossible to find because mysql doesn't accept text in int field / so why run the query ... Quote Link to comment https://forums.phpfreaks.com/topic/268213-mysql-like-operator-not-working-for-safari/#findComment-1376676 Share on other sites More sharing options...
scootstah Posted September 10, 2012 Share Posted September 10, 2012 Eh, what? You can search INT fields... that's why i edited the post cause i tested my "advice" i replied like that cause i thought in a logical way / how can you search for a-Z in a numeric field / it's impossible to find because mysql doesn't accept text in int field / so why run the query ... Who said $search contains non-int characters? MySQL will just typecast it anyway. Quote Link to comment https://forums.phpfreaks.com/topic/268213-mysql-like-operator-not-working-for-safari/#findComment-1376679 Share on other sites More sharing options...
PFMaBiSmAd Posted September 10, 2012 Share Posted September 10, 2012 I'm going to guess that either the browser is requesting the page twice (different browsers do that for different reasons) and the second time it submits a $search term that causes all the results to be returned or that you actually have the posted query AND another query on the page that intentionally returns all the results and due to a logic error in your code, that only shows up for the one browser (due to a race condition or how the browser handles errors in the markup or how it handles redirects...), that the second query is executed and returns all the results. For problems like this - i.e. I have a page that doesn't work, it takes seeing and having all your code that reproduces the problem. The problem isn't the query (it is just doing what it is told to do), but either the data being put into the query or how many times that query (or another query on the page) is being executed. Quote Link to comment https://forums.phpfreaks.com/topic/268213-mysql-like-operator-not-working-for-safari/#findComment-1376687 Share on other sites More sharing options...
cybernet Posted September 10, 2012 Share Posted September 10, 2012 Eh, what? You can search INT fields... that's why i edited the post cause i tested my "advice" i replied like that cause i thought in a logical way / how can you search for a-Z in a numeric field / it's impossible to find because mysql doesn't accept text in int field / so why run the query ... Who said $search contains non-int characters? MySQL will just typecast it anyway. i presumed that backend user wont search for 1347289747 Quote Link to comment https://forums.phpfreaks.com/topic/268213-mysql-like-operator-not-working-for-safari/#findComment-1376690 Share on other sites More sharing options...
scootstah Posted September 10, 2012 Share Posted September 10, 2012 Eh, what? You can search INT fields... that's why i edited the post cause i tested my "advice" i replied like that cause i thought in a logical way / how can you search for a-Z in a numeric field / it's impossible to find because mysql doesn't accept text in int field / so why run the query ... Who said $search contains non-int characters? MySQL will just typecast it anyway. i presumed that backend user wont search for 1347289747 They don't have to. They could search a human-readable date (like Sep 09, 2012) which gets converted to a UNIX timestamp or DATETIME. Quote Link to comment https://forums.phpfreaks.com/topic/268213-mysql-like-operator-not-working-for-safari/#findComment-1376692 Share on other sites More sharing options...
NealeWeb Posted September 10, 2012 Author Share Posted September 10, 2012 Hi guys and wow, thanks for all the replies but while i was away waiting i was just playing with the code, changing things to see if i could get it to work and i found that it actually isnt the query thats the problem its something else i have on the page. I have a small page transition script that i found on the internet and when i removed it, it all worked fine. So now i just need to figure out why it is affecting my page as it only happens when i try to submit a form. Here is the script: <script type="text/javascript"> (function inittrans() { var params = //All params are optional, you can just assign {} { "navB" : "slide reverse", //Effect for navigation button, leave it empty to disable it "but" : true, //Flag to enable transitions on button, false by default "cBa" : onTransitionFinished // function() { alert("Done!"); } //callback function }; new ft(params); })(); function onTransitionFinished() { //Do anything you want } </script> And in all my links i have, data-ftrans="slide" after the href. I got the script from here: http://www.fasw.ws/faswwp/non-jquery-page-transitions-lightweight/ Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/268213-mysql-like-operator-not-working-for-safari/#findComment-1376696 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.