marklarah Posted October 21, 2007 Share Posted October 21, 2007 Hi. Im like...a beginner at php (i know a quite a bit, but not as much as you guys) Anyway Im coding a casino thing for some message forums (www.fraqppster.net/boards/casino) and with the "chips" you can buy prizes. (which are just images.) Anyway, I want it so it when the user buys the prize, their user ID gets added to "buyers" field in the prizes table. I have done that (and the spacer thingy is "|") But now, how do I look up in sql for the indivddual user that has bought the item? So like when the user goes on their "My prizes page" (which is where i want it to display) it shows up all the prizes they bought. Here is the code for the page where you buy the item: Here is the buying thing that does work (but not for multiple items if the user bought two) <?php $item = $_POST["item"]; //item chosen by user If ($item == 'trophy') //sets the price. I could do an sql call and put it in but i can't be bothered PS i do have the name of the item in the sql table, price can be added easily if you want { $price = "1000"; $item_id = "1"; } else if ($item == 'tim') { $price = "750"; $item_id = "2"; } If ($userinfo['chips'] < $price) { echo "You don't have enough for $item."; } else { $row = mysql_fetch_assoc($result); $set_item_buyers = $row['buyers'] . $useridm . '|'; $query="UPDATE users SET chips = chips-$price WHERE username = '$username';"; mysql_query($query); mysql_query("UPDATE prizes SET buyers = '$set_item_buyers' WHERE id = $item_id"); } echo "Well done! You bought $item. Enjoy!"; ?> Here is the displaying code which does not work. It also would not actually display the picture even if it did, any help on that please? <?php $row = mysql_fetch_assoc($result); $items = ''; $result_c = mysql_query('SELECT id, buyers, name, FROM prizes'); while($row_c = mysql_fetch_assoc($result_c)) { $buyers = explode('|', $row_c['buyers']); if(in_array($useridm, $buyers)) { $items .= (empty($items) ? '' : ', ') . $row_c['item_name'] . [<b>'.count(array_keys($buyers, $useridm)).'</b>]' : ''); echo $items; ?> Any help really appreceated. Quote Link to comment https://forums.phpfreaks.com/topic/74181-help-with-imploding-please/ Share on other sites More sharing options...
marklarah Posted October 21, 2007 Author Share Posted October 21, 2007 Oh, server version is: 4.1.21 and error currently: Parse error: syntax error, unexpected '[' in /home/mark/public_html/boards/casinofiles/prizes.php on line 18 Quote Link to comment https://forums.phpfreaks.com/topic/74181-help-with-imploding-please/#findComment-374632 Share on other sites More sharing options...
fenway Posted October 22, 2007 Share Posted October 22, 2007 Oh, server version is: 4.1.21 and error currently: Parse error: syntax error, unexpected '[' in /home/mark/public_html/boards/casinofiles/prizes.php on line 18 First... use code blocks (I've fixed it for you this time)... second, that's a PHP error... find it first, there may not be anything wrong from the mysql-side. Quote Link to comment https://forums.phpfreaks.com/topic/74181-help-with-imploding-please/#findComment-375443 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.