Results 1 to 1 of 1

Thread: nooobie needs help

  1. #1
    Join Date
    Sep 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default nooobie needs help

    hi im putting together a video script an have just added a search script.
    The search script displays the text and images vertically,iwant to display them
    horizontally with four images in a row , like u tube.
    can any one help?

    here is the search script. many thanks

    Code:
    <?php 
    include './connections/c_database.php';
    //This is a working script
    //Make sure to go through it and edit database table filelds that you are seraching
    //This script assumes you are searching 3 fields
    
    $connections = mysql_connect($host, $user, $pass) or die ( "Unabale to connect to the database" );
    //select database
    mysql_select_db($db) or die ( "Unable to select database!" );
    
    //specify how many results to display per page
    $limit = 50;
    
    // Get the search variable from URL
    $var = @$_GET['q'] ;
    //trim whitespace from the stored variable
    $trimmed = trim($var); 
    //separate key-phrases into keywords
    $trimmed_array = explode(" ",$trimmed); 
    // check for an empty string and display a message.
    if ($trimmed == "") {
    $resultmsg = "<p>Search Error</p><p>Please enter a search...</p>" ;
    }
    // check for a search parameter
    if (!isset($var)){
    $resultmsg = "<p>Search Error</p><p>We don't seem to have a search parameter! </p>" ;
    }
    // Build SQL Query for each keyword entered 
    foreach ($trimmed_array as $trimm){
    
    // EDIT HERE and specify your table and field names for the SQL query
    $query = "SELECT * FROM data WHERE  id  LIKE \"%$trimm%\" OR thumb  LIKE \"%$trimm%\" OR titel LIKE \"%$trimm%\" OR code  LIKE \"%$trimm%\"ORDER BY  id  DESC" ; 
    // Execute the query to get number of rows that contain search kewords
    $numresults=mysql_query ($query);
    $row_num_links_main =mysql_num_rows ($numresults);
    // next determine if 's' has been passed to script, if not use 0.
    // 's' is a variable that gets set as we navigate the search result pages.
    if (empty($s)) {
    $s=0;
    }
    // now let's get results.
    $query .= " LIMIT $s,$limit" ;
    $numresults = mysql_query ($query) or die ( "Couldn't execute query" );
    $row= mysql_fetch_array ($numresults);
    
    //store record id of every item that contains the keyword in the array we need to do this to avoid display of duplicate search result.
    do{
    //EDIT HERE and specify your field name that is primary key
    $adid_array[] = $row[ 'id' ];
    }while( $row= mysql_fetch_array($numresults));
    } //end foreach
    
    if($row_num_links_main == 0 && $row_set_num == 0){
    $resultmsg = "" . $trimmed ."</p><p>Sorry, your search returned zero results</p>" ;
    }
    //delete duplicate record id's from the array. To do this we will use array_unique function
    $tmparr = array_unique($adid_array); 
    $i % 5 == 0; 
    foreach ($tmparr as $v) { 
    $newarr[$i] = $v; 
    $i++; 
    } 
    // now you can display the results returned. But first we will display the search form on the top of the page
    ?>
    
    
    <?php
    // display what the person searched for.
    if( isset ($resultmsg)){
    echo $resultmsg;
    exit();
    }else{
    echo "
    <div align=center>
    <center>
    <table border=0 cellpadding=0 cellspacing=0 width=943>
    <tbody>
    <tr>
    <td><p><font size=4>Search results for : $var</td>
    </tr>
    <tr>
    <td></td>
    </tr>
    <tr>
    <td></td>
    </tr>
    </tbody>
    </table>
    </center>
    </div> " ;
    }
    
    foreach($newarr as $value){
    
    // EDIT HERE and specify your table and field names for the SQL query
    $query_value = "SELECT * FROM data WHERE id = '$value'";
    $num_value=mysql_query ($query_value);
    $row_linkcat= mysql_fetch_array ($num_value);
    $row_num_links= mysql_num_rows ($num_value);
    
    //now let's make the keywords bold. To do that we will use preg_replace function. 
    //EDIT parts of the lines below that have fields names like $row_linkcat[ 'field1' ]
    //This script assumes you are searching only 3 fields. If you are searching more fileds make sure that add appropriate line. 
    $titlehigh = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'id' ] );
    $linkhigh = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'titel' ] );
    $linkthumb = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'thumb' ] );
    $datum = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'datum' ] );
    $code = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'code' ] );
    
    foreach($trimmed_array as $trimm){
    if($trimm != 'b' ){
    //IF you added more fields to search make sure to add them below as well.
    $titlehigh = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $titlehigh);
    $linkhigh = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $linkhigh);
    $linkdesc = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $datum); 
    $linkthumb = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $thumb); 
    $linkcode = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $code); 
    }
    //end highlight
    ?>
    
    
    
    <?php echo $datum; ?>
    <?php echo $linkhigh; ?><br>
    <?php echo $thumb; ?>
    
    <font color="#FF0000">
    
    
    			
    				<a href="index.php?video=<?= $code ?>"><img src="<?= $thumb ?>">
    			
    			
    
    
    
    
    <?php 
    } //end foreach $trimmed_array 
    if($row_num_links_main > $limit){
    // next we need to do the links to other search result pages
    if ($s>=0) { // do not display previous link if 's' is '0'
    $prevs=($s-$limit);
    
    }
    // check to see if last page
    $slimit =$s+$limit;
    if (!($slimit >= $row_num_links_main) && $row_num_links_main!=1) {
    // not last page so display next link
    $n=$s+$limit;
    
    }
    }
    } //end foreach $newarr
    ?>
    Last edited by djr33; 09-27-2009 at 06:11 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •