ClanKiller.com
https://forums.plasmasky.com/

Output result after textmatching (php)
https://forums.plasmasky.com/viewtopic.php?f=8&t=1446
Page 1 of 1

Author:  Mole [ Mon Sep 26, 2005 2:52 pm ]
Post subject:  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]

Author:  Satis [ Mon Sep 26, 2005 5:29 pm ]
Post subject: 

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.

Author:  Satis [ Mon Oct 03, 2005 4:23 pm ]
Post subject: 

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.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/