Jump to content

[SOLVED] Capitalization from database


prime

Recommended Posts

Hi currently have a PHP script that I have written access and displaying info from a database, which is working fine, but I've have now decided to do a conversion on the variable drew from the database and first convert it all to lower case then to do the ucfirst, to capitalize the first letter of the variables, and I seem to be having some problems, here the code I wrote, Obiosuly since I am new to php I mis-understanding something

 

<?php // Cant seem to get this part functioning, variable  direct from the database is $name which I am trying to put through a 2 part conversion as you can see, and then down below I'm trying to display the modified variable, except I seem to having some problems

$lower = strtolower("$name");
$cname = ucfirst($lower);

?>

<?php

echo "<table class='fore' border='1' bordercolor='white' width='100%' align='center'>";
echo "<tr>
        
        <td><center><b class='thead'>Character name</b></center></td>
        
        <td><center><b class='thead'>Character Site/Blog URL</b></center></td>
        
        <td><center><b class='thead'>Player's Comments</b></center></td>
        
        </tr>";
while ($row = mysql_fetch_array($result))

    {
        extract($row);
            echo "<tr>\n
                    <td width='150' valign='top'><b class='tname'><a href='http://hiscore.runescape.com/lang/en/aff/runescape/hiscorepersonal.ws?user1=$cname'>$cname</a></b></td>\n
                    
# Script continues but this is the end of the relevant part
?> 

Link to comment
https://forums.phpfreaks.com/topic/50425-solved-capitalization-from-database/
Share on other sites

Ok here's the complete code

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="keywords" content="runescape, mmorpg, registry, registrar, runescape registry" />
<meta name="description" content="This is the runescape registry, a place which links to people's personal runescape sites or pages" />
<meta name="copyright" content="Copyright © 2007 Bradley Floyd and Marlaine Rathman Floyd, All Rights Reserved">
<meta name="robots" content="index,follow" />
<meta name="robots" content="ALL" />
<meta name="revisit-after" content="7 days" />
<meta name="Classification" content="registry" />
<meta http-equiv="Content-Language" content="en-us">
<meta name="rating" content="general">
<meta http-equiv="imagetoolbar" content="no" />
<meta name="MSSmartTagsPreventParsing" content="true">

<title>Runescape Registration Database</title>

<style type="text/css">
<!--

b.thead
{
text-align:center;
font-family:new times roman;
font-weight:600;
color:black;
font-size:13pt;
}

b.tname
{
text-align:left;
font-family:new times roman;
font-weight:normal;
color:black;
font-size:13pt;
}

b.ttitle
{
text-align:left;
font-family:new times roman;
font-weight:normal;
color:black;
font-size:10pt;
}

b.tcstart
{
text-align:left;
font-family:new times roman;
font-weight:normal;
color:black;
font-size:8pt;
}

b.tlink
{
text-align:left;
font-family:new times roman;
font-weight:600;
color:black;
font-size:11pt;
}

b.nolink
{
text-align:left;
font-family:new times roman;
font-weight:normal;
color:black;
font-size:11pt;
}

b.tdes
{
text-align:left;
font-family:new times roman;
font-weight:normal;
color:black;
font-size:11pt;
}

b.body
{
text-align:left;
font-family:new times roman;
font-weight:600;
color:orange;
font-size:13pt;
}

b.mainlink
{
text-align:center;
text-decoration: underline;
font-family:new times roman;
font-weight:normal;
color:orange;
font-size:12pt;
}

b.regform
{
text-align:center;
text-decoration: underline;
font-family:new times roman;
font-weight:900;
color:black;
font-size:12pt;
}

b.description
{
text-align: left;
text-decoration: none;
font-family:new times roman;
font-weight: 500;
color:black;
font-size:12pt;
}

b.nodescription
{
text-align: left;
font-style: italic;
text-decoration: none;
font-family:new times roman;
font-weight: 300;
color:black;
font-size:10pt;
}

b.url
{
text-align: left;
text-decoration: none;
font-family:new times roman;
font-weight: 900;
color:black;
font-size:12pt;
}

b.nourl
{
text-align: left;
font-style: italic;
text-decoration: none;
font-family:new times roman;
font-weight: 300;
color:black;
font-size:10pt;
}

b.banned
{
text-align: left;
text-decoration: none;
font-family:new times roman;
font-weight: 900;
color: red;
font-size:12pt;
}

-->
</style>


<link rel=stylesheet type="text/css" href="../../styles.css">


</head>


<body class="standard" link="black" alink="black" vlink="black"><br/><br/><b class="body"><div align="center">

Whether you're a member or a free player, have a website or not, currently active or not, feel free to register any and all of your runescape characters. Once your character has been registered, it will not be removed even if you've been banned.
<br/>
Click individual names to see current highscores on Runescape. Many of the listings below were added by Runescape Registry due to their high skills, Runescape videos, and/or personal web sites and were not volunteered by the character.
</b>
<p/>
<table class="fore">
	<tr><td>
	<a href="../registration form/register.php" target="_self"><b class="regform">Register Here</b></a>
	</td></tr>
</table>


</div>

<b class="body"><div align="center">
We reserve the right to remove any site links due to questionable content!
<p/>
We will not list any sites that deal in real world item trading or that encourage cheating!
</div></b>
<br/>


<?php include("../../../admin/secret admin files/verification.php") ?>

<?php

$connection = mysql_connect($host,$user,$password)
	or die("couldn't connect toserver");

$db = mysql_select_db($database,$connection)
	or die("couldn't select database");

$query= "SELECT * FROM registry ORDER BY name";
$result = mysql_query($query)
	or die("couldn't execute query");

?>

<?php // Cant seem to get funtioning

$lower = strtolower("$name");
$cname = ucfirst($lower);


?>

<?php




echo "<table class='fore' border='1' bordercolor='white' width='100%' align='center'>";
echo "<tr>
        
        <td><center><b class='thead'>Character name</b></center></td>
        
        <td><center><b class='thead'>Character Site/Blog URL</b></center></td>
        
        <td><center><b class='thead'>Player's Comments</b></center></td>
        
        </tr>";
while ($row = mysql_fetch_array($result))

    {
        extract($row);
            echo "<tr>\n
                    <td width='150' valign='top'><b class='tname'><a href='http://hiscore.runescape.com/lang/en/aff/runescape/hiscorepersonal.ws?user1=$cname'>$cname</a></b></td>\n
                    
<td width='200' valign='top'>";
                    
                    
                            
                    if ($url == null)
                    {
                    echo "<b class='nourl'>No website submitted</b>";
                    }
                    elseif ($url == "banned")
                    {
                    echo "<b class='banned'><b>Url has been removed due to breach of Runescape rules</b>";
                    }                    
                    
                    
                    
                    
                    else                    
                    {
                    echo "<a href='$url' target='_new'><b class='url'>$name's Website</b>";
                    }    
                    
				              
                
                                        
                    echo "</b></a></td>\n
                    
                    <td width='*' valign='top'><b class='tdes'>";
                    
                    if ($description == null)
                    {
                    echo "<b class='nodescription'>No comment</b>";
                    }
                                       
                    else                    
                    {
                    echo "<b class='description'>$description</b>";
                    }   
                   
                    
                    
            echo "</b></td>\n
                    </tr>\n";
                
            echo "<tr><td colspan='3'></td></tr>\n";
        
    }    
    echo "</table>\n";
    
?>

<br/>
<hr/>
<div align="center">
<a href="http://www.runescaperegistry.com" target="_top"><b class="mainlink">Home</b></a>
</div>

</body></html>

<?php
/* snip */

$result = mysql_query($query) or die("couldn't execute query");

// Cant seem to get funtioning

$name = ucfirst(strtolower($name));  // THIS LINE NEEDS TO BE....

/* snip */

while ($row = mysql_fetch_array($result)) {
        extract($row);  // ....BELOW THIS LINE!
?>

This

<?php // Cant seem to get funtioning

$lower = strtolower("$name");
$cname = ucfirst($lower);


?>

doesn't make any sense where you have the code.  Where is the variable $name being set?

 

You should be doing this inside the "while" loop:

<?php
while ($row = mysql_fetch_array($result))
    {
            echo "<tr>\n
                    <td width='150' valign='top'><b class='tname'><a href='http://hiscore.runescape.com/lang/en/aff/runescape/hiscorepersonal.ws?user1=" . $row['name'] . ">" . ucfirst(strtolower($row['name'])) . "</a></b></td>\n<td width='200' valign='top'>";
             switch ($row['url']) {
                    case null:
                           echo "<b class='nourl'>No website submitted</b>";
                           break;
                    case 'banned':
                           echo "<b class='banned'><b>Url has been removed due to breach of Runescape rules</b>";
                           break;
                     default:
                            echo "<a href='$url' target='_new'><b class='url'>$name's Website</b>";
              }
              echo "</b></a></td>\n
                        <td width='*' valign='top'><b class='tdes'>";
             if ($row['description'] == null)
                    echo "<b class='nodescription'>No comment</b>";
             else
                    echo "<b class='description'>" . $row['description'] . "</b>";
             echo "</b></td>\n
                    </tr>\n";
             echo "<tr><td colspan='3'></td></tr>\n";
    }    
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.