View Full Version : Limiting the results in index page but display all in another page....

07-17-2010, 03:40 AM
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.

function displayEvents($row)
$day = substr($row['date'], 8, 2);
$day = $day - 0;
$month = substr($row['date'], 5, 2);
$year = substr($row['date'], 0, 4);
$dayw = date("D", mktime(0, 0, 0, $month, $day, $year));
$monthName = date("M", mktime(0, 0, 0, $month, $day, $year));
$hour = realHour($row['time']);
$minute = substr($row['time'], 3, 2);
$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>


echo "<div class='post_content'>
<h1><a >{$row['name']} </a></h1>
<a href='index.htm#'>Read more ...</a><br>

<a href='http://maps.google.com/maps?q={$row['address']} '>Ver mapa mas grande.</a>

echo " <div class='post_info'>
<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>

<img src='http://www.luiyiruiz.com/site/images/post_sep.gif' width='960' height='2' alt='post sep' />

echo "</div>";


07-18-2010, 07:09 PM
If you are pulling this info from a DB then in the query string use the LIMIT at the end of the string.

myql_query("SELECT * FROM $tbl_name LIMIT 3");

07-19-2010, 01:25 AM
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????

07-19-2010, 01:32 AM
Use a limit if you are on the main page and not on the other. Just use "if/else" for this.

07-19-2010, 04:59 PM
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...

07-19-2010, 05:51 PM
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.

$page = basename($_SERVER['PHP_SELF'], ".php");
Then use the $page in an if/else statement

07-19-2010, 06:09 PM
fastsol1 just beat me to it but here's the code I use in my common header file to target the index page only.

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

07-19-2010, 06:35 PM
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).

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

07-19-2010, 08:53 PM
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?

07-19-2010, 10:06 PM
$array = get_included_files();

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.

07-19-2010, 10:13 PM
The only problem is that im including it into an html file using SSI, which means i can not use php there...

07-19-2010, 10:20 PM
Is there a reason you can't use PHP instead of SSI?

I don't really have a suggestion that will work without testing a few things. Try looking at get_included_files() and $_SERVER to find some bit of info that tells you which page you're on.

Can SSI use get variables? mypage.php?short
Then if (isset($_GET['short'])) ......