Displaying Information in more than 1 colour
I already have a database with information stored in it. And I want to display the information on a webpage using PHP.
Is it possible to tell it to be displayed with the first letter in one colour and the rest of the word in another colour.
So, for example, my name on this site is Smithster.
If this word was stored in a database and I wanted to display it on the webpage in the following format......
Smithster
Is this possible and if so, anyone know how to do it?!?!?!?
Thanks in advance.
Smithster.
Display data from database in a table with different colours
Ive created a new thread which sort of runs off the previous one because I thought it is in a way a different question to the last one even though the two are related so I hope that this is ok.
Basically, I have this code that retrieves data from a table in a database.
Code:
<?php
$dbhost = 'localhost';
$dbuser = 'dbuser';
$dbpass = 'dbpass';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'dbname';
mysql_select_db($dbname);
$query = "SELECT alias FROM challengeus";
$result = mysql_query($query)
or die(mysql_error());
print "
<center>
<table border=\"5\" cellpadding=\"5\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#808080\" width=\"20%\" id=\"AutoNumber2\" bgcolor=\"#C0C0C0\"><tr>
<td align=center bgcolor=\"#ffffcc\"><b>Player:</b></td>
</tr>";
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
print "<tr>";
print "<td align=center>" . $row['alias'] . "</td>";
print "</tr>";
}
print "</table>";
print "</center>";
?>
and I have this code that outputs data from the database onto a webpage but into 2 different colours....eg.
Smithster
Code:
<style type="text/css">
.name-firstletter {
color: red;
}
.name-rest {
color: #48d1cc;
}
</style>
</head>
<body>
<p>
<span class="name-firstletter">
<?php echo($name[0]); ?>
</span>
<span class="name-rest">
<?php echo(substr($name, 1)); ?>
</span>
</p>
when I put the 2 scripts together, I end up with this....
Code:
<html>
<style type="text/css">
.name-firstletter {
color: red;
}
.name-rest {
color: #48d1cc;
}
</style>
<?php
$dbhost = 'localhost';
$dbuser = 'dbuser';
$dbpass = 'dbpass';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'dbname';
mysql_select_db($dbname);
$query = "SELECT alias FROM challengeus";
$result = mysql_query($query)
or die(mysql_error());
print "
<center>
<table border=\"5\" cellpadding=\"5\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#808080\" width=\"20%\" id=\"AutoNumber2\" bgcolor=\"#C0C0C0\"><tr>
<td align=center bgcolor=\"#ffffcc\"><b>Player:</b></td>
</tr>";
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
print "<tr>";
print "<td align=center>"<span class=\"name-firstletter\"><?php echo($row[0]); ?> </span> <span class=\"name-rest\"> <?php echo(substr($row, 1)); ?> </span>"</td>";
print "</tr>";
}
print "</table>";
print "</center>";
?>