The problem with the one before is that there was no way to handle, so this function solves that issue. The following function (similar to one above) will render an array as a series of HTML select options (i.e. JOIN product AS p ON p.product_id = c.Getting Started Introduction A simple tutorial Language Reference Basic syntax Types Variables Constants Expressions Operators Control Structures Functions Classes and Objects Namespaces Enumerations Errors Exceptions Fibers Generators Attributes References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Predefined Attributes Context options and parameters Supported Protocols and Wrappers Security Introduction General considerations Installed as CGI binary Installed as an Apache module Session Security Filesystem Security Database Security Error Reporting User Submitted Data Hiding PHP Keeping Current Features HTTP authentication with PHP Cookies Sessions Dealing with XForms Handling file uploads Using remote files Connection handling Persistent Database Connections Command line usage Garbage Collection DTrace Dynamic Tracing Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions Cryptography Extensions Database Extensions Date and Time Related Extensions File System Related Extensions Human Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions Other Basic Extensions Other Services Search Engine Extensions Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation GUI Extensions Keyboard Shortcuts ? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto search SELECT SUM(p.product_price * c.quantity) AS total FROM cart AS c In the case that there's a quantity field, just change the SUM() function to multiply price by quantity: JOIN product AS p ON p.product_id = c.p_id SELECT SUM(p.product_price) AS total FROM cart AS c Assuming you don't have a "quantity" field, the function can be as simple as one SQL query with a JOIN and using the SUM() function. Your code looks much more complicated than it needs to be. Write your code below and put the answer into the variable ANSWER. Answer with a call to the function using the array: 4,256,5,13,1. You're overwriting the variable $sql and $row inside the loop that's using those variables for iteration, you're also overwriting the value of $total on each iteration. Need to create a function called sumArray () that should take an array as argument and return the sum of all items in the array. I'm only getting the latest price not the total price. The product_price in other table which is product. I'm trying to get total price from cart table. $sql = $db->query("SELECT product_price from product WHERE product_id='$product_id'") $no=$sql->rowCount() // number of rows affected by the last SQL statement $sql = $db->query("SELECT * from cart WHERE ip_add='$ip'")
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |