Jump to content


Photo

Print first table row in bold...


  • Please log in to reply
4 replies to this topic

#1 jcbarr

jcbarr
  • Members
  • PipPipPip
  • Advanced Member
  • 219 posts

Posted 22 August 2006 - 10:02 PM

Okay here is the code...

<?php

//Get UL C
$sql="SELECT * FROM ballot WHERE POS='C' AND LEAGUE='UL' ORDER BY VOTES DESC LIMIT 2";
$result=mysql_query($sql);

//Create loop and print rows
while($ulfbase=mysql_fetch_array($result)){
	echo "<tr>";
	echo "<td align=center>";
	echo $ulfbase['NAME'];
	echo "</td><td align=center>";
	echo $ulfbase['STAT'];
	echo "</td><td align=center>";
	echo $ulfbase['VOTES'];
	echo "</td>";
	echo "</tr>";
}
?>

Now it only pulls two rows from the database, how do I make it print the text in the first table row in bold, while printing the second table row normal?

Thanks in advance guys, I'm sure this is simple, I just can't think of how to do it right now...

#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 22 August 2006 - 10:42 PM

I suspect you want to do something like this:

<?php

//Get UL C
$sql="SELECT * FROM ballot WHERE POS='C' AND LEAGUE='UL' ORDER BY VOTES DESC LIMIT 2";
$result=mysql_query($sql);

//Create loop and print rows
while($ulfbase=mysql_fetch_array($result)){
$countshit++;
if($countshit == 3){$countshit = 1;}
if($countshit == 1){$ulfbase['NAME'] = "<b>$ulfbase['NAME']</b>";}
if($countshit == 2){$ulfbase['NAME'] = $ulfbase['NAME'];}
echo"<tr>
<td align=center>$ulfbase['NAME']</td>
<td align=center>$ulfbase['STAT']</td>
<td align=center>$ulfbase['VOTES']</td></tr>";
}
?>

PHP Ninja

#3 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 22 August 2006 - 10:43 PM

Test it though. :-) I'm at work and only threw that together.
PHP Ninja

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 22 August 2006 - 10:56 PM

If you just want to print the first line in bold and the rest normal, you can use a simple true/false flag:
<?php
$firstflag = false; // has first row been printed?
$sql="SELECT * FROM ballot WHERE POS='C' AND LEAGUE='UL' ORDER BY VOTES DESC LIMIT 2";
$result=mysql_query($sql);

//Create loop and print rows
while($ulfbase=mysql_fetch_assoc($result)){
        $style = (!$firstflag)?'style="font-weight:bold;text-align:center"':'style="text-align:center"'; // make the correct style
	echo "<tr>";
	echo "<td $style>";
	echo $ulfbase['NAME'];
	echo "</td><td $style>";
	echo $ulfbase['STAT'];
	echo "</td><td $style>";
	echo $ulfbase['VOTES'];
	echo "</td>";
	echo "</tr>";
        if (!$firstflag) $firstflag = true; // first line has been printed
}
?>

Ken

#5 jcbarr

jcbarr
  • Members
  • PipPipPip
  • Advanced Member
  • 219 posts

Posted 22 August 2006 - 10:59 PM

**SOLVED**

Thanks fellas.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users