Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Stylize font in php

Featured Replies

How would I go about making certain parts of the echo bold?

 

For example

 

while($row = mysql_fetch_array($results)){
echo  $num_rows++ . ' ' . $row['Name'] . ' ' . $row['Points'] . '<br/>';

 

Outputs: 1 Name 500

 

but I want the points to be Bold and the num of rows a different color font,

 

For Example

 

1 Name 500

Edited by Renaissance-Design
Please use the code button or tags to format your code.

while($row = mysql_fetch_array($results)){
echo  '<span style="color:#FFA500;">'. $num_rows++ .'</span>'. ' ' . $row['Name'] . ' ' . '<strong>'. $row['Points'] .'</strong>' . '<br/>';

Edited by webdesigner93

  • Author

while($row = mysql_fetch_array($results)){
echo  '<span style="color:#FFA500;">'. $num_rows++ .'</span>'. ' ' . $row['Name'] . ' ' . '<strong>'. $row['Points'] .'</strong>' . '<br/>';

 

 

Thank you very much!

To be honest, semantically this is a table and should be a HTML table, however you style it:

 

<table>
 <thead>
   <tr>
     <th>ID</th><th>Name</th><th>Points</th>
   </tr>
 </thead>
 <tbody>
 <?php while($row = mysql_fetch_array($results)) : ?>
   <tr>
     <td class="id"><?php echo $num_rows++; ?></td><td class="name"><?php echo $row['Name']; ?></td><td class="points"><?php echo $row['Points']; ?></td>
   </tr>
 <?php endwhile; ?>
 </tbody>
</table>

 

The alternative PHP loop syntax (above) is much better for output as it preserves HTML formatting and whitespace and only dips into PHP to actually echo the variables.

  • Author

To be honest, semantically this is a table and should be a HTML table, however you style it:

 

<table>
 <thead>
   <tr>
     <th>ID</th><th>Name</th><th>Points</th>
   </tr>
 </thead>
 <tbody>
 <?php while($row = mysql_fetch_array($results)) : ?>
   <tr>
     <td class="id"><?php echo $num_rows++; ?></td><td class="name"><?php echo $row['Name']; ?></td><td class="points"><?php echo $row['Points']; ?></td>
   </tr>
 <?php endwhile; ?>
 </tbody>
</table>

 

The alternative PHP loop syntax (above) is much better for output as it preserves HTML formatting and whitespace and only dips into PHP to actually echo the variables.

 

 

Ok this is helpful because I now have the correct output, although Id like to align the points to the far right so they are all aligned together and can be read easily, could I do this using the following code you presented? if so how would I do this as I dont quite understand where Id paste this? here is what i have at the moment....

 

 

<?php

$connect = mysql_connect("localhost","root","pw");

if(!$connect){
die("Failed to connect: " . mysql_error());
}

if(!mysql_select_db("TourneyLeague")) {
die("Failed to select DB:" . mysql_error());
}

$results = mysql_query("SELECT * FROM TourneyTable ORDER BY points DESC LIMIT 15");
$num_rows = 1;

while($row = mysql_fetch_array($results)){
echo '<span style="color:#ff0;">'. $num_rows++ .'</span>'. ' ' . $row['Name'] . ' -  ' . '<strong>'.$row['Points'] .'</strong>'. '<br/>';
}

$sql = "\n"
   . " ALTER TABLE `testtable`\n"
   . " ORDER BY `Points`";





?>

 

 

and that will display it like this

 

1. joe blogs 5000

2. peter hilberry 3200

3. joe luther 2300

4. will willows 1500

5. martin pea 750

 

would there be a way using the table code u presented to have the id + name aligned left and the points aligned right in different cells?

 

effectivly

 

1. joe blogs--------5000

2. peter hillberry--3200

3. joe luther--------2300

 

.. ?

Edited by Renaissance-Design
Please use the code button or tags to format your code.

First things first: format your code properly. It makes it easier for the people who are trying to help you to read it. It's this button on the editor: code.png

 

<?php

$connect = mysql_connect("localhost","root","pw");

if(!$connect){
       die("Failed to connect: " . mysql_error());
}

if(!mysql_select_db("TourneyLeague")) {
       die("Failed to select DB:" . mysql_error());
}

$results = mysql_query("SELECT * FROM TourneyTable ORDER BY points DESC LIMIT 15");
$num_rows = 1;

?>

<table>
 <thead>
   <tr>
     <th>ID</th><th>Name</th><th>Points</th>
   </tr>
 </thead>
 <tbody>
 <?php while($row = mysql_fetch_array($results)) : ?>
   <tr>
     <td class="id"><?php echo $num_rows++; ?></td><td class="name"><?php echo $row['Name']; ?></td><td class="points"><?php echo $row['Points']; ?></td>
   </tr>
 <?php endwhile; ?>
 </tbody>
</table>

<?php

$sql = "\n"
   . " ALTER TABLE `testtable`\n"
   . " ORDER BY `Points`";

?>

 

You can target the <td> classes in your stylesheet:

 

.name {
text-align: left;
}

.points {
text-align: right;
}

  • Author

First things first: format your code properly. It makes it easier for the people who are trying to help you to read it. It's this button on the editor: code.png

 

<?php

$connect = mysql_connect("localhost","root","pw");

if(!$connect){
       die("Failed to connect: " . mysql_error());
}

if(!mysql_select_db("TourneyLeague")) {
       die("Failed to select DB:" . mysql_error());
}

$results = mysql_query("SELECT * FROM TourneyTable ORDER BY points DESC LIMIT 15");
$num_rows = 1;

?>

<table>
 <thead>
   <tr>
     <th>ID</th><th>Name</th><th>Points</th>
   </tr>
 </thead>
 <tbody>
 <?php while($row = mysql_fetch_array($results)) : ?>
   <tr>
     <td class="id"><?php echo $num_rows++; ?></td><td class="name"><?php echo $row['Name']; ?></td><td class="points"><?php echo $row['Points']; ?></td>
   </tr>
 <?php endwhile; ?>
 </tbody>
</table>

<?php

$sql = "\n"
   . " ALTER TABLE `testtable`\n"
   . " ORDER BY `Points`";

?>

 

You can target the <td> classes in your stylesheet:

 

.name {
text-align: left;
}

.points {
text-align: right;
}

 

 

Okay thats great thanks, as you can see I am a complete novice, even to the works of a forum so your have to excuse me for that, you have been a great help to me today maybe I will have to 'buy you a beer' ha, thanks again!

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.