Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Limiting the results in index page but display all in another page....

  1. #1
    Join Date
    Apr 2007
    Posts
    149
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Limiting the results in index page but display all in another page....

    I have a function with get information (Events) from database and it displays then on the index page using the function below, however, i want to limit the number of events it displays in the front page but display them all in the events.php page... what is the easiest way to do this?? Any help would be appeciated. Thanks.

    PHP Code:
    function displayEvents($row)
    {
     
    $day substr($row['date'], 82);
    $day $day 0;
    $month substr($row['date'], 52);
    $year substr($row['date'], 04);
    $dayw =  date("D"mktime(000$month$day$year));
    $monthName date("M"mktime(000$month$day$year));
    $hour realHour($row['time']);
    $minute substr($row['time'], 32);
    $ampm realAMPM($row['time']);
    $showTime $row['showTime'];


    echo 
    "<div class='post no_border'>
                <div class='post_image'>
                    
                    
                    
                    <iframe width='170' height='104' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='http://maps.google.com/maps?q=
    {$row['address']},&amp;ie=UTF8&amp;hq=&amp;hnear={$row['address']}&amp;z=14&amp;iwloc=&amp;output=embed'></iframe>
                    
                </div>"
    ;
                
            echo 
    "<div class='post_content'>
                    <h1><a >
    {$row['name']} </a></h1>
                    <p>
    {$row['description']}</p>
                    <a href='index.htm#'>Read more ...</a><br>
                    
                    <a href='http://maps.google.com/maps?q=
    {$row['address']}   '>Ver mapa mas grande.</a> 
             </div>"
    ;
                
                echo 
    " <div class='post_info'>
                    <ul>
                        <li> <strong>Lugar:</strong> <br> 
    {$row['venue']} </li>
                        <li> <strong>Fecha:</strong> <br> 
    $dayw$monthName $day$year  </li>
                        <li><strong>Hora:</strong> <br> "
    ;
                        if (
    $showTime) {echo  "$hour:$minute $ampm";}
                echo 
    "</li>
                
            
                
                </ul>
                </div>
                   <img src='http://www.luiyiruiz.com/site/images/post_sep.gif' width='960' height='2' alt='post sep' />
                "
    ;
            
            echo 
    "</div>";





  2. #2
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    If you are pulling this info from a DB then in the query string use the LIMIT at the end of the string.
    PHP Code:
    myql_query("SELECT * FROM $tbl_name LIMIT 3"); 

  3. #3
    Join Date
    Apr 2007
    Posts
    149
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your response... i think is a great idea... but the problem is that this is being included in to the main page, so i would like to somehow identify whether the info is being displayed in the index page or events page, and if index page, then limit results to x number....

    How can i do this????

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Use a limit if you are on the main page and not on the other. Just use "if/else" for this.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Apr 2007
    Posts
    149
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    yeah, right, but what function can i use to find out whether i am in index.php or events.php??? Thanks, i appreciate your help...

  6. #6
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    Use this to get the base page name, I put this at the top of my page cause I use this to set the <body id=$page> for page specific css formatting if needed.
    PHP Code:
    $page basename($_SERVER['PHP_SELF'], ".php"); 
    Then use the $page in an if/else statement

  7. #7
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    fastsol1 just beat me to it but here's the code I use in my common header file to target the index page only.

    PHP Code:
    <?php
    // get page name and strip path and extention, regardless of what it is 
    $page_title basename(substr($_SERVER['PHP_SELF'], 0,strrpos($_SERVER['PHP_SELF'],'.'))); 
    if (
    $page_title == 'index') { 
        
    // do or show something on index page
        
    echo "This is the index page";
    } else { 
        
    // do or show something on all other pages
        
    echo "This is any page other than the index page";
    }; 
    ?>
    Last edited by Beverleyh; 07-19-2010 at 06:36 PM.

  8. #8
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    BTW - you can remove the other fluff from my example and just use fastsol1's shorter basename($_SERVER['PHP_SELF'], ".php"); string but I just left my version in as it also accounts for pages with file extensions other than .php.

    For example, you might have the follow 2 lines of code in an .htaccess file which allow .html and .htm pages to process php scripts and then my slightly longer-winded code would work on and strip the file extension from those too (without needing to specify it).

    Code:
    AddType application/x-httpd-php .html
    AddType application/x-httpd-php .htm

  9. #9
    Join Date
    Apr 2007
    Posts
    149
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Here's whats going on:
    I have a index.html page which is including a index.php in a folder called events (including: events/index.php)

    Im adding the code you guys provided in to the index.php but when the server processes, it seem the $page_title = basename(substr($_SERVER['PHP_SELF'], 0,strrpos($_SERVER['PHP_SELF'],'.'))); part is being done to the index.php page, therefore even if im at the index.html or events.html, it still seems to read as if it is in index.php

    Is there a way around this?

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    $array = get_included_files();
    print_r($array);


    Then look to find which is the relevant file. It may take some testing to really figure this out.

    Note that if(in_array(...)) and if($array[#]=='mypath') are both methods you could use.

    Also, how do you determine which page to include? Can you not use the same logic there? For example, if it's a cookie, then just check if that cookie exists again... or whatever other method you could be using.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •