Jump to content

Changing a Number into a word


jonoc33

Recommended Posts

I currently have the following script which, when there is a number, it changes it into a word.

 












$results = mysql_query("SELECT package FROM clients WHERE clientid = $_SESSION[client_id]");
if($values = mysql_fetch_array($results)){
echo $values['package'] != 1 ? "You are on an <font color=red>Advanced Package</font" : "You are on a <font color=green>Starter Package</font>";
echo "<br />";
};

 

Now I have three packages for my site.

1. Starter Package

2. Basic Package

3. Advanced Package.

 

The code I showed above shows that if it is a 1, it will show as Starter, and if it is anything else it will show up as Advanced. I can't find a way to fit in Basic Package as 2 (so when there is a 2, show Basic Package).

 

Can anyone take a look at my script and see what they can do?

Link to comment
https://forums.phpfreaks.com/topic/79371-changing-a-number-into-a-word/
Share on other sites

<? 
include("db.php");
$sql = "SELECT package FROM clients WHERE clientid = $_SESSION[client_id]";
$result= mysql_query($sql, $connection) or die (mysql_error());
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result))  {
$package = $row['$Package'];
if($package = "1") {
$package ="Starter";
} else
if($package = "2") {
$package ="Basic Package";
} else
if($package = "3") {
$package ="Advanced";
} 


} 
}

echo "$package";
?>

 

Try to use and if statment something like this for this query.

you can try with switch too...

<?php
include("db.php");
$sql = "SELECT package FROM clients WHERE clientid = $_SESSION[client_id]";
$result= mysql_query($sql, $connection) or die (mysql_error());
if (mysql_num_rows($result) > 0) 
{
while ($row = mysql_fetch_array($result))  
{
// you can add this code after you fetch the record
        $package = $row['$Package'];
switch ($package) 
	{
	case "1";
	$package ="Starter";
	break;
	case "2";
	$package ="Basic Package";
	break;
	case "3";
	$package ="Advanced";
	break;
	}
}
}

echo $package;
?>


$sql = "SELECT package FROM clients WHERE clientid = $_SESSION[client_id]";
$result= mysql_query($sql, $connection) or die (mysql_error());
{
while ($row = mysql_fetch_array($result))  
{
// you can add this code after you fetch the record
        $package = $row['package'];
switch ($package) 
	{
	case "1";
	$package = "Starter Package";
	break;
	case "2";
	$package = "Basic Package";
	break;
	case "3";
	$package = "Advanced Package";
	break;
	}
}
}

echo $package;

}
elseif ($client_name == 'admin')
{

 

It has already connected to the DB, so that isn't the problem.

It doesn't give an error, it just blanks it and everything below it also (if you know what I mean)

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.