jonoc33 Posted November 29, 2007 Share Posted November 29, 2007 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 More sharing options...
jonoc33 Posted November 29, 2007 Author Share Posted November 29, 2007 Edited Link to comment https://forums.phpfreaks.com/topic/79371-changing-a-number-into-a-word/#findComment-401831 Share on other sites More sharing options...
dewey_witt Posted November 29, 2007 Share Posted November 29, 2007 <? 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. Link to comment https://forums.phpfreaks.com/topic/79371-changing-a-number-into-a-word/#findComment-401834 Share on other sites More sharing options...
jonoc33 Posted November 29, 2007 Author Share Posted November 29, 2007 Nope, that didn't work. It sort of disappeared itself and everything below it. Is it because I have an elseif below it? } elseif ($client_name == 'admin') { Link to comment https://forums.phpfreaks.com/topic/79371-changing-a-number-into-a-word/#findComment-401836 Share on other sites More sharing options...
~n[EO]n~ Posted November 29, 2007 Share Posted November 29, 2007 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; ?> Link to comment https://forums.phpfreaks.com/topic/79371-changing-a-number-into-a-word/#findComment-401862 Share on other sites More sharing options...
jonoc33 Posted November 29, 2007 Author Share Posted November 29, 2007 Strange.. it didn't work. Both codes seem to look fine but do not work. Link to comment https://forums.phpfreaks.com/topic/79371-changing-a-number-into-a-word/#findComment-401876 Share on other sites More sharing options...
~n[EO]n~ Posted November 29, 2007 Share Posted November 29, 2007 Hmmm.... are you getting errors , can you post your new code Nope, that didn't work. It sort of disappeared itself and everything below it. Is it because I have an elseif below it? } elseif ($client_name == 'admin') { with this also... Link to comment https://forums.phpfreaks.com/topic/79371-changing-a-number-into-a-word/#findComment-401877 Share on other sites More sharing options...
jonoc33 Posted November 29, 2007 Author Share Posted November 29, 2007 $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) Link to comment https://forums.phpfreaks.com/topic/79371-changing-a-number-into-a-word/#findComment-401880 Share on other sites More sharing options...
jonoc33 Posted November 29, 2007 Author Share Posted November 29, 2007 I think I know the problem.. $connection hasn't been made to anything. EDIT: AH working now, I fixed the problem, it hadn't connected to the DB because of that variable.. Thanks alot Link to comment https://forums.phpfreaks.com/topic/79371-changing-a-number-into-a-word/#findComment-401881 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.