Web Hosting Talk







View Full Version : Need Some Help by a PHP Expert


sasjamal
10-30-2002, 05:23 AM
function blogs($period="current")
{
if ($period=="current")
{
global $bloghistory;
if ($_GET["history"])
{
$bloghistory=$_GET["history"]<=5 ? $_GET["history"] : 5;
}
// because MySQL does not support sub selects...
mysql_query("create temporary table datetemp (dates varchar(25) NOT NULL) type=myisam") or die(mysql_error());
mysql_query("insert into datetemp (dates) select distinct date_format(dateentered,'%Y-%m-%d') as entrydate from blog_entries where active=1 and pinned=0 order by entrydate desc limit $bloghistory") or die(mysql_error());
$query="select be.blogid,be.preview,be.entry,be.dateentered,be.title,be.pageviews,be.usepreview,ba.name,be.pinned from blog_entries be,datetemp inner join blog_authors ba on be.authorid=ba.authorid where date_format(be.dateentered,'%Y-%m-%d')=datetemp.dates and be.active=1 and be.pinned=0 order by be.dateentered desc";
}
elseif ($period=="category")
{
global $catid;
$query="select be.blogid,be.preview,be.entry,be.dateentered,be.title,be.pageviews,be.usepreview,ba.name,be.pinned from blog_entries be inner join blog_authors ba on be.authorid=ba.authorid where catid=$catid and be.active=1 order by be.dateentered desc";
}
else
{
$query="select be.blogid,be.preview,be.entry,be.dateentered,be.title,be.pageviews,be.usepreview,ba.name,be.pinned from blog_entries be inner join blog_authors ba on be.authorid=ba.authorid where date_format(be.dateentered,'%Y-%m')='$period' and be.active=1 order by be.dateentered desc";
}
showblogs($query);
}

sasjamal
10-30-2002, 05:25 AM
Now, basicaly I have a program i can add more releveant code if necessary, this program lets me depending on the 5 values that are sent to it show the blog entries for up to 5 days, 4, days, 3 days, 2 days, or just one day (which is default)

I want to adjust this so that it shows the last 10 enties, last 20 entries, last 30 entries or last 40 entries, instead of show them on a daily basis.

So can anyone suggest whay I have to change for this script to work?

thanks

Rich2k
10-30-2002, 05:40 AM
In the SQL query simply use

LIMIT 0,10
LIMIT 0,20
LIMIT 0,30
LIMIT 0,40

sasjamal
10-30-2002, 06:53 AM
what exactly would i change in the php code?

depedning on the var it changed

ie. index.php?history=1
index.php?history=2

so where on the code would i modify?

thanks