google like search

PHP, HTML, Joomla, WordPress, etc..
Plaats reactie
ojee66

google like search

Ongelezen bericht door ojee66 »

Op verzoek van dwarrel, en Wout kan er ook misschien nog iets mee ;)

Het gaat om 2 php bestandjes


Searchdata.php

Code: Selecteer alles

<html> 
<head>  
<script language="JavaScript1.2"><? require("songinfo.js"); ?></script>
</head>
</html>
<?php
error_reporting (E_ALL ^ E_NOTICE);

$COM_CONF['full_path'] = dirname(__FILE__);

include("{$COM_CONF['full_path']}/samPHPweb/comment/config2.php");
if (! $COM_CONF['dbhost']) {
	echo 'It seems that comments script is not properly installed. See readme.txt for more info.';
}

$comments_db_link = mysql_connect($COM_CONF['dbhost'],$COM_CONF['dbuser'],$COM_CONF['dbpassword']);
mysql_select_db($COM_CONF['dbname'], $comments_db_link);


if(isset($_GET['search_word']))
{
$search_word=$_GET['search_word'];

$search_word_new=mysql_escape_string($search_word);
$search_word_fix=str_replace(" ","%",$search_word_new);
$sql=mysql_query("SELECT ID, artist, title, genre, albumyear, picture, duration FROM songlist WHERE artist LIKE '%$search_word_fix%' ORDER BY ID DESC LIMIT 20");
$count=mysql_num_rows($sql);
if($count > 0)
{
while($row=mysql_fetch_array($sql))
{

 $ss = round($row["duration"] / 1000);
 $mm = (int)($ss / 60);
 $ss = ($ss % 60);
 if($ss<10) $ss="0$ss";
 $song["mmss"] = "$mm:$ss";

	  
	  $remoteImageURL = 'http://radiosoundfm.nl/samPHPweb/pictures/'.$row['picture'];
if(@GetImageSize($remoteImageURL)){
    //image exists!
	
}else {
$artist1 = str_replace(" ", "_", $row['artist']);
$que = array( 'á','é','í','ó','ú','Á','É','Í','Ó','Ú','ñ','Ñ', );
$por = array( 'a','e','i','o','u','A','E','I','O','U','n','n', );
$artist1 = strtolower( str_replace( $que,$por,$artist1 ) );
$replace = array(',','<','>','|','/','\\','.',';',':','"','\'');
$artist1 = str_replace($replace,'',$artist1);

$row['picture'] = $artist1.'.jpeg';


$remoteImageURL = 'http://radiosoundfm.nl/samPHPweb/pictures/'.$row['picture'].'.jpeg';	
if(@GetImageSize($remoteImageURL)){
// exists !
		} else {
$row['picture'] = 'nopic.jpeg';		

	}
}


$msg = $row['artist'];
//$bold_word = '<b>'.$search_word.'</b>';
//$msg = str_ireplace($search_word, $bold_word, $msg);

$table1 = "<table border='0' width='98%' cellspacing='1' cellpadding='2'>";
$table1 = $table1."<tr bgcolor='#002E5B'> ";
$table1 = $table1."<td colspan='6'>"; 
$table1 = $table1."<p align='center'><font size='2'><b><font color='#FFFFFF' size='1' face='Verdana, Arial, Helvetica, sans-serif'>Song Information</font></b></font>";
$table1 = $table1."</td>";
$table1 = $table1."</tr>";
$table1 = $table1."<tr>"; 
$table1 = $table1."<td colspan='6'><img src='samPHPweb/images/spacer.gif' width='15' height='13'></td>";
$table1 = $table1."</tr>";
$table1 = $table1."<tr>"; 
$table1 = $table1."<td bgcolor='EAEAEA' align='right' width='15%'><font color='#333333' size='2'>Artist<img src='samPHPweb/images/spacer.gif' width='15' height='13'></font></td>";
$table1 = $table1."<td bgcolor='eaeaea' ><b><font color='#003366' size='2'>" . $msg . " </font></b></td>";
$table1 = $table1."<td bgcolor='EAEAEA'>"; 
$table1 = $table1."</td>";
$table1 = $table1."<td bgcolor='EAEAEA'>"; 
$table1 = $table1."</td>";
$table1 = $table1."<td bgcolor='EAEAEA'>"; 
$table1 = $table1."<p align='center'><font color='#333333' size='2'>Picture</font>";
$table1 = $table1."</td>";
$table1 = $table1."</tr>";
$table1 = $table1."<tr>";
$table1 = $table1."<td bgcolor='#FFFFFF' align='right' ><font color='#333333' size='2'>Title<img src='samPHPweb/images/spacer.gif' width='15' height='13'></font></td>";
$table1 = $table1."<td bgcolor='#FFFFFF'><b><font color='#003366' size='2' >" . $row['title'] . "</font></b></td>";
$table1 = $table1."<td bgcolor='#FFFFFF' align='right'><font color='#333333' size='2' width='15'>Time<img src='samPHPweb/images/spacer.gif' width='15' height='13' /></font></td>";
$table1 = $table1."<td bgcolor='#FFFFFF'><b><font color='#003366' size='2' width='15'>" . $song["mmss"] . "</font></b></td>";




$table1 = $table1."<td bgcolor='#FFFFFF' rowspan='3' valign='middle' width='1%'>";
if ($row['info']=='') {
$table1 = $table1.'<img align="left" width="60" height="60" scr="samPHPweb/pictures/nopic.jpeg" border="0">'; }
else
$table1 = $table1.'<a href=' .$row['info']. ' target="_blank" ><img align="left" width="60" height="60" scr="samPHPweb/pictures/nopic.jpeg" alt="Artist homepage" border="0" ></a>';

$table1 = $table1."</td>";
$table1 = $table1."</tr>";
$table1 = $table1."<tr>";
 
$table1 = $table1."<td bgcolor='EAEAEA' align='right' width='15%'><font color='#333333' size='2'>Genre<img src='samPHPweb/images/spacer.gif' width='15' height='13'></font></td>";
$table1 = $table1."<td bgcolor='eaeaea'><b><font color='#003366' size='2'>" . $row['genre'] . " </font></b></td>";

$table1 = $table1."</td>";
$table1 = $table1."<td bgcolor='#EAEAEA' rowspan='2' colspan='2' valign='middle' width='1%'>";
$table1 = $table1.'<a href="samPHPweb/req2.php?songid='. $row['ID'] . '" align="middle">REQUEST</a>';
$table1 = $table1."</td>";
$table1 = $table1."<td bgcolor='EAEAEA'>"; 
$table1 = $table1."</td>";
$table1 = $table1."</tr>";
$table1 = $table1."<tr>"; 
$table1 = $table1."<td bgcolor='#FFFFFF' align='right' width='15%'><font color='#333333' size='2'>Year<img src='samPHPweb/images/spacer.gif' width='15' height='13'></font></td>";
$table1 = $table1."<td bgcolor='#FFFFFF'><b><font color='#003366' size='2'>" . $row['albumyear'] . "</font></b></td>";
$table1 = $table1."<td bgcolor='#FFFFFF'></td>";
$table1 = $table1."</tr>";
$table1 = $table1."<tr>";

$table1 = $table1."</tr>";

$table1 = $table1."</table>";

$final_msg = $table1;

?>

<li><?php echo $final_msg; ?></li>

<?php
}
}
else
{
echo "<li>No Results</li>";
}
}
?>

en de eigenijke zoekpagina

newsearch.php

Code: Selecteer alles


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 

<style type="text/css"> 
body{
font-family:Arial, Helvetica, sans-serif;
 
}
*{margin:0;padding:0;}
a
{
color:#DF3D82;
text-decoration:none
 
}
a:hover
{
color:#DF3D82;
text-decoration:underline;
 
}
b
{
 
 
}
	ol.update
	{list-style:none;font-size:1.1em; margin-top:20px }
	ol.update li{ height:140px; border-bottom:#dedede dashed 1px; text-align:left;}
	ol.update li:first-child{ border-top:#dedede dashed 1px; height:140px; text-align:left}
	#flash
	{
	margin-top:20px;
	text-align:left;
	
	}
	#searchword
	{
	text-align:left; margin-top:20px; display:none;
	font-family:Arial, Helvetica, sans-serif;
	font-size:16px;
	color:#000;
	}
	.searchword
	{
	font-weight:bold;
	color:#000000;
	
	}
	#search_box
	{
	padding:4px; border:solid 1px #666666; width:550px; height:30px; font-size:18px;-moz-border-radius: 6px;-webkit-border-radius: 6px;
	}
	.search_button
	{
	background:url(); border:#000000 solid 1px; padding-left:9px;padding-right:9px;padding-top:9px;padding-bottom:9px; color:#000; font-weight:bold; font-size:16px;-moz-border-radius: 6px;-webkit-border-radius: 6px;
	}
</style> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script> 



<script type="text/javascript">
$(document).ready(function() {
var search_now = function() {

var time_out = 0;

return function(callback, time) {

clearTimeout(time_out);

time_out = setTimeout(callback, time);

}

}();


 
$("#search_box").keyup(function() {

	if("#search_box" < 3)
	{
	}

    var search_word = $("#search_box").val();
    var dataString = 'search_word='+ search_word;



	if((search_word < 3)||(search_word==''))
	{
	}
	else
	{
	$.ajax({
	type: "GET",
    url: "searchdata.php",
    data: dataString,
    cache: false,
    beforeSend: function(html) {
   
	document.getElementById("insert_search").innerHTML = ''; 
	$("#flash").show();
	$("#searchword").show();
	$(".searchword").html(search_word);
	$("#flash").html('<img src="images/ajax-loader.gif" align="absmiddle">&nbsp;Loading Results...');
	               
            },
    success: function(html){
   $("#insert_search").show();
   $("#insert_search").append(html);
   $("#flash").hide();
  }
});
		
	}
		
 
    return false;
	});
 
 
 
});
</script> 


</head> 
 
<body> 


<div align="center"> 
<div style="width:700px"> 
<div style="margin-top:20px; text-align:left"> 
<form method="get" action=""> 
			  <input type="text" name="search" id="search_box" class='search_box'/> 
			  <input type="submit" value="Clear Search" class="search_button" /><br /> 
			  <span style="color:#666666; font-size:14px; font-family:Arial, Helvetica, sans-serif;"><b>Eg :</b> madonna, solvaig, laszlo, brothers</span> 
			  
			  
			  </form> 
		</div>	  
			  <div> 
			  <div id="searchword">Search results for <span class="searchword"></span></div> 
			  <div id="flash"></div> 
			  <ol id="insert_search" class="update"> 
			  </ol> 
			  
			  </div> 
			  </div> 
			  </div> 

</body> 
</html> 

in de config2.php van searchdata.php staat hoe de verbinding wordt opgebouwd met de sql server soortgelijk als

<?
$COM_CONF['site_url'] = "http://www.jouw domeinnaam .nl"; // Without trailing slash

$COM_CONF['dbhost'] = "localhost";
$COM_CONF['dbuser']="username";
$COM_CONF['dbpassword']="password";
$COM_CONF['dbname']="databasename";
?>
drOhimself

Re: google like search

Ongelezen bericht door drOhimself »

Ziet er echt super uit Ojee66, ik ga me toch ook maar eens wat meer in php verdiepen !
Dwarrel

Re: google like search

Ongelezen bericht door Dwarrel »

Heb 1 vraagje:

De php draait nu met een localhost, en ik heb mijn host ergens anders met port 3306. Verschillende dingen heb ik al geprobeerd maar blijf een eroor krijgen met connecten, Hoe en waar moet ik dit ingeven....???

Dwarrel....
ojee66

Re: google like search

Ongelezen bericht door ojee66 »

je kan dezelfde gegevens voor connecten gebruiken als bij je sam connectie (wat er in dbconfig.xml.php staat)

zie dat je ms sql gebruikt, weet niet of die op dezelfde manier connectie maakt.
Plaats reactie