SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Sep 2009
    0 Post(s)
    0 Thread(s)

    nooooobie needs help

    I have been working on a website using PHP and MySQL and although I have knowledge in both these fields, my knowledge is quite limited and I have come across a problem I need help with.
    I am creating a videos page and I would like the videos to be displayed (using PHP) in a format similar to what is found here:

    I would like the videos to display the date headline (the date being when the videos were posted) then the thumbnails of the videos to be displayed in 4 columns. I already have the videos page set up with the pagination, mysql connection and video details. I am currently displaying the videos in a single column as I dont know how to display PHP results in multiple columns.

    So basically I am looking for the videos page to display the results like this (example):

    Thursday, August 27, 2009
    Video 1 | Video 2 | Video 3 | Video 4
    Video 5 | Video 6 | Video 7 | Video 8

    here is the search script. many thanks

    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)) {
    // 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.
    //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;
    // now you can display the results returned. But first we will display the search form on the top of the page

    // display what the person searched for.
    if( isset ($resultmsg)){
    echo $resultmsg;
    echo "
    <div align=center>
    <table border=0 cellpadding=0 cellspacing=0 width=943>
    <td><p><font size=4>Search results for : $var</td>
    </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 ?>">

    } //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'

    // 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

    } //end foreach $newarr

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Philadephia, PA
    1 Post(s)
    0 Thread(s)
    Wrap each video (and any details you're displaying above/below each video) in a div. Give those divs a fixed width and float them. If the width of each div is approximately 1/4 the width of the piece of the page they all sit in, they'll automatically wrap to 4 columns.

    You could do it with tables just as easily (hint: ($a_counter &#37; 4 == 0) when it's time to start a new row), but modern web designers will yell at you for it.


Posting Permissions

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