Those dots aren't helping.
$name= $row['alias'];
Printable View
Those dots aren't helping.
$name= $row['alias'];
ok thank you so much guys for your help. Just one more thing though.
The output of the name works. But there is a space between the first and second letter!!! I can't find where in the script to correct that?!?!?
It's just because there's whitespace between the two <span> tags. Remove it, and all will be fine.
lol thank you, silly me!!!
ok, the script is complete and it leads me onto another question. Lets say I have 10 names I want outputting into a table. I have just been trying by myself by the way!! But I am failing!!
Any ideas would be a help.
Thanks.
How are they stored?
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.
and I have this code that outputs data from the database onto a webpage but into 2 different colours....eg.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>";
?>
Smithster
when I put the 2 scripts together, I end up with this....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>
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>";
?>
New thread created as this is really a different question. I hope the question I have asked answers this question!!
http://www.dynamicdrive.com/forums/s...4765#post94765
MODERATOR EDIT: This is the same discussion, so please only use one thread. It has already been discussed, so anyone who helps you may wish to review this thread when doing so. I merged the two threads. Please keep it this way, for this, and for future questions.
The code (once put together) should look like so:
Notice how I broke out of PHP parsing mode to basically make it easier to keep track of. Hope this helps.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());
?>
<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>
<?php
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
?>
<tr>
<td align=center><span class="name-firstletter"><?php echo $row[0];?></span> <span class="name-rest"><?php echo substr($row, 1));?></span></td>
</tr>
<?php
}
?>
</table>
</center>
Well the script caused an error when first ran. So I put the exact HTML for the span section into it and this time there was no error. But only the top part of the table is shown. Nothing else. Something is still wrong?!?!?