Getting a string from a int

Hello,

I’m very new to PHP, literally just started yesterday so any help is appreciated. I tried to Google as much as I could before this and this is all I could really find.

I’ve created an array with a few strings which I need to get with an int I’ve got saved on my database but I’m not entirely sure what I’ve done wrong. My MySQL is linked up fine and works if I only want to show the integer but I’d like it to show the corresponding text in the array.

Testing here(user LLAMA is what I’m testing): http://gametrade.sx/site/signature.php?player_name=LLAMA
As you can see the other stats are pulled fine, but the "Rank: " part is empty.

[php]
$result=mysql_query($query);

$rankname = array
(
array(“Rank 1”),
array(“Rank 2”),
array(“Rank 3”),
array(“Rank 4”)
);

$Rank=mysql_result($rankname[$result],0,"Rank");

$text_rank = "Rank: $Rank";

imagettftext($im, 10, 0, 185, 85, $text_color, $font, $text_rank); 

[/php]

So if the record for Rank = 0 it should output “Rank: Rank 1”, but at the moment it’s only outputting "Rank: "

Thank you.

Well, you did not show us your query. There are so many problems with the small code snippet you showed
to us. First, you are using deprecated code. MySQL is outdated and will not work in the future. The newer
version MySQLi (i is for “imporved”) or the PDO version should be used. The MySQLi version is easy to use
and simple to update to. Please look that up on the PHP site.

Next, you show a query without showing the query itself. Also, you have not used any type of error-checking.
My guess without seeing the query, that you are pulling out an empty recordset. Since you did not check for
an empty recordset, you might be creating bad outputs yourself.

Normally, you load your query into a variable such as $query. You did this although not showed to us. Next,
you normally test the output of the query to see if it contains data. If it does, you display it. If no data was
pulled from the database, you set up an alternative display or you debug the error somehow.

Here is a site that explains how to do this. I would suggest using the second example format which is
named “Example (MySQLi Procedural)” and uses the the MySQLi format similar to your old code. You will
have to alter your connection string to the MySQLi version. This site has just about anything you will ever
need in tutorials, but, some are hard to locate. I use Google to locate them for others here on this site. I
use search words in Google like “w3schools get data from database” or other searches, but put the name
of the site first, “w3schools”. Hope it helps…
http://www.w3schools.com/php/php_mysql_select.asp

Sponsor our Newsletter | Privacy Policy | Terms of Service