Result Sets
- From: ajtdds@xxxxxxx
- Date: Tue, 30 Dec 2008 09:56:59 -0800 (PST)
Please bear with me on this one everyone, as it is not often I use
php.
Am trying to put together a news page. First of all I get the last 10
news articles ordered by date.
$query = ("SELECT title, headline, timestamp FROM news ORDER BY
timestamp DESC LIMIT 10");
$result = mysql_query($query) or die ('Error in query: $query .
' .mysql_error());
What I want to do is create a headline page, where for example the
first result is the main headline with title, image and text, results
2 and 3 are subheadlines (with a different table format), and the
remaining headlines just show the title (again with a different table
format). So how can I separate the results.
I have tried the following where $count determines what happenes when
firstly result 1, and then results 2 and 3, and finally the remaining
are current.
$count=0
if (mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_array($result, MYSQL_ASSOC) AND
$count=1)
{
$page=1; echo $page;
$title = $row['title'];
$headline = $row['headline'];
$count=count+1;
}
while($row = mysql_fetch_array($result, MYSQL_ASSOC) AND
$count<4)
{
$page=2; echo $page;
$title = $row['title'];
$headline = $row['headline'];
$count=count+1;
}
while($row = mysql_fetch_array($result, MYSQL_ASSOC) AND
$count>3)
{
echo $count;
$page=3; echo $page;
$title = $row['title'];
$headline = $row['headline'];
$count=count+1;
}
}
But for some reason I do not get past the first 'while' loop.
Again apologies for what might seem a very simple question.
Alec
.
- Follow-Ups:
- Re: Result Sets
- From: Tim Streater
- Re: Result Sets
- Prev by Date: Re: How can I distinguish between production and development?
- Next by Date: Re: Result Sets
- Previous by thread: Re: How can I distinguish between production and development?
- Next by thread: Re: Result Sets
- Index(es):
Relevant Pages
|