Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Dec 2009
    Posts
    240
    Thanks
    7
    Thanked 0 Times in 0 Posts

    How Do I Just Get The Newest Products To Be Shown?

    Alrights guys

    I am in the process of creating a new php page called newest. I would like it to work like this

    It will automatically read the newest category that I have added to the database and the display the products under it..

    This is the markerplace code at the moment

    PHP Code:
    <?php
    include_once ("header.php");
    $cat $_GET["cat"];
    $link $_GET["category"];
    $search $_GET["search"];
    $cat_title str_replace("_"," ",$link);

    if(
    $cat != "t")
        {
        
    $GetFile file("http://www.digitalresellersvault.com/template/template.php");
        
    $Content join(""$GetFile);
        
    $categories=$common->categories($db);
        
    $content=str_replace("{categories}",$categories,$content);    
        
    $Pat "/<{Begin}>(.*?)<{End}>/s";
        
    preg_match($Pat,$Content,$Output);
        
    $SelectedContent $Output[1];
        
    $q "select *,DATE_FORMAT(product_date, '%m-%d-%Y') as date from
        "
    .$prefix."products where show_product = '1' ORDER BY Rand() LIMIT 1";
        
        
    $r $db->get_a_line($q);
        
    $id $r[id];
        
    $imageurl $r[imageurl];
        
    $prod_description $r[prod_description];
        
    $salesprice $r[price];
        
    $product_name $r[product_name];
        
    $salespage_link='<a href="prods.php?pid='.$id.'">Click Here For More Information</a>';
        
    $product_name='<a href="prods.php?pid='.$id.'">'.$product_name.'</a>';            
        
    $prod_image='<a href="prods.php?pid='.$id.'"><img src="images/'.$imageurl.'"></a>';        
        
    $Content preg_replace($Pat,$ToReplace,$Content);
        
    $Content preg_replace("/{{(.*?)}}/e""$$1"$Content);
        echo 
    $Content;
        include_once (
    "footer.php");        
        exit();        
        }


    elseif(
    $cat == "t")
        {
        
    $search $_GET["search"];
        
    $link $_GET["category"];
        
    $cat_title str_replace("_"," ",$link);
        
    $GetFile file("http://www.digitalresellersvault.com/template/template.php");
        
    $Content join(""$GetFile);
        
    $categories=$common->categories($db);
        
    $content=str_replace("{categories}",$categories,$content);    
        
    $theselect=$common->category_select($db'select');
        
    $Content str_replace("{{category_select}}"$theselect$Content);
        
    $Pat "/<{Begin}>(.*?)<{End}>/s";
        
    preg_match($Pat,$Content,$Output);
        
    $SelectedContent $Output[1];
        
        if(
    $search_txt != "")
            {
            
    $cond    "where product_name like '%".$search_txt."%' && show_product = '1'";        
            }
        else
            {
            
    $cond    "where category = '$cat_title' && show_product = '1'";
            }

        
    ########## pagination ###########
        
    $q "select count(*) as cnt from ".$prefix."products $cond";
        
    $r $db->get_a_line($q);
        
    $count $r[cnt];
        if(
    $count == "0")
            {
            
    $warning "No Results Found";
            }
        
    $records=10;
        
    $links="marketplace.php?cat=t&category=$category&search_txt=$search_txt&";
        if(
    $page=="")
            {
            
    $page=1;
            }
        
    $start=($page-1)*$records;
        
    $Content=$common->print_page_break3($db,$Content,$count,$records,$links,$page);
        
    ########## pagination ###########

        
    $ChangeColor 1;
        
    $ToReplace "";
        
    $GetProduct $db->get_rsltset("select *,(SELECT
    DATE_FORMAT(product_date, '%b/%d/%Y')) as formatteddate from
    "
    .$prefix."products $cond order by product_date DESC limit $start, $records");
        for(
    $i 0$i count($GetProduct); $i++)
            {
            
    $bgcolor "#FFFFFF";
            @
    extract($GetProduct[$i]);
            if(
    $period3_interval == "D"){$interval "Day(s)";}
            if(
    $period3_interval == "W"){$interval "Week(s)";}
            if(
    $period3_interval == "M"){$interval "Month(s)";}
            if(
    $period3_interval == "Y"){$interval "Year(s)";}
            
            
            
    $product_name='<a href="prods.php?pid='.$id.'">'.$product_name.'</a>';
            

            if(
    $subscription_active == "1")
                {
                
    $salesprice $amount3." every ".$period3_value." ".$interval;
                }
            else
                {
                
    $salesprice $price;
                }    
            
    $prod_image='<a href="prods.php?pid='.$id.'"><img src="images/'.$imageurl.'"></a>';    
            
    $download_link='<a href="http://www.digitalresellersvault.com/go/downloads/'.$download_link.'"><img border="0" src="http://www.digitalresellersvault.com/template/images/downloadbutton.jpg" width="104" height="16"></a>';

            
    $salespage_link='<a href="prods.php?pid='.$id.'"><img border="0" src="http://www.digitalresellersvault.com/template/images/moreinfobutton.jpg" width="104" height="16"></a>';
            
    $ToReplace .= preg_replace($Ptn,"$$1",$SelectedContent);
            }
        }    
            
    $Content preg_replace($Pat,$ToReplace,$Content);
    $Content preg_replace("/{{(.*?)}}/e""$$1"$Content);
    echo 
    $Content;
    include_once (
    "footer.php");
    ?>
    Last edited by Inigoesdr; 02-21-2010 at 05:31 PM.

  • #2
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    It will automatically read the newest category that I have added to the database and the display the products under it..





    sample db, status 1 = newest category
    Code:
    category | status
    
    boxes | 1
    widgets | 2
    wood | 3



    PHP Code:
    ORDER BY 1 




    ----------
    Leonard Whistler

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Posts
    240
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Len Whistler View Post
    It will automatically read the newest category that I have added to the database and the display the products under it..





    sample db, status 1 = newest category
    Code:
    category | status
    
    boxes | 1
    widgets | 2
    wood | 3



    PHP Code:
    ORDER BY 1 




    ----------
    Len

    Sorry but you have totally lost me.. Are you saying that the code already shows the newest one already??

  • #4
    Regular Coder
    Join Date
    Dec 2008
    Posts
    133
    Thanks
    15
    Thanked 0 Times in 0 Posts
    i would use ORDER and LIMIT

    If it was me i would create a MySQL database and include a Timestamp for the products, then ORDER Timestamp and LIMIT to how many you want displayed in the SQL query.

  • #5
    Regular Coder
    Join Date
    Dec 2009
    Posts
    240
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by CallumJohnson View Post
    i would use ORDER and LIMIT

    If it was me i would create a MySQL database and include a Timestamp for the products, then ORDER Timestamp and LIMIT to how many you want displayed in the SQL query.
    I already got the order part in the code

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Either store the date added in the products table, or use an auto_increment primary key and sort by whichever you have.

  • #7
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Quote Originally Posted by Byronwells View Post
    Len

    Sorry but you have totally lost me.. Are you saying that the code already shows the newest one already??
    I made a major typo, should be:


    db columns
    Code:
    category | status
    
    boxes | 1
    widgets | 2
    wood | 3
    mysql query
    PHP Code:
    ORDER BY status 
    Boxes is the newest category with status set to 1



    --------------
    Leonard Whistler

  • #8
    Regular Coder
    Join Date
    Dec 2009
    Posts
    240
    Thanks
    7
    Thanked 0 Times in 0 Posts
    I think you have totally misunderstood me.. I would like the newest product link to automatically read and display the newest/latest category that I have added to the script..

  • #9
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Current query:
    PHP Code:
    $q "select *,DATE_FORMAT(product_date, '%m-%d-%Y') as date from
        "
    .$prefix."products where show_product = '1' ORDER BY Rand() LIMIT 1"
    I'm not sure why you have random output but if you want a certain category to output first you could try something like:

    Create a category_date column.
    PHP Code:
    $q "select *,DATE_FORMAT(product_date, '%m-%d-%Y') as date from
        "
    .$prefix."products where show_product = '1' ORDER BY category_date"
    OR

    Create a status column, you could then easily change the order that the product categories are displayed.
    PHP Code:
    $q "select *,DATE_FORMAT(product_date, '%m-%d-%Y') as date from
        "
    .$prefix."products where show_product = '1' ORDER BY status"
    There are many ways to display product categories in a certain order.


    --------
    Leonard Whistler


  •  

    Posting Permissions

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