Jump to content

Recommended Posts

Here's the code with the function that won't work!

 

$itemsRaw = explode(" ", $player['inventory']);
foreach ($itemsRaw as $inv){
$contents = explode("-", $inv);
if(strlen($contents[0]) > 0 && strlen($contents[1]) > 0 && $contents[1] > 0)
echo getItemName($contents[0]) . " (" . number_format($contents[1]) . ")<br />";
}

 

Here's my function:

 

function getItemName($id_raw){
$id = $id_raw - 1;
$q = $db->query("SELECT * FROM items WHERE id = $id") or die(mysql_error());
$f = $db->fetch_assoc($q);
return $f['name'];
}

 

It stops the page when it gets to that point and won't load anything else and the function doesn't even work with it :/ What's wrong with it? If anything..

Link to comment
https://forums.phpfreaks.com/topic/255492-php-function-not-working-properly/
Share on other sites

There's two things wrong with it:

1)  There's  no error-handling code

2)  Nobody tried to debug it.

 

Are you absolutely 100% certain that the value coming into this function is a number?  Are you sure you even have error_reporting turned on?

I don't know how to turn it on, and yes the output looks like 1040 (1)

The 1040 is the item code and (1) is the quantity..

Before I put getItemName in front of it, it puts out the items and the quantity.

 

After I put that before content, it messes up..

 

What the getitemname function is supposed to do.. Is take the 1040 that's being output or in other words the item number, scanning through the items table and comparing the id column to the item number then combining it with the name column that correlates with the item number and outputs that instead of the raw item number code..

 

 

^ I hope that makes sense... lol

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.