[ale] Querying a MySQL database from PHP

Mike Lockhart backpacker at hikers.net
Fri Sep 20 12:06:32 EDT 2002


$varSort_search = "%";

if(code here)
 $varSort_search1 .= (test and return here)

$varText_search1 = "%"

if(code here)
 $varText_search1 .= (test and return here)


Notice the .=  , its important. :)  Hope that helps 'ya.

-- mike


On Fri, 2002-09-20 at 10:23, John Cole wrote:
> Howdy all!
> 
> I've built a page in Dreamweaver MX that uses PHP for scripting.  I can get
> data out of my mysql database but I need to be able to search for wildcards.
> currently it only matches 100% exact queries.
> Below is the code that is at the beggining of the PHP page.
> -----------
> $varSort_search1 = "%";
> if (isset($HTTP_POST_VARS["Sort"])) {
>   $varSort_search1 = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS["Sort"] :
> addslashes($HTTP_POST_VARS["Sort"]);
> }
> $varText_search1 = "%";
> if (isset($HTTP_POST_VARS["Text"])) {
>   $varText_search1 = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS["Text"] :
> addslashes($HTTP_POST_VARS["Text"]);
> }
> mysql_select_db($database_CATCH, $CATCH);
> $query_search1 = sprintf("SELECT * FROM secureworks WHERE %s LIKE  '%s'",
> $varSort_search1,$varText_search1);
> $search1 = mysql_query($query_search1, $CATCH) or die(mysql_error());
> $row_search1 = mysql_fetch_assoc($search1);
> $totalRows_search1 = mysql_num_rows($search1);
> 
> -------------
> 
> Does anyone have any ideas?
> 
> Thanks,
> John Cole, TCISA
> 
> Help Desk Administrator
> Lockheed Georgia Employees' Federal Credit Union
> 430 Commerce Park Drive
> Marietta, GA 30060 
> (770) 424-0060
> (800) 541-8921 
> jcole at lgefcu.org
> Disclaimer: The information contained in this email is proprietary and
> confidential.  It is intended solely for the use of the person identified
> and intended as the recipient. This document is forwarded to you in such a
> form (E-mail) that LGEFCU cannot guarantee the completeness and/or
> correctness of its contents and information. If you have received this
> E-mail message in error, please notify us immediately. Please also delete
> this document from your computer. This document may not be reproduced,
> copied, distributed, published, modified, or furnished to third parties,
> without the prior written consent of LGEFCU. LGEFCU specifically disclaims
> any responsibility or liability for any personal information or opinions of
> the author expressed in this email.
> 
> ---
> This message has been sent through the ALE general discussion list.
> See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
> sent to listmaster at ale dot org.
> 
-- 

================================
Michael Lockhart - PHP Developer
Intercosmos Media Group
mailto:mlockhart at intercosmos.com
http://orbital.intercosmos.net
================================

 This is a digitally signed message part




More information about the Ale mailing list