kryoxis Posted January 22, 2012 Share Posted January 22, 2012 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.. Quote Link to comment https://forums.phpfreaks.com/topic/255492-php-function-not-working-properly/ Share on other sites More sharing options...
ManiacDan Posted January 22, 2012 Share Posted January 22, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/255492-php-function-not-working-properly/#findComment-1309929 Share on other sites More sharing options...
kryoxis Posted January 22, 2012 Author Share Posted January 22, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/255492-php-function-not-working-properly/#findComment-1309934 Share on other sites More sharing options...
ManiacDan Posted January 22, 2012 Share Posted January 22, 2012 Within these lines that you posted, scatter echo or var_dump statements that show the contents of the variables. Check to see if they're what you think they're supposed to be. Make sure the query is correct. Quote Link to comment https://forums.phpfreaks.com/topic/255492-php-function-not-working-properly/#findComment-1310044 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.