It is currently Tue Jul 22, 2025 2:29 am



Reply to topic  [ 3 posts ] 
Output result after textmatching (php) 
Author Message
Minor Diety
User avatar

Joined: Fri Apr 11, 2003 5:09 pm
Posts: 4004
Location: Walsall, West Mids, UK
Reply with quote
Post Output result after textmatching (php)
Here's my code

Code:

if (!isset($_POST['location'])) {
    echo "No location selected";
}
else {
    $q = $_POST['location'];
   
    $sql = " SELECT * FROM arena WHERE location = '". mysql_real_escape_string($q) ."' ";
   
    // do query & show results
    echo "Results for search (<b>". $q ."</b>) :";
}


In a nut shell, how do I output the results of the search? [/code]

_________________
Games to complete:
GTA IV [100%] (For Multiplayer next!)
Fallout 3 [50%]
Rock Band [35%]
http://www.cafepress.com/SmeepProducts


Mon Sep 26, 2005 2:52 pm
Profile WWW
Felix Rex
User avatar

Joined: Fri Mar 28, 2003 6:01 pm
Posts: 16701
Location: On a slope
Reply with quote
Post 
Code:
//set up MySQL connection
$host = "mysql server hostname";
$username = "username";
$password = "password";
$db = mysql_connect($host, $username, $password);
if (!$db){
   echo "Error: Database connection failure.";
   exit;
   };
mysql_select_db("database name",$db);

//execute query
$result = mysql_query($sql);

//iterate through results as associate array
while($row = mysql_fetch_array($result)){
     echo $row['fieldname'] .'<br>';
}


obviously it gets more cimplicated than that. I also recommend pulling the sql server connection stuff (host, username, password, database) into an external file and just including it prior to running a query.

_________________
They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.


Mon Sep 26, 2005 5:29 pm
Profile WWW
Felix Rex
User avatar

Joined: Fri Mar 28, 2003 6:01 pm
Posts: 16701
Location: On a slope
Reply with quote
Post 
hey, FYI, if you're still using database stuff with PHP and MySQL...

you really might want to check out ADODB. It's a database abstraction layer. What it boils down to is, with ADODB you can use the exact same commands to access different database types (ie, MySQL vs MS-SQL vs Access vs ODBC). With PHP you can access all those, but the commands are entirely different. So, if you change database servers, you have to rewrite all your code.

Also, ADODB returns results in a standard array you can use standard array functions on, instead of wierd results pointers you have to use specialized commands against (ie, mysql_fetch_array).

I ignored ADODB for awhile, and now I'm regretting it. I'm now attaching to various databases (MySQL is my main one, but also MS-SQL, Sybase and ODBC) and ADODB is indispensable.

http://adodb.sourceforge.net/

The only thing I can bitch about is that the documentation stinks.

_________________
They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.


Mon Oct 03, 2005 4:23 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware.