Jump to content

Mysql LIKE operator not working for safari


NealeWeb

Recommended Posts

 

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

 

Link to comment
Share on other sites

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 )

Link to comment
Share on other sites

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 %  :wtf:

especially if the $search contains a-Z caracters

 

Eh, what? You can search INT fields...

Link to comment
Share on other sites

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 ...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.