DJTim666 Posted August 27, 2007 Share Posted August 27, 2007 I am currently coding usershops for my website where users will be able to sell their items. I need help making it so that users can price multiple items all at once. I am thinking maybe a foreach statement or something but I am not 100% sure. What I want to happen is this; The user has 20 items in their shop, they price all 20 items, and hit submit, and it prices all of those items. Sorry if this doesn't make to much sense. MSN: djtim2005@gmail.com AIM: Freudian666 Feel free to add me so I can explain further ! -- DJ Quote Link to comment https://forums.phpfreaks.com/topic/66911-help-with-shop/ Share on other sites More sharing options...
Jessica Posted August 27, 2007 Share Posted August 27, 2007 We'd need to see more of your code and database structure to help. A foreach would work but you could probably do it much easier with one SQL statement to update all items in the users shop with the price. Quote Link to comment https://forums.phpfreaks.com/topic/66911-help-with-shop/#findComment-335454 Share on other sites More sharing options...
DJTim666 Posted August 27, 2007 Author Share Posted August 27, 2007 But, they would be updating all 20 items with different prices. Here is the code I have so far; <?php require_once("core.php"); loggedin(); $shopID = $_GET['shopID']; $shopID2 = mysql_query("SELECT * FROM usershops WHERE owner='" . $Yourname . "'"); $shopID3 = mysql_fetch_array($shopID2); echo "<h3>Your Shop</h3>"; echo "<a href='$PHP_SELF?act=prices'>Edit Prices</a> | <a href='viewshops.php?shopID=" . $shopID3['id'] . "'>View Your Shop</a>"; if (!$act) { if (!mysql_num_rows($shopID2)) { echo "You don't have a Shop yet. Click <a href='$PHP_SELF?act=create'>here</a> to create one. Creating a shop costs 1,500 RBC."; die(); } else { echo "Welcome to user shops. Please navigate around using the links above."; } } if ($act == 'create') { $description = $_POST['descrip']; $shop_name = $_POST['shop_name']; $safe_shop_name = mysql_real_escape_string(striptags($shop_name)); $safe_description = mysql_real_escape_string(striptags($description)); if (!isset($shop_name)) { echo "<form action='$PHP_SELF?act=create' method='post'> Shop Name: <input type='text' name='shop_name' /><br /> Description: <input type='text' name='descrip' size='30' /><br /> <input type='submit' value='Create Shop' /> </form>"; } if (isset($description)) { if (mysql_num_rows($shopID2)) { showerror("You already have a shop. Why do you need another?"); } if (empty($description) || empty($shop_name)) { showerror("You left one of the required fields blank."); } if ($userinfo['point'] < 1500) { showerror("You don't have enough RBC to create a shop."); } } else { mysql_query("INSERT INTO usershops(owner, description, shope_name) VALUES ('" . $Yourname . "', '" . $safe_description . "', '" . $safe_shop_name . "')"); echo "You have just created a shop. You may now sell all the items you like."; } } if ($act == 'prices') { $query = mysql_query("SELECT * FROM user_items WHERE location=3 AND owner='" . $Yourname . "'"); echo "<table border='1' width='100%' bordercolor='blue'> <tr> <td><b>Item</b></td> <td><b>Price</b></td> <td><b>Remove</b></td> </tr>"; while ($row_shop = mysql_fetch_array($query)) { echo "<tr> <td><img src='" . $row_shop['image'] . "'><br />" . $row_shop['name'] . "</td> <td>lalala</td> </tr>"; } } require_once("footer.php"); ?> EDIT: Noticed a couple errors. Fixed them ! Quote Link to comment https://forums.phpfreaks.com/topic/66911-help-with-shop/#findComment-335455 Share on other sites More sharing options...
DJTim666 Posted August 27, 2007 Author Share Posted August 27, 2007 Anyone :'(! Quote Link to comment https://forums.phpfreaks.com/topic/66911-help-with-shop/#findComment-335467 Share on other sites More sharing options...
Jessica Posted August 27, 2007 Share Posted August 27, 2007 If all 20 prices are different you'll need to use a foreach. Are you having an actual problem or is this just theoretical? Quote Link to comment https://forums.phpfreaks.com/topic/66911-help-with-shop/#findComment-335473 Share on other sites More sharing options...
DJTim666 Posted August 27, 2007 Author Share Posted August 27, 2007 I am asking before I start coding so maybe I can get an idea as to what I need to do. An example would be nice. Quote Link to comment https://forums.phpfreaks.com/topic/66911-help-with-shop/#findComment-335477 Share on other sites More sharing options...
Jessica Posted August 27, 2007 Share Posted August 27, 2007 We're not going to write it for you - just start. Here is the manual on foreach which contains many examples: http://us3.php.net/foreach Quote Link to comment https://forums.phpfreaks.com/topic/66911-help-with-shop/#findComment-335479 Share on other sites More sharing options...
DJTim666 Posted August 27, 2007 Author Share Posted August 27, 2007 I've been looking at that page for the past 3 hours, and nothing is helping me o_O! Quote Link to comment https://forums.phpfreaks.com/topic/66911-help-with-shop/#findComment-335480 Share on other sites More sharing options...
DJTim666 Posted August 27, 2007 Author Share Posted August 27, 2007 Ok, now I have my foreach statement. How would I store 20 new prices into an array? Quote Link to comment https://forums.phpfreaks.com/topic/66911-help-with-shop/#findComment-335572 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.