Re: Result Sets



Tim Streater wrote:
In article <629dba1a-92dd-436d-b635-a022d1a82dd8@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
ajtdds@xxxxxxx wrote:

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

1) I'm not sure why you think you need the first while loop, you only want to go round it once anyway.

2) It should in any case be $count==1 rather than $count=1

And then it will be skipped because $count is initialized to 0. so the while condition will then never be true.
....
--
Ron Fox
NSCL
Michigan State University
East Lansing, MI 48824-1321
.



Relevant Pages

  • Re: Result Sets
    ... Am trying to put together a news page. ... What I want to do is create a headline page, ... $page=1; echo $page; ... But for some reason I do not get past the first 'while' loop. ...
    (comp.lang.php)
  • Re: Result Sets
    ... Am trying to put together a news page. ... What I want to do is create a headline page, ... $page=1; echo $page; ... "That excessive Baile ought not to be required nor excessive Fines imposed ...
    (comp.lang.php)
  • Result Sets
    ... Am trying to put together a news page. ... What I want to do is create a headline page, ... and 3 are subheadlines (with a different table format), ... $page=1; echo $page; ...
    (comp.lang.php)
  • Re: TeamB pictures
    ... Lots of news are simply copy-pastes of last year news. ... The world is a loop. ... > Why do they re-use the same 'Borland Bounces Back' headline every year? ...
    (borland.public.delphi.non-technical)
  • Two Things ... (was Re: The Hazards of Instant Communication)
    ... One report, 1010 newsradio said ... > In reading this morning's newspaper closely, I note the headline "12 ... > I mention this because of today's passion for "instant" news. ... > We all know the famous Truman victory where everyone just "knew" Dewey ...
    (comp.dcom.telecom)