Jump to content

CloudSex13

Members
  • Posts

    162
  • Joined

  • Last visited

    Never

Everything posted by CloudSex13

  1. I have a file called pick.php. pick.php, in example, would look like this as a link on the page: pick.php?place=2 Let's say 2 is a casino-like outcome. When this link is clicked, I want there to be a random selection of what is displayed on the page pick.php, in example, "You got Casino Outcome 5." or "You got Casino Outcome 10." - as many as I needed to put. So basically, in pick.php, they'll need to be a random generator as to what the results picked will display when the pick.php?place=2 link is accessed. My problem is that I lack the knowledge of how to script a random results generator, because the rand() function only handles integers and variable integers to my knowledge. Could anyone give me a tip or point me in the right direction to accomplish my coding goal? Thank you very much, if so.
  2. For some reason, the variable $itemURL outputs only the last item fetched's URL, and displays that one URL for all data returned. I want each item's unique URL displayed at the end of the path instead. Could anyone see a reason as to why this does not work? Something a little less important too that doesn't work is the ORDER BY ItemName code - it will not order the returned data by it's name either ASC or DESC. Any suggestions? :/ $query = mysql_query("SELECT Inventory FROM Users WHERE Username='$cookie' LIMIT 1"); $getquery = mysql_fetch_assoc($query); $inventory = substr($getquery['Inventory'], 0, -1); $itemnames = array(); $query2 = mysql_query("SELECT * FROM Items WHERE ItemID IN (".$inventory.") AND ItemType='Box' ORDER BY ItemName"); $inventory = explode(",",$inventory); $inventory= array_count_values($inventory); while ($row = mysql_fetch_assoc($query2)) { $itemnames[$row['ItemID']] = $row['ItemName']; $itemurl = $row['ItemURL']; } foreach ($inventory as $key => $count) { $stuff .= "<div class=\"item\"><img src=\"http://www.example.com/images/".$itemURL."\" /><strong>".$itemnames[$key]." (".$count.")</strong><br /><a href=\"action.php?do=remove&itemid=".$key."\">Remove</a></div>"; }
  3. That actually worked! It outputted the following: (2) Box1 (6) Box2 ( The (2) would be an ItemType that's "Plastic", and not a "Box". So this would mean I'd have to separate everything into different Inventory fields in the database to get everything to display properly in sections, but it does work. I sent you a message about what I meant to talk about. Thanks SO much Ken2k7, for you help!
  4. Progress! It didn't die short this time and echoed out the following on the page: string(78) "SELECT ItemID, ItemName FROM Items WHERE ItemID IN (Array) AND ItemType='Box'" array(0) { } array(1) { [""]=> int(1) } (1)
  5. Same error keeps appearing, man: Unknown column 'Array' in 'where clause' D:
  6. Yeah, I PMed you but you never replied back. Error: Unknown column 'Array' in 'where clause'
  7. That seems to output nothing. Is there a way I could speak with you over MSN, Skype, or AOL about this?
  8. No worries either way - I appreciate the dedicated assistance, man.
  9. lol, I know, right? In comparison to what it's displaying now: BOX1 (2) BOX1 (6) BOX1 (8 ) BOX1 (1) BOX2 (2) BOX2 (6) BOX2 (8 ) BOX2 (1) I want it to display: BOX1 (Actual amount of this box) BOX2 (Actual amount of this box) I changed: $listed[$theitemname] = $item; To: $listed[] = $item; And now it only displays 4 BOX1's and 4BOX2's for a total of 8 outputs, where it should only be 2, one for each box, and the number of that box next to it instead of so much output it flows off the screen. Updated code: $query = mysql_query("SELECT * FROM Users WHERE Username='$cookie' LIMIT 1"); $getquery = mysql_fetch_array($query); $inventory = $getquery['Inventory']; $items = explode(",", $inventory); $listed = array(); foreach ($items as $item) { if (!in_array($item, $listed)) { $query = mysql_query("SELECT * FROM Items WHERE ItemID='$item' AND ItemType='Box' ORDER BY ItemName"); $itemamount = array_count_values($items); while ($getquery = mysql_fetch_array($query)) { $itemname = $getquery['ItemName']; $itemid = $getquery['ItemID']; foreach ($itemamount as $theitemname => $theitemamount) { $allitems .= "<div class=\"item\">".$itemname." (".$theitemamount.")</strong>"; $listed[] = $item; } } } }
  10. Oh, gotcha. That outputs something like the following: SHIRT (2) SHIRT (6) SHIRT (8 ) SHIRT (1) PANTS (2) PANTS (6) PANTS (8 ) PANTS (1) SHIRT (2) SHIRT (6) SHIRT (8 ) And then it continues off screen - I'm baffled at this point.
  11. For some reason, that's giving an "Parse error: syntax error, unexpected $end" Hm?
  12. Outputs this: string(36) "3,3,3,1,1,1,1,1,2,2,2,2,2,2,2,1,2,3,"
  13. I don't want rows removed in a table. It's a users inventory stored as one field in a table on a datase - how else could that be stored? I don't get it. Here's the actual code: $query = mysql_query("SELECT * FROM Users WHERE Username='$cookie' LIMIT 1"); $getquery = mysql_fetch_array($query); $inventory = $getquery['Inventory']; Does that make anymore sense, or? :/
  14. Oh, no, ignore that. $inventory is what the users Inventory is stored in the database. That field would have a value of "1,2,3,2,3,2,3,5,7,87677," As far as the database normalization goes, the article on it showed how to use it to link in a search. I have to store data that is consistent and maybe have a small portion removed or added in it.
  15. I did read up on DB normalization. That cannot work for what I'm trying to accomplish. Thank you, though. That string is not being put into an array. The foreach statement is the only thing not working... I can't seem to grasp my head around it.
  16. Thanks for the reply! Actually, $inventory is a value from a field in a table on a database holding the following: "1,2,1,3,4,2,2,4,2," just like that. Updating my question now, I would have to keep explode there. Would everything you suggested still be wrong, or?
  17. I came up with a script (below) that matches values in a given array to items in a table in a database, displays all the items on the page (only once per item), and what I'm trying to do currently is count how many of the items are the same in the array and display it next to that item. I'm not sure as to why this script will not count and display correctly the amounts or items, but I was wondering if anyone could give me some pointers or assistance to help me do so. Thank you kindly if so. $inventory = array("1,2,3,2,3,2,3,5,7,87677"); $items = explode(",", $inventory); $listed = array(); foreach ($items as $item) { if (!in_array($item, $listed)) { $query = mysql_query("SELECT * FROM Items WHERE ItemID='$item' AND ItemType='Box' ORDER BY ItemName"); $itemamount = array_count_values($items); while ($getquery = mysql_fetch_array($query)) { $itemname = $getquery['ItemName']; $itemid = $getquery['ItemID']; foreach ($itemamount as $theitemname => $theitemamount) { $allitems .= "<div class=\"item\">".$itemname." (".$theitemamount.")</strong>"; $listed[$theitemname] = $item; } }
  18. In example, I'm looking on how to replace the string "5," with an empty string "" a specified amount of times. preg_replace does not work because the "," is in the string. str_replace replaces all matched values, and to my knowledge, you cannot specify a manual amount of replace times for multiple matches. Could anyone give me a pointer? :/
  19. Wait, you can combine SQL statements like that crossing tables?
  20. I have a coding problem that has stumped me for the past week: For example, let's say I have a field in a database called Container under the table Users containing the following values: 1,2,3,64,3,3,3,1 I'm trying to link those values to another table in the same database called Things where the user's Container is equal to the ThingID, and then echo all the ones that match. Could anyone offer me a bit of help in how to go about this? Thank you, if so.
  21. Like, would this even be possible to do? Is there actually an array counting function of the same strings contained in an array?
×
×
  • 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.