Thursday, January 4, 2018
php Associative Multidimensional Array
php Associative Multidimensional Array
php - Associative Multidimensional Array -
i want able utilize variable (which value imputed in textbox) in associative multidimensional array , print out rest of array values associated it.
here have far doesnt work
<html> <body> <form method="post" action="newcal.php"> <table> <tr> <td> item #: </td> <td> <input type=text name= txtitem > <br> </td> <td> </td> <td> <fieldset style = "width:60px"> <input type=submit value = "get data" name= getdata> <input type=submit value = "add cart" name= addto> <input type=submit value = "get total" name= gettotal> </fieldset> </td> </tr> </table> </form> <?php $item = isset($_post[txtitem]); $stuff = array( array("id" => 1,"name" => "apples","price" => 50 ), array("id" => 2,"name" => "pineapples","price" => 125 ), array("id" => 3,"name" => "mango","price" => 35 ), array("id" => 4,"name" => "banana","price" => 25 ), array("id" => 5,"name" => "naseberry","price" => 38 )); if(isset($_post[getdata])) { foreach ($stuff $row) { if ($row[id] == $item) { $name = $row[name]; $price = $row[price]; } } echo $name; echo $price; } ?> </body> </html>
i think error next line:
$item = isset($_post[txtitem]); $item beingness set boolean value. want this:
$item = (isset($_post[txtitem]) ? intval($_post[txtitem]) : null); php arrays multidimensional-array
alternative link download
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.