Subscribe:

Jumat, 06 April 2012

Tutorial Membuat PHP Search Engine

Ok jadi kali ini adalah tentang tutorial Cara membuat Search Engine Anda Sendiri.

Sekarang, saya harus pendahuluan ini dengan mengatakan bahwa ada sekitar dua triliun cara merancang dan menerapkan sebuah mesin pencari, tapi ini adalah salah satu yang paling mudah, dan cepat.


  Oke, Jadi Kode kepalan kita dengan apa yang kita harus mulai tepat setelah <php ....


1.$var = @$_GET['q'] ; // get the query for <span id="IL_AD3" class="IL_AD">the search</span> engine (if applicable)
2.$trimmed = trim($var); //trim whitespace from the stored <span id="IL_AD7" class="IL_AD">variable</span>



Ini potongan kode PHP harus di atas <head> dokumen. Baris pertama mengambil "q" ("q" adalah singkatan dari query, jika anda ingin tahu) dari pencarian. Baris kedua stripspasi putih.

Berikutnya kita akan perlu untuk menghubungkan ke database ... 


01.$user = "username"; // AN EDIT IS REQUIRED HERE
02.$password = "password";
03.$host = "host";
04.$dbase = "dbase";
05.$table = "table";
06. 
07.// Connection to DBase
08.mysql_connect($host,$user,$pass);
09.@mysql_select_db($dbase) or die("Unable to select database");


Variabel di atas perlu diatur (jelas) terhadap apa pun yang berlaku untuk host Anda / database.

Oke, sekarang kita akan berbicara tentang struktur database sedikit. Pada dasarnya, apa yang saya lakukan adalah menambahkan field ke dBASE disebut "kata kunci".Kemudian, aku masuk nilai dipisahkan koma yang ingin saya kaitkan dengan surattertentu. Lihatlah kode: 
1.$field_to_search = "field";
2.$query = "SELECT * FROM $table WHERE $field_to_search LIKE "%$trimmed%" order by id";
3. 
4.$result = mysql_query($query);
5.$count =mysql_numrows($result);


Jadi, keempat baris melakukannya :

1) Setel field untuk mencari variabel yang disebut $field_to_search
2) Query database untuk istilah yang dicari
3) Kembali hasil
4) Hitung hasil (untuk tujuan estetika kemudian)

Sampai saat ini, semua kode PHP harus dalam atau di atas bagian <head>. Untuk menjadi 100% jujur​​, tidak terlalu penting jika itu atau tidak di bagian <head>, tapi saya ingin untuk tetap "backend" saya PHP di sana karena "keluar dari jalan" (sehingga untuk berbicara ).

Ini potongan kode pertama TIDAK PHP. Ini tidak harus diletakkan di <? > Tag?. 


1.<form name="search" method="GET" action="<?=$PHP_SELF?>">
2.Seach the database for: <input type="text" name="q" />
3.<input type="submit" name="search" value="Search" />
4.</form>


Potongan kode di atas adalah bentuk HTML untuk query database. Jika Anda ingin,Anda dapat mengatur potongan kode untuk menyembunyikan bentuk ketika seseorangtelah melakukan pencarian, karena hasilnya akan ditampilkan pada halaman yang sama.Anda bisa melakukannya dengan kode ini: 


01.if($q == true)
02.{
03.exit;
04.}
05.elseif($q == false)
06.{
07.<form name="search" method="GET" action="<?=$PHP_SELF?>">
08.Seach all the newsletters for
09.<input type="text" name="q" />
10.<input type="submit" name="search" value="Search" />
11.</form>
12.}


Oke, itu hanya catatan ... untuk menampilkan hasil!

Ini adalah banyak kode, tapi itu cukup jelas ... Cukup ikuti komentar dalam kode, dan Anda harus memiliki ide yang baik apa yang terjadi. 

01.if ($trimmed == "")
02.{
03.echo "<p>Please enter a search...</p>";
04.exit;
05.}
06. 
07.// check for a search parameter
08.if (!isset($var))
09.{
10.echo "<p>We dont seem to have a search parameter!</p>";
11.exit;
12.}
13. 
14.$numresults=mysql_query($query);
15.$numrows=mysql_num_rows($numresults);
16. 
17.if ($numrows == 0)
18.{
19.echo "<h4>Results</h4>";
20.echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>";
21.}
22. 
23.// next determine if s has been passed to script, if not use 0
24.if (empty($s))
25.{
26.$s=0;
27.}
28. 
29.// get results
30.$result = mysql_query($query) or die("Couldn't execute query");
31. 
32.if($numrows > 1){ $return = "results";}
33.else{ $return = "result"; }
34. 
35.// display what the person searched for
36.echo "<p>Your search for "" . $var . "&quot returned $numrows $return.</p>";
37. 
38.// begin to show results set
39.$count = 1 + $s ;<div><input type="hidden" name="IL_TAG_CLOUD" id="IL_TAG_CLOUD1"><div class="IL_BASE IL_TC" style="margin-top: 7px; margin-right: 15px; margin-bottom: 7px; margin-left: 15px; clear: both; width: 915px; "><div style="height:24px; border:1px solid #636363; background-color:#f4f4f4; border-radius:8px 8px 0 0; -webkit-border-radius:8px 8px 0 0; -moz-border-radius-topleft:8px; -moz-border-radius-topright:8px; margin: 0px;" class="IL_BASE">                                 <a style="border:0px none; font-family:Arial,sans-serif; font-size:13; font-weight:normal; color:#666666; float:right; height:19px; margin-right:7px; padding:4px 64px 1px 0; background:url(http://resources.infolinks.com/static/logo20-blue_2.png) no-repeat scroll right center transparent;" href="http://www.infolinks.com/" class="IL_BASE"></a>                                <div style="padding-left:7px; padding-top:5px; font-family:Arial,sans-serif; font-size:13; font-weight:normal; color:#666666; margin: 0px" class="IL_BASE">Tag Cloud</div>                        </div>                        <!-- body -->                        <div style="height:60px;border:1px solid #636363; border-top:0px; text-align:center; background-color:#FFFFFF; border-radius:0 0 8px 8px; -webkit-border-radius:0 0 8px 8px; -moz-border-radius-bottomleft:8px; -moz-border-radius-bottomright:8px; overflow: hidden; margin:0px;" class="IL_BASE">                        <ul id="IL_TAG_CLOUD_LIST0" class="IL_BASE" style="text-align: center !important; margin: 0px !important; padding: 0px !important; list-style: none outside none !important;"><li class="IL_BASE" style="display: inline-block; "><span id="IL_TAG_CLOUD_AD2" class="IL_BASE IL_TAG_CLOUD_AD" style="cursor: pointer; white-space: nowrap; float: none; line-height: 30px; vertical-align: top; font-size: 23px; color: rgb(0, 0, 153); ">Free work from home</span></li>
40.<li class="IL_BASE" style="display: inline-block; "><span id="IL_TAG_CLOUD_AD9" class="IL_BASE IL_TAG_CLOUD_AD" style="cursor: pointer; white-space: nowrap; float: none; line-height: 30px; vertical-align: top; font-size: 16px; color: rgb(0, 157, 12); ">Tax Bracket</span></li>
41.<li class="IL_BASE" style="display: inline-block; "><span id="IL_TAG_CLOUD_AD4" class="IL_BASE IL_TAG_CLOUD_AD" style="cursor: pointer; white-space: nowrap; float: none; line-height: 30px; vertical-align: top; font-size: 21px; color: rgb(0, 0, 153); ">Internet Services</span></li>
42.<li class="IL_BASE" style="display: inline-block; "><span id="IL_TAG_CLOUD_AD3" class="IL_BASE IL_TAG_CLOUD_AD" style="cursor: pointer; white-space: nowrap; float: none; line-height: 30px; vertical-align: top; font-size: 22px; color: rgb(0, 157, 12); ">Create a website</span></li>
43.<li class="IL_BASE" style="display: inline-block; "><span id="IL_TAG_CLOUD_AD5" class="IL_BASE IL_TAG_CLOUD_AD" style="cursor: pointer; white-space: nowrap; float: none; line-height: 30px; vertical-align: top; font-size: 20px; color: rgb(0, 0, 153); ">Online writing course</span></li>
44.<li class="IL_BASE" style="display: inline-block; "><span id="IL_TAG_CLOUD_AD6" class="IL_BASE IL_TAG_CLOUD_AD" style="cursor: pointer; white-space: nowrap; float: none; line-height: 30px; vertical-align: top; font-size: 19px; color: rgb(0, 157, 12); ">Website design tutorial</span></li>
45.<li class="IL_BASE" style="display: inline-block; "><span id="IL_TAG_CLOUD_AD7" class="IL_BASE IL_TAG_CLOUD_AD" style="cursor: pointer; white-space: nowrap; float: none; line-height: 30px; vertical-align: top; font-size: 18px; color: rgb(0, 0, 153); ">Personalized Gift</span></li>
46.<li class="IL_BASE" style="display: inline-block; "><span id="IL_TAG_CLOUD_AD8" class="IL_BASE IL_TAG_CLOUD_AD" style="cursor: pointer; white-space: nowrap; float: none; line-height: 30px; vertical-align: top; font-size: 17px; color: rgb(0, 157, 12); ">Legitimate work at home</span></li>
47.<li class="IL_BASE" style="display: inline-block; "><span id="IL_TAG_CLOUD_AD1" class="IL_BASE IL_TAG_CLOUD_AD" style="cursor: pointer; white-space: nowrap; float: none; line-height: 30px; vertical-align: top; font-size: 24px; color: rgb(0, 0, 153); ">Free work at home</span></li></ul>                         </div></div></div>



Oke, saya telah memilih untuk mengganggu kode di sini untuk menjelaskan while loop ()berikut. Jika Anda telah bekerja dengan PHP / mySQL untuk setiap jangka waktu singkat, Anda mungkin membuat sebuah lingkaran seperti ini, tapi saya akan berasumsi bahwa Anda belum.

Apa yang akan Anda inginkan, sehingga untuk mengatur variabel, kemudian menempatkan tanda =, maka $ r [""];. dalam tanda kutip ("), Anda akan menambahkannama field yang ingin Anda kaitkan dengan variabel tersebut. saya akan menunjukkanbeberapa contoh, tapi tolong sekarang bahwa Anda akan perlu mengubah ini agar sesuai database Anda. 


01.while ($r= mysql_fetch_array($result))
02.{
03.$id = $r["id"];
04.$year = $r["year"];
05.$date = $r["date"];
06.$title = $r["title"];
07.$description = $r["description"];
08. 
09.$count++ ;
10.?>



Jadi sekarang Anda memiliki while () loop Anda mengatur. Baris terakhir ada $count + +;. Biasanya, Anda akan mengakhiri loop sementara dengan tanda kurung tutup (}), tetapi kita akan "keluar" dari sementara () loop sini untuk memformat hasil kami. Dengan melanggar keluar dari while loop untuk memasukkan beberapa baik ol 'HTML, Andaakan menghasilkan HTML setiap kali sementara loop melewati, jadi, dengan kata lain, untuk setiap hasil pencarian Anda! Cukup pintar, ya?

Menggunakan database contoh di atas, saya akan menunjukkan apa yang bisa dilakukan ... Perlu diingat, ini perlu LUAR <itu? > Tag? ... lebih tepatnya, di antara mereka. 


1.<a href="http://www.YOURDOMAIN.com/archive/<;? echo $year ?>/<? echo $id ?>.html"><? echo $title ?></a>
2. 
3.<? echo $description ?>
4.Result Number: <? echo $count ?>

Oke, jadi jika pencarian Anda kembali 12 hasil, semua html Anda akan ditulis untuk Anda dengan link, judul, deskripsi, dan membiarkan Anda tahu mana jumlah hasil yang Anda lihat!

Sekarang, bagian yang sangat penting dari kode: 


1.<? } ?>


Anda harus menutup loop sementara Anda! Banyak jam frustasi banyak saya telahdihabiskan debugging kode sumber karena saya lupa delapan karakter kecil!
Baca Selengkapnya»»

Rabu, 14 Maret 2012

Aziatix - Be With You






Code :
Baca Selengkapnya»»

Senin, 12 Maret 2012

Maher Zain - Awaken





Lirik Lagu Maher Zain - Awaken

We were given so many prizes 
We changed the desert into oasis 
We built buildings of different lengths and sizes 
And we felt so very satisfied 
We bought and bought 
We couldn't stop buying 
We gave charity to the poor 'cause 
We couldn't stand their crying 
We thought we paid our dues 
But in fact 
To ourselves we're just lying 

Oh...I'm walking with my head lowered in shame from my place 
I'm walking with my head lowered from my race 
Yes it's easy to blame everything on the west 
When in fact all focus should be on ourselves 

We were told what to buy and we'd bought 
We went to London, Paris and Costa Del Sol 
We made show we were seen in the most exlusive shops 
Yes we felt so very satisfied 

We felt our money gave us infinite power 

We forgot to teach our children about history and honor 
We didn't have any time to lose 
When we were.. (were) 
So busy feeling so satisfied 

I'm walking with my head lowered in shame from my place 
I'm walking with my head lowered from my race 
Yes it's easy to blame everything on the west 
When in fact all focus should be on ourselves 

We became the visuals without a soul 
despite the heat 
Our homes felt so empty and cold 
To fill the emptiness 
We bought and bought 
Maybe all the fancy cars 
And bling will make us feel satisfied 

My dear brother and sister 
It's time to change inside 
Open your eyes 
Don't throw away what's right aside 
Before the day comes 
When there's nowhere to run and hide 
Now ask yourself 'cause Allah's watching you 

Is He satisfied? 
Is Allah satisfied? 
Is Allah satisfied? 
Is Allah satisfied? 

Oh..I'm walking with my head lowered in shame from my place 
I'm walking with my head lowered from my race 
Yes it's easy to blame everything on the west 
When in fact all focus should be on ourselves

Baca Selengkapnya»»

Bruno Mars - Marry You








Code :



Lirik Lagu Bruno Mars - Marry You


It's a beautiful night,
We're looking for something dumb to do.
Hey baby,
I think I wanna marry you.

Is it the look in your eyes,
Or is it this dancing juice?
Who cares baby,
I think I wanna marry you.

Well I know this little chapel on the boulevard we can go,
No one will know,
Come on girl.
Who cares if we're trashed got a pocket full of cash we can blow,
Shots of patron,
And it's on girl.

Don't say no, no, no, no-no;
Just say yeah, yeah, yeah, yeah-yeah;
And we'll go, go, go, go-go.
If you're ready, like I'm ready.

Cause it's a beautiful night,
We're looking for something dumb to do.
Hey baby,
I think I wanna marry you.

Is it the look in your eyes,
Or is it this dancing juice?
Who cares baby,
I think I wanna marry you.

I'll go get a ring let the choir bells sing like oooh,
So whatcha wanna do?
Let's just run girl.

If we wake up and you wanna break up that's cool.
No, I won't blame you;
It was fun girl.

Don't say no, no, no, no-no;
Just say yeah, yeah, yeah, yeah-yeah;
And we'll go, go, go, go-go.
If you're ready, like I'm ready.

Cause it's a beautiful night,
We're looking for something dumb to do.
Hey baby,
I think I wanna marry you.

Is it the look in your eyes,
Or is it this dancing juice?
Who cares baby,
I think I wanna marry you.

Just say I do,
Tell me right now baby,
Tell me right now baby. [x2]

Cause it's a beautiful night,
We're looking for something dumb to do.
Hey baby,
I think I wanna marry you.

Is it the look in your eyes,
Or is it this dancing juice?
Who cares baby,
I think I wanna marry you.




Baca Selengkapnya»»

Sabtu, 10 Maret 2012

Base Jam - Bermimpi






Code :
Baca Selengkapnya»»