Help - Search - Members - Calendar
Full Version: Database Search Script
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
MrTouz
ok i just finished my script on the writing the database... so all my infos are stored.

now i am trying to find a GOOD correct script wich will allow a user of my site to search inside this database.

Anyone know a good script ? ofcourse like always, sicne im new to this... i need a simple script and/or well explained on the tutorial because i really understand nothing to it... well i do.. but some stuff only :/


Thanks in advance smile.gif
Earpy
What type of database are you using? Is it MySQL?
Luke
Correct me if I'm wrong but, assuming your using mysql, you can use queries? I really don't know much about php and mysql. I'm getting to it. I think you could make a request from the database... using a form? I could be completely wrong, I don't know. This also helps me out so... I'm benefiting too smile.gif
Ed
This should help:
http://devzone.zend.com/node/view/id/1304
Sickness
There is my script
CODE
<?php
//----------------------------------------------------------------
//
// Search page with key word or just word
//
// search.php
//
//----------------------------------------------------------------

$mysql_host = 'localhost'; // enter your host name
$mysql_user = 'login'; // enter your login
$mysql_password = 'password'; // enter your password
$mysql_base = 'database name'; // enter your database name


//You sign in the database
$db = mysql_connect($mysql_host,$mysql_user,$mysql_password) or die ("connexion error");

//you select your database
mysql_select_db($mysql_base,$db) or die ("erreur de connexion
base");


//search request
$req = mysql_query("SELECT * from your_table where mots_cles LIKE '%$_POST[searchword]%' Order by url Asc ") or die ("request error ".mysql_error());

//we count the result
$res= mysql_num_rows($req);

//we show the number of result
print '  There are '.$res.' for '.$searchword.' results <br>';

//----------------------------------------------------------------------
//We show the information by alphabetical order

while( $result = mysql_fetch_array($req))
{

print '<strong>'.$result['name'].'</strong><br / >';
print $result['description'].'<br />';
print'<a href="'.$result['url'].'">'.$rsult['url'].'</a><br / >';
print '-----------------------------------------------------------------'; // it's just a separation line
}//end of the while function

//we close the mysql connection
mysql_close();



?>
Luke
Nice work sickness wink.gif Strange this is... I can understand that! Just can't code it smile.gif
Ed
QUOTE(Luke @ Oct 23 2007, 12:44 AM) *
Strange this is... I can understand that! Just can't code it smile.gif


That would be the one of the primary stages of learning any language, once you've got there you just need to stick at it by writing everything and anything until you start to retain the pieces of code you use. Start simple is the best advice, then from that simply expand upon it, don't set HUGE goals, start small and progress. I remember how I first got started, I wrote a simple flatfile tagboard and slowly improved it, turned it into MySQL, added some administration features... before long it became feature packed and I had learnt a hell of a lot. Just stick at it!

The forum is always willing to answer programming questions, if you're not too broad in your questioning you'll get the right answer. smile.gif
Luke
Thanks Bread... I'll keep that in mind ;P I guess it's always better to learn from experience rather than reading a manual and expecting to remember everything and know all! smile.gif Oh, I just realized I was talkin like yoda. smile.gif 'Strange this is...' wink.gif lol Thanks again!
Sickness
I've just stick all my script, to be easy for learning
EMOruffino
QUOTE(Bread @ Oct 22 2007, 06:58 PM) *
That would be the one of the primary stages of learning any language


very true....... take myspaces for a quick example....
Luke
Wow... I really never thought of it but I guess myspace has inspired a lot of people. From the CSS coding. A LOT of people must have begun their designing career there! smile.gif
EMOruffino
QUOTE(Luke @ Oct 22 2007, 08:23 PM) *
Wow... I really thought of it but I guess myspace has inspired a lot of people. From the CSS coding. A LOT of people must have begun their designing career there! smile.gif

its true..... i seen some "STORIES" on the tube...

anywayz, but the database you use.. is it mysql? or is it portuguese or what?
MrTouz
Well im using MySql database.

i think what sickness just poseted is what i need.
Because i have a script already but it has been implemented into PHPBB3 by a friend, thing i si can't eather extract or modify... well hardly...

btw i see some stuff are in french smile.gif good thing.. im french smile.gif

im at school right now... and im gonna test that at home ill let you know if it worked smile.gif
Sickness
QUOTE(MrTouz @ Oct 23 2007, 01:46 PM) *
btw i see some stuff are in french smile.gif good thing.. im french smile.gif

im at school right now... and im gonna test that at home ill let you know if it worked smile.gif

Oh sorry, I've forgot to translate all the script....
MrTouz
np like i said... im french so i can read and write it tongue.gif

oops btw im not sure what to edit, well some spot i dont really understand, can you please enlight what i have to edit ? thanks....

soz for being so nooby... i really really suck at php... even tho im geting a bit better at reading... i still get confused sometimes :/
Sickness
QUOTE(Sickness @ Oct 22 2007, 11:43 PM) *
There is my script <code><?php
//----------------------------------------------------------------
//
// Search page with key word or just word
//
// search.php
//
//----------------------------------------------------------------

$mysql_host = 'localhost'; // enter your host name
$mysql_user = 'login'; // enter your login
$mysql_password = 'password'; // enter your password
$mysql_base = 'database name'; // enter your database name
//You sign in the database
$db = mysql_connect($mysql_host,$mysql_user,$mysql_password) or die ("connexion error");

//you select your database
mysql_select_db($mysql_base,$db) or die ("connexion error
base");
//search request
$req = mysql_query("SELECT * from your_table where mots_cles LIKE '%$_POST[searchword]%' Order by url Asc ") or die ("request error ".mysql_error());

//we count the result
$res= mysql_num_rows($req);

//we show the number of result
print ' There are '.$res.' for '.$searchword.' results <br>';

//----------------------------------------------------------------------
//We show the information by alphabetical order

while( $result = mysql_fetch_array($req))
{

print '<strong>'.$result['name'].'</strong><br / >';
print $result['description'].'<br />';
print'<a href="'.$result['url'].'">'.$rsult['url'].'</a><br / >';
print '-----------------------------------------------------------------'; // it's just a separation line
}//end of the while function

//we close the mysql connection
mysql_close();
?></code>



QUOTE(MrTouz @ Oct 23 2007, 09:34 PM) *
np like i said... im french so i can read and write it tongue.gif

oops btw im not sure what to edit, well some spot i dont really understand, can you please enlight what i have to edit ? thanks....

soz for being so nooby... i really really suck at php... even tho im geting a bit better at reading... i still get confused sometimes :/



All the text in red are to edit,

just a question/juste une question MrTouz d'où tu vient de france québec etc..../from where are you french quebec etc....
MrTouz
thanks for the highlighted part smile.gif you rock dude !

je vien de Paris smile.gif si tu ve vrement savoir pk je te demande ce system... je fini un site de rencontre, et un de mes ami devai le finir avec moi... il est le codeur en PHP mais il a eu un pti problem donc il ne peut pas finir... donc jusqu ici j'ai reussi a faire le script qui envoi les données sur la base... et maintenant ba je v le finir en faisait des recherche sur la base de données. c un site en francais... je te le montreri une foi terminer smile.gif

edit : so i forgot to translate for others... :

i basicly told him where i was from (Paris) and told him why i neede this script.. basicly for a meeting site, well beterthan meeting... its more over a founding site...

Thanks again smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.