RE: Struggling with MySQL query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: David Green [mailto:simpill@xxxxxxxxx]
> Sent: Tuesday, August 09, 2011 10:14 AM
> To: php-general@xxxxxxxxxxxxx
> Subject:  Struggling with MySQL query
> 
> Hi
> 
> I have a simple from which uses the post method to get to my page
> script
> results.php
> 
> in results.php I have
> 
> $find=$_POST["find"]; //this works perfectly, echo $find gives me the
> search
> term as entered
> 
> I then connect to mysql and select the db successfully.
> 
> After that, I have the following:
> 
> $find = strtoupper($find);
> $find = strip_tags($find);
> $find = trim($find);
> 
> $data = mysql_query("SELECT * FROM news_items WHERE upper('headline')
> LIKE
> '%$find%'");
> 
> while($result = mysql_fetch_array($data)) { //etc
> 
> I get no error messages, but no results to work with either.  It
> returns a
> "no results" message that I put in further on in the script.  A casual
> look
> at the db shows that I should be getting results.  I'm pretty sure that
> the
> problem is in the query, but for the life of me I can't see the
> problem.
> 
> Kind regards
> David


Suggestion:

$query = "SELECT * FROM news_items WHERE UPPER(headline) LIKE
'%".mysql_real_escape_string($find)."%' ";
$result = mysql_query($query);

//Check your syntax display any errors.
Echo mysql_error();
Echo mysql_errno();

If(mysql_num_rows($result)>= 1) {
	While($row = mysql_fetch_assoc($result))
	{	
		print_r($row);
	}
}else{
Echo 'nothing to show';
}









-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux