Connecting Tech Pros Worldwide Help | Site Map

How to display first record in bold

dr. zoidberg
Guest
 
Posts: n/a
#1: Jul 17 '05
Hello,

I'm pulling news titles from MySQL. How Can I display first record in
bold (different than other ones). What is the best way to do that. Is
there some 'magic' query or PHP function.

*First Headline*
Second Headline
Third Headline

TNX

Andreas Paasch
Guest
 
Posts: n/a
#2: Jul 17 '05

re: How to display first record in bold


dr. zoidberg wrote:
[color=blue]
> Hello,
>
> I'm pulling news titles from MySQL. How Can I display first record in
> bold (different than other ones). What is the best way to do that. Is
> there some 'magic' query or PHP function.
>
> *First Headline*
> Second Headline
> Third Headline
>
> TNX[/color]

I would look into mysql_num_rows == 1 ... if your select statement is made
orderly.
If the value is one, then print in bold ... else don't.

/Andreas
--
Registeret Linux user #292411
Andy Hassall
Guest
 
Posts: n/a
#3: Jul 17 '05

re: How to display first record in bold


On Sat, 15 Nov 2003 01:28:27 +0100, "dr. zoidberg" <someone@example.wrong>
wrote:
[color=blue]
>I'm pulling news titles from MySQL. How Can I display first record in
>bold (different than other ones). What is the best way to do that. Is
>there some 'magic' query or PHP function.
>
>*First Headline*
> Second Headline
> Third Headline[/color]

Just use a simple flag.

$first = true;
while ($row = mysql_fetch_array()) {
if ($first) {
// bold
$first = false;
} else {
// normal
}
}

--
Andy Hassall (andy@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Geoff Berrow
Guest
 
Posts: n/a
#4: Jul 17 '05

re: How to display first record in bold


I noticed that Message-ID: <4hvarvkjqbk0alrdvnfau55m4muhfm34hk@4ax.com>
from Andy Hassall contained the following:
[color=blue]
> Just use a simple flag.
>
>$first = true;
>while ($row = mysql_fetch_array()) {
> if ($first) {
> // bold
> $first = false;
> } else {
> // normal
> }
>}[/color]
Calling the function does that automatically

$row = mysql_fetch_array()
//print the row in bold
while ($row = mysql_fetch_array()) {
//print the other rows normally
}

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
nariman amiri
Guest
 
Posts: n/a
#5: Jul 17 '05

re: How to display first record in bold


Andreas Paasch wrote:
[color=blue]
> dr. zoidberg wrote:[/color]
[color=blue][color=green]
>> Hello,
>>
>> I'm pulling news titles from MySQL. How Can I display first record
>> in
>> bold (different than other ones). What is the best way to do that.
>> Is
>> there some 'magic' query or PHP function.
>>
>> *First Headline*
>> Second Headline
>> Third Headline
>>
>> TNX[/color][/color]
[color=blue]
> I would look into mysql_num_rows == 1 ... if your select statement is
> made
> orderly.
> If the value is one, then print in bold ... else don't.[/color]
[color=blue]
> /Andreas[/color]


As far as I know there is no single SQL line that can solve your problem.
you need to check the pointer location, and the best way will be something
like this:

$query_headline = mysql_query ("SELECT headline FROM headlines") or die
("Query failed!");
$first_row = true;
while ($row=mysql_fetch_array($query_headline)){
if ($first_row)
{
echo "<b>".$row['topicName']."</b><br />";
$first_row = false;
} else
{
echo $row['topicName']."<br />";
}
}

Hope it helps...

##-----------------------------------------------#
Article posted from PHP Freaks NewsGroup
http://www.phpfreaks.com/newsgroup
Get Addicted: comp.lang.ph
##-----------------------------------------------##
Closed Thread