Jump to content

mrooks1984

Members
  • Posts

    82
  • Joined

  • Last visited

    Never

Everything posted by mrooks1984

  1. hi, Array ( [option_price] => Array ( [1] => 5.00 [2] => 0.00 ) ) )
  2. this one is 209: $option_price .= $option_price + $product_option_price['option_price']; thanks.
  3. hello, i am trying to get my array result to keep adding up the result into the $option_price varible, but i am getting this message: Fatal error: Unsupported operand types on line 209 so put that part of the code on here to see if someone can help. $option_price = '0.00'; foreach ($product_option_prices as $product_option_price) { $option_price .= $option_price + $product_option_price['option_price']; } thanks all
  4. by the way this is a continueation of this: http://forums.phpfreaks.com/index.php?topic=363743.15 but no longer fitted under the title and i cant edit my posts so moved to this one. is there away to e.g. if i have 3 results for $store_variation_values['title']; is there a way to call out say result 1 with my current code. if this is possible how, as i could make it work with a run loop.
  5. hello, i am hoping someone can help me, i am trying to build a array all the array displays correctly using the print_r so i know that parts working. the issue is i have 2 arrays one with the drop down menu name and other information and the other one with the values for each dropdown menu. i am currently trying to figure out and need help on how to get it to display multiple menus if they exist in the database, my current code only displays the last result of the array. heres the code function product() { //Import product varible global $product; $product = mysql_real_escape_string($product); //convert product value into a title $value = str_replace("-"," ",$product); //Connect to database and get the required product. $result = mysql_query("SELECT * FROM store_products WHERE name = '$value' ORDER BY id"); //If the product is not found in the database. if (mysql_num_rows($result) == 0) { //Display a message echo '<h1>' . "This product doesent exist" . '</h1>' . "\n"; //If products are found in database. } else { while ($row = mysql_fetch_array($result)) { $store_products[] = array("name" => $row['name'], "image" => $row['image'], "category" => $row['category'], "description"=> $row['description'], "price" => $row['price']); } foreach ($store_products as $store_product) //Get variations Names $sql = "SELECT * FROM store_variations WHERE product = '$product'"; $res = mysql_query($sql) or die(mysql_error()); //If the options are not named if (0 === mysql_num_rows($res)) { } else { while ($row = mysql_fetch_assoc($res)) { $store_variations[] = array("title" => $row['title'], "variation" => $row['variation'], "price" => $row['price'], "product"=> $row['product']); } foreach ($store_variations as $store_variation) print_r($store_variations); } //Get variations values $sql = "SELECT * FROM store_variations_values WHERE product = '$product'"; $res = mysql_query($sql) or die(mysql_error()); //If the options are not named if (0 === mysql_num_rows($res)) { } else { while ($row = mysql_fetch_assoc($res)) { $store_variations_values[] = array("title" => $row['title'], "variation" => $row['variation'], "price" => $row['price'], "product"=> $row['product']); } foreach ($store_variations_values as $store_variation_values) print_r($store_variations_values); } //Show Product form. echo '<div id ="StoreCol1">' . "\n"; echo '<form method="post" action="">' . "\n"; echo '<h1>' . $store_product['name'] . '</h1>' . "\n"; echo '<input type="hidden" name="name" value="' . $store_product['name'] . '">' . "\n"; echo '<a href="public/images/' . $store_product['image'] . '" target="_blank"><img src="public/images/' . $store_product['image'] . '" height="200" width="300" style="border:none;" /></a>' . "\n"; echo '<p>' . $store_product['description'] . '</p>' . "\n"; echo '<a href="store.php?category=' . $store_product['category'] . '">' . "Go Back" . '</a>' . "\n"; echo '</div>' . "\n"; echo '<div id="StoreCol2">' . "\n"; echo '<p>' . "Any extra charges will be displayed and added in your cart." . '</p>' . "\n"; echo '<p>' . '<b>' . "Price: £" . $store_product['price'] . '</b>' . "</p>" . "\n"; echo '<p>' . "Excludes postage and packaging." . '</p>' . "\n"; //Add options here if ($store_variation_values['variation'] == $store_variation['variation']) { echo '<p>' . $store_variation['title'] . ": "; echo '<select name = "option'.$store_variation['variation'].'" >' . "\n"; echo '<option value= "'.$store_variation_values['title'].'">'.$store_variation_values['title'].'</option>' . "\n"; echo '</select></p>'; echo '</form></div>'; echo $store_variation_values['title']; } } } i think this is the area that needs fixing, maybe a loop or something, just not sure how to. echo '<p>' . $store_variation['title'] . ": "; echo '<select name = "option'.$store_variation['variation'].'" >' . "\n"; echo '<option value= "'.$store_variation_values['title'].'">'.$store_variation_values['title'].'</option>' . "\n"; echo '</select></p>'; echo '</form></div>'; echo $store_variation_values['title']; if anyone could help me i would be really greatful, thanks all
  6. hi, i have done abit more and got this far: foreach ($store_variations as $store_variation) { foreach ($store_variations_values as $store_variation_values) { if ($store_variation_values['variation'] == $store_variation['variation']) { echo '<p>' . $store_variation['title'] . ": "; echo '<select name = "option'.$store_variation['variation'].'" >' . "\n"; echo '<option value= "'.$store_variation_values['title'].'">'.$store_variation_values['title'].'</option>' . "\n"; echo '</select></p>'; echo '</form></div>'; } } } this code sort of works, it displays the title of the dropdown menus and the dropdown menus, the issue is i have 2 values for one of the variations and is showing 2 of the same dropdown menus just with the single different values in. i do know its because its going around multiple times on the foreach loop so its only creating the single value, but dont know how to fix this
  7. thanks very much for your help, i am more aless there now and have a 3 arrays setup and getting information and working great. i have one issue/question heres the code i am working with: //Import product varible global $product; $product = mysql_real_escape_string($product); //convert product value into a title $value = str_replace("-"," ",$product); //Connect to database and get the required product. $result = mysql_query("SELECT * FROM store_products WHERE name = '$value' ORDER BY id"); //If the product is not found in the database. if (mysql_num_rows($result) == 0) { //Display a message echo '<h1>' . "This product doesent exist" . '</h1>' . "\n"; //If products are found in database. } else { while ($row = mysql_fetch_array($result)) { $store_products[] = array("name" => $row['name'], "image" => $row['image'], "category" => $row['category'], "description"=> $row['description'], "price" => $row['price']); } foreach ($store_products as $store_product) //Get variations Names $sql = "SELECT * FROM store_variations WHERE product = '$product'"; $res = mysql_query($sql) or die(mysql_error()); //If the options are not named if (0 === mysql_num_rows($res)) { } else { while ($row = mysql_fetch_assoc($res)) { $store_variations[] = array("title" => $row['title'], "variation" => $row['variation'], "price" => $row['price'], "product"=> $row['product']); } foreach ($store_variations as $store_variation) print_r($store_variations); } //Get variations values $sql = "SELECT * FROM store_variations_values WHERE product = '$product'"; $res = mysql_query($sql) or die(mysql_error()); //If the options are not named if (0 === mysql_num_rows($res)) { } else { while ($row = mysql_fetch_assoc($res)) { $store_variations_values[] = array("title" => $row['title'], "variation" => $row['variation'], "price" => $row['price'], "product"=> $row['product']); } foreach ($store_variations_values as $store_variation_values) print_r($store_variations_values); } //Show Product form. echo '<div id ="StoreCol1">' . "\n"; echo '<form method="post" action="">' . "\n"; echo '<h1>' . $store_product['name'] . '</h1>' . "\n"; echo '<input type="hidden" name="name" value="' . $store_product['name'] . '">' . "\n"; echo '<a href="public/images/' . $store_product['image'] . '" target="_blank"><img src="public/images/' . $store_product['image'] . '" height="200" width="300" style="border:none;" /></a>' . "\n"; echo '<p>' . $store_product['description'] . '</p>' . "\n"; echo '<a href="store.php?category=' . $store_product['category'] . '">' . "Go Back" . '</a>' . "\n"; echo '</div>' . "\n"; echo '<div id="StoreCol2">' . "\n"; echo '<p>' . "Any extra charges will be displayed and added in your cart." . '</p>' . "\n"; echo '<p>' . '<b>' . "Price: £" . $store_product['price'] . '</b>' . "</p>" . "\n"; echo '<p>' . "Excludes postage and packaging." . '</p>' . "\n"; //Add options here } as you can see i have the option section empty (at the bottom) some of the arrays have multiple options and i am trying to figure out how to make it loop through the result in the code below until it runs out of results. echo '<select name = "option1" >' . "\n"; echo '<option value= "'.$store_variation_values['title'].'">'.$store_variation_values['title'].'</option>' . "\n"; thanks again
  8. 1. in other words if i desided i want to add for example price into the array as well as options, these caused me to get got stuck in the past with arrays adding more then one thing in to it and results into them. 2. add results from a array e.g. $sql = "SELECT * FROM store_variations WHERE product = '$product'"; $res = mysql_query($sql) or die(mysql_error()); //If the options are not named while ($row = mysql_fetch_assoc($res)) { $row['value_title']; how would i also add the $row['value_title'] into the array as well. thanks for the heads up on the options naming i will have to do that using ids like you suggested, when i had the to while statements before i used titles as i dident think that each value for each product and dropdown menu would be the same, but now i am doing it this way i be getting all the results in one go from the query and adding them into the array, well thats what i am hoping to save on multiple querys. thanks again
  9. thanks very much for your post, just got 3 questions 1. how would i add extra values into the array and get it to show in the for each statement 2. how would i get a mysql query to add into the query 3. echo '<pre>',print_r($_POST,true); could you tell me what this line is doing, i know its printing the array but not sure what the post and true for or meaning. thanks again
  10. 1. the post option1 etc etc depend if the option in the form is set 2. if i can do it that way that would be great and by the sound of it very useful, i have seen a few arrays in the past but never got my head around them fully, maybe just never seen a good example. i am hoping to change it so not limited to 5 options in the future 3. the store variation values are the seperate values for each drop down menu like pink green etc and price in there is for setting prices in for each value if wanted, the store variation table is for the titles of the dropdown menus and price of all values in that dropdown menu again if wanted. 4. both price varibles are for the drowndown menu price or the dropdown menu value prices if any are set thanks again.
  11. hi, ok thanks for letting me know, now i know it cant be done like that i rethink the code. short term arrays are out of the question i dont fully understand them so i have a think of another way, thanks again.
  12. hi thanks for your answer, it seems that one is fine its caused by the $run one as soon as i replace it with a one its fine
  13. i have now attached the full class and screenshots of the table, in case i have missed something. i need to tidy up some of the code and querys but just trying to get it working first. full class function add_product() { //Get Date $date = date("Y/m/d"); //Gets Required Form Information $product = $_POST['name']; $customer = session_id(); //Setup Varibles $price = '0.00'; $option_price = '0.00'; //start options blank $option1_value = ""; $option2_value = ""; $option3_value = ""; $option4_value = ""; $option5_value = ""; //Connect to database and get the required product price. $result = mysql_query("SELECT price FROM store_products WHERE name = '$product' ORDER BY id"); while ($row = mysql_fetch_array($result)) { //Give results a varible $price = $row['price']; } //run 5 times for ($run = 1; $run <= 5; $run++) { //Get Option Names $sql = "SELECT * FROM store_variations WHERE product = '$product' AND variation = '$run'"; $res = mysql_query($sql) or die(mysql_error()); if (0 === mysql_num_rows($res)) { echo "another issue"; //Make the option names and prices blank ${'option'.$run.'_title'} = ""; ${'option'.$run.'_price'} = "0.00"; } else { while ($row = mysql_fetch_assoc($res)) { ${'price'.$run} = $row['price']; ${'option'.$run.'_title'} = $row['title']; }//end of while }//end of else //If options are set get result if (isset($_POST['option'.$run]) && $_POST['option'.$run] != "") { ${'option'.$run.'_value'} = ${'option'.$run.'_title'}; }//end of options if }//end of run if ($option1_value != "") { $option_price = $option_price + $price1; } if ($option2_value != "") { $option_price = $option_price + $price2; } if ($option3_value != "") { $option_price = $option_price + $price3; } if ($option4_value != "") { $option_price = $option_price + $price4; } if ($option5_value != "") { $option_price = $option_price + $price5; } //run 5 times for ($run = 1; $run <= 5; $run++) { if (${'option'.$run.'_value'} != "") { //Run option price query $sql = "SELECT * FROM store_variations_values WHERE product = '$product' AND title = '${'option'.$run.'_value'}'"; $res = mysql_query($sql) or die(mysql_error()); if (0 === mysql_num_rows($res)) { echo "Heres the issue"; }else{ while ($row = mysql_fetch_assoc($res)) { ${'price'.$run} = $row['price']; $option_price = $option_price + ${'price'.$run}; }//end of else }//end of while }//end of if if (isset($_POST['option'.$run]) && $_POST['option'.$run] != "") { ${'option'.$run.'_value'} = ${'option'.$run.'_title'}.": ".$_POST['option'.$run]; }//end of options if }//end of run //Add product price to total option price and give it the price varible $price = $price + $option_price; //Insert into the database mysql_query("INSERT INTO store_cart (product, option1, option2, option3, option4, option5, customer, price, date) VALUES ('$product','$option1_value','$option2_value','$option3_value','$option4_value', '$option5_value','$customer','$price', '$date')"); //Tell customer the product has been added. echo $option1_value." ".$product." oh yea"; echo '<p>' . "Product Added To Basket" . '</p>'; }//Ends Add product function if i change the query to the following it works: $sql = "SELECT * FROM store_variations WHERE product = '$product' AND variation = '1'"; its very strange thanks again, i just dont know were i am going wrong
  14. hi, thanks for your responce. I have done echos for the varibles out and seem to be fine, i think its just the query keeps defaulting to the num rows 0. i will have a look for code to tell it to show all errors, but i am show xampp does this out of the box with out needing this, but will look. i will try dumping out the $row but i think it will be empty due to it defaulting to the num rows. i am not getting any errors at all. product varible is below //Import product varible global $product; $product = mysql_real_escape_string($product);
  15. hello all, i am hoping someone can help me, i have the following code and check the table a few tims and it should be finding results, so it must be the code. //run 5 times for ($run = 1; $run <= 5; $run++) { //Get Option Names $sql = "SELECT * FROM store_variations WHERE product = '$product' AND variation = '$run'"; $res = mysql_query($sql) or die(mysql_error()); if (0 === mysql_num_rows($res)) { echo "another issue"; //Make the option names and prices blank ${'option'.$run.'_title'} = ""; ${'option'.$run.'_price'} = "0.00"; } else { while ($row = mysql_fetch_assoc($res)) { ${'price'.$run} = $row['price']; ${'option'.$run.'_title'} = $row['title']; }//end of while }//end of else //If options are set get result if (isset($_POST['option'.$run]) && $_POST['option'.$run] != "") { ${'option'.$run.'_value'} = ${'option'.$run.'_title'}; }//end of options if }//end of run many thanks all.
  16. thanks for getting back to me, no just the part i think is the issue, but i have it working now, heres the code: //get cart info order items $result = mysql_query("SELECT product,option1,option2,option3,option4,option5 FROM store_cart WHERE customer='$session_id'"); while($row = mysql_fetch_array($result)) { $product= $row['product']; //Run through all 5 rows and add them to the output if they contain data. for ($run = 1; $run <= 5; $run++) { if ($row['option'.$run] != 'NULL') { ${'option'.$run} = $row['option'.$run]; }else{ ${'option'.$run} = ""; } } $product_list .= $product." - ".$option1." ".$option2." ".$option3." ".$option4." ".$option5."<br>"; } then i just call the product list variable and it works.
  17. hello all, i am trying to convert results from a database and email them, but its only doing one of the results and i cant figure out how to fix this, i am hoping someone on here can help me out. heres my current code while($row = mysql_fetch_array($result)) { //Send order placed email $customer_name = $customer_first_name . " " . $customer_last_name; $email_subject = "A order has been placed"; $email_message_admin = "" . $row['product'] . $row['option1']. $row['option2']; $email_message_customer = ""; $date_time = date("F j, Y, g:i a"); $sql = "INSERT INTO ticket (name, subject, message, email, date_time) VALUES ('$customer_name','$email_subject','$email_message_admin','$customer_email','$date_time')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } //Send Email To Site Owner mail($store_email, $email_subject, $email_message_admin, 'From:' . $store_email); //Send Email To Customer mail($customer_email, $email_subject, $row['user_message'], 'From:' . $store_email); many thanks all.
  18. hello thanks for your responses. heres the code i have for a dropdown menu echo '<div id="StoreOption1">'; echo $option1_title; if ($option1_price > 0) { echo "£" . $option1_price . " "; } echo '<select name = "option1" >'; echo '<option value= "NULL">None</option>'; while ($row = mysql_fetch_assoc($res)) { if ($row['price'] > 0) { echo '<option value= "' . $row['value'] . '">' . $row['title'] . " + £" . $row['price'] . '</option>'; }else{ echo '<option value= "' . $row['value'] . '">' . $row['title']; } } echo '</select>' . '</div>'; } the value i want to update on selection from a dropdown menu echo "Price: ?" . $price . "<br />"; as you can see i dont have any js as of yet as i dont know where to start with that, hence why i come on here for help and advice. thanks all.
  19. hello all, i have looked for a solution on Google but cant seem to find one, or maybe i have used the wrong keywords in the search. i am hoping someone can help me on here. i don't know much js at all, but i have a drop down menu built from php results from a database and i have a echo to display a separate field depending on what is selected. i need it to on a selection or a item in the drop down menu to update the php echo with a value depending on what was selected. i think the way is js, but not knowing js i am hoping someone can help me.
  20. thanks very much ChristianF you are the man!, i now know the basics and changed your code abit to work with the new sql code. the only thing i couldn't get working is the $location .= coming up with unidentified variable if i remember rightly and wasent sure how to actually tell it to display the results so just changed that bit to a echo and it all works a treat, i looked at the article wasent sure about some of it so looked for another one and found this: http://www.tizag.com/mysqlTutorial/mysqlleftjoin.php/ which is helping me get my head around it. again thanks very much for all your help. this is what i have ended with: function view() { $session_id = session_id(); $query = mysql_query("SELECT * FROM store_cart LEFT JOIN store_options ON store_cart.product = store_options.product WHERE store_cart.customer='$session_id'"); if (0 === mysql_num_rows($query)) { }else{ while ($row = mysql_fetch_assoc($query)) { echo '<h1>' . $row['product'] . '</h1>'; //Run through all 5 rows and add them to the output if they contain data. for ($run = 1; $run <= 5; $run++) { if ($row['option'.$run] != 'NULL') { echo '<p>' . $row['title'.$run] . ": " . $row['option'.$run] . "</p>\n"; } } } } }
  21. hi christian, could you give me a example of what you mean here please: if-tests and echos are prime examples of repeated patterns which could have been merged, using variables for the tiny bits that differ between them had a look at the link and not sure what it means, so i have to look all over google and get my head around it, do you know any good links that i could read. thanks again.
  22. thanks for getting back to me, the reason i have the two tables is one stores all the information for different titles of options or variants per product so i have upto 5 different ones per product e.g. size, colour etc, the variants them self's are then stored in a different table for the title and values for the drop down menu then linked to a certain product. the other one stores all values selected from the drop down menu into a database with a customer id along with total price calculated depending on options. i tried doing this using session array for a solid month, but just couldn't get it to work the way i can with the database way. i have tidied the code down a lot more then it was lol, but this was the best i could figure out. the code i put in is getting the information from the cart table once finished will get price, each product name and option one to five if it was selected. the problem i noticed is i then need to get the title of the variants do display next to each option, put thats stored in the other table, so the only way i could figure out how to get this doing it the way i did. i attach screenshots of the database to give you a idea. i will try get my head around the left join, if anyone has other ideas or anything please let me know thanks again i am grateful for you inputs i am hoping to get it working and then keep coming back it and making the code better as i learn more.
  23. hello all, i am currently trying to figure out how to do multiple mysql querys, the code i have sort of works. if displays the correct information, but doesent loop again (only shows the first result. heres the code: class Cart extends CMS { function view() { $session_id = session_id(); $query1 = mysql_query("SELECT * FROM store_cart WHERE customer='$session_id'"); $query2 = mysql_query("SELECT * FROM store_options"); if (0 === mysql_num_rows($query1)) { }else{ while ($row1 = mysql_fetch_assoc($query1)) { while ($row2 = mysql_fetch_assoc($query2)) { echo '<h1>' . $row1['product'] . '</h1>'; if ($row1['product'] == $row2['product']) { if ($row1['option1'] != 'NULL') { echo '<p>' . $row2['title1'] . ": " . $row1['option1'] . '</p>'; } if ($row1['option2'] != 'NULL') { echo '<p>' . $row2['title2'] . ": " . $row1['option2'] . '</p>'; } if ($row1['option3'] != 'NULL') { echo '<p>' . $row2['title3'] . ": " . $row1['option3'] . '</p>'; } if ($row1['option4'] != 'NULL') { echo '<p>' . $row2['title4'] . ": " . $row1['option4'] . '</p>'; } if ($row1['option5'] != 'NULL') { echo '<p>' . $row2['title5'] . ": " . $row1['option5'] . '</p>'; } } } } } } } hoping someone can help me, i am still learning php so any answers please answer as simple as possible. thanks all.
×
×
  • 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.