PHP - Create Dynamic Dropdown From $_session Variable
Hi all, here's my code:
Code: [Select] <?php foreach ($_SESSION['topping'] as $value) { echo "<tr><td width='30%'>Topping</td><td width='50%'>$value</td><td width='20%'><select name='notopping'>"; foreach ($_SESSION['cupcake'] as $number) { '<option name="notoppings[]" value="'.$number.'">".$number."</option>'; } echo "</select></td></tr>"; } ?> $_SESSION['cupcake'] is a value from either 6, 12, 24 or 36. What I want to do is put them into a drop down box (second foreach) as the value and the displayed value - counting up from 1 (so 1,2,3,4,5,6 or up to 12,24 etc). Also by creating this as an array, does this mean than for each topping (say Vanilla and Chocolate) the value dynamically created can be used on the next page by using $_POST['notoppings'] to display each type (two different numbers - one for Vanilla and one for Chocolate). Does that make sense? Thanks! Jason Similar TutorialsHello everyone, I am working on a form that is similar to a shopping cart system and I am thinking of creating a button that submits the checked value and saves them to a $_SESSION variable. And also a link that links to a cart.html that takes the values of a $_SESSION variable. I am have trouble figuring what tag/attribute should I use in order to achieve that.
Right now my code attached below submits the checked values to cart.html directly. However I want my submit button to save the checked box to a $_SESSION variable and STAY on the same page. And then I will implement a <a> to link to the cart.php.
I researched a little bit about this subject and I know it's somewhat related to ajax/jquery. I just wanted to know more about it from you guys. I appreciate your attention for reading the post and Thanks!
Below is the form that I currently have:
<form name= "finalForm" method="POST" action="cart.php"> <input type="Submit" name="finalSelected"/> <?php foreach($FinalName as $key => $item) {?> <tr> <td><input type="checkbox" name="fSelected[]" value="<?php echo htmlspecialchars($FinalID[$key])?>" /> <?php echo "$FinalID[$key] & $item";?> </td> </tr> <?php } ;?>Below is the code for cart.php <?php require ('connect_db.php'); if(isset($_POST['finalSelected'])) { if(!empty($_POST['fSelected'])) { $chosen = $_POST['fSelected']; foreach ($chosen as $item) echo "aID selected: $item </br>"; $delimit = implode(", ", $chosen); print_r($delimit); } } if(isset($delimit)) { $cartSQL = "SELECT * from article where aID in ($delimit)"; $cartQuery = mysqli_query($dbc, $cartSQL) or die (mysqli_error($dbc)); while($row = mysqli_fetch_array($cartQuery, MYSQLI_BOTH)) { $aTitle[] = $row[ 'name' ]; } } ?> <table> <?php if(isset($delimit)) { $c=0; foreach($aTitle as $item) {?> <tr> <td> <?php echo $aTitle[$c]; $c++;?> </td> </tr> <?php }}?> </table> I have a form that inserts information into a mysql, the only prolem is I need to add different surrounding html to the information when entering it into the database depending what the value is...(essentially I want to store font color around different levels) How would I define the same variable with different information depending on the value? The information is called using: if ($_SERVER['REQUEST_METHOD'] == 'POST') { $editLEVEL=$_POST['level']; I want it so if 'Level1' is the posted value then $editLEVEL would be '<color=1>$editLEVEL</color>' but if 'Level2' is the posted value the $editLEVEL would be '<color=2>$editLEVEL</color>' If you dont understand just let me know I'll try explain best I can.
First let me explain my code. This is later included in project_status.php] . In project_status.php] , I have included another file project_status_app.php which contains a HTML form.
<?php include 'inc_fn_header_and_menu.php'; function includeFile($file,$variable) { $var = $variable; include($file); } if (isset($_GET['id']) && $_GET['id']!="") { $pid = $_GET['id']; $_SESSION['pidForApproval'] = $_GET['id']; $query = 'SELECT * FROM `profile` WHERE pid ='.'\''.$pid.'\''; $result=mysqli_query($db,$queryToRetrievePP) or die("There are no records to display ... \n" . mysqli_error()); foreach ($result as $row) { $status = $row['status']; } } ...........some PHP and HTML code....... <div id="customerPurchaseApprovalForm"> <?php echo '<p>APPROVAL FOR CUSTOMER PURCHASE</p>'; $discountApprovalStatus = "Granted"; if ($discountApprovalStatus == "Granted") { includeFile("project_status_app.php",$highestannualvalue); } else { //......... } In project_status_app.php I am attempting to retrieve pidForApproval from the $_SESSION array. <?php // put your code here UPDATE `pp` SET `customer_purchase_remarks` = 'hahaha' WHERE `pp`.`id` = 207; if ($_SERVER['REQUEST_METHOD'] == 'POST') { include '../../inc/fastlogin.php'; $sql = "UPDATE pp SET customer_purchase_remarks ='{$_POST['remarkstxt']}' WHERE pp.pid='{$_SESSION['pidForApproval']}'"; $result = mysqli_query ( $fastdb, $sql ) ; if (mysqli_affected_rows($fastdb) != 1) { $_SESSION['err_cpa_rmks'] = "<p>Error while updating WHERE id='{$_SESSION['pidForApproval']}'</p>"; //echo "<p>Error while updating WHERE id='{$_POST['pidForApproval']}'</p>".mysqli_error($fastdb); } else { $_SESSION['suc_cpa_rmks'] = "<p>Records was updated successfully.</p>"; //echo "Records was updated successfully."; } header ("location: project_status.php?id="$_SESSION['pidForApproval']); exit(); } ?> When I load project_status.php, project_status_app.php is supposed to display the form. Once the user fills in the form the and the submit button has been pressed, the UPDATE statement is supposed to run and then it is supposed to navigate back to project_status.php?id=FA142. But the update is failing and the when the project_status.php is loaded back, the url looks like this http://localhost/fast/project_status.php?id= . The id is empty. It is supposed to be something like this http://localhost/fast/project_status.php?id=FA142. With the id being populated at the header ("location: project_status.php?id=".$_SESSION['pidForApproval']);
Missing some information. Code: [Select] <?php function Login() { session_start(); $_SESSION["loggedin"] = true; echo "You are logged in!"; header("Location: ../L_index.php"); //Aka Logged in Index. } function Logout() { $_SESSION["loggedin"] = false; session_destroy(); } function checklogin() { session_start(); if ($_SESSION["loggedin"] == true) { return true; } else { return false; } } ?> This is just a tiny bit of my code, there is security holes, but as you see, there is 3 functions: Login Logout Checklogin But when i use the Login function, everything is fine, but if i then use the checklogin, then it always returns true(it returns true after i used the logout function), why? Quote Hi guys, I have a question, I have a fairly large site wich we have resellers for, but in certain circumstances for admin purposes, we need to be able to login under the same credentials EG: I might be doing something on one machine and i need to log in on another machine to do something else but with my user name and pass At the moment when i try to to this It will log out the session already logged in when i try to log in from the other machine Is there away around this,, i suspect that when i log in from the other machine its ending the first session Any Idears Guys and Gals..... really stuck Hi guys, I've got this php script which display the users of my database in a dynamic dropdown: <?php include "leadscript/connect_to_mysql.php"; $canvass_name=""; $sql = mysql_query("SELECT * FROM csj_canvasser"); $appointmentCount6 = mysql_num_rows($sql); // count the output amount if ($appointmentCount6 > 0) { while($row = mysql_fetch_array($sql)){ $c_employee = $row["c_employee"]; $canvass_name .='<option value="' . $c_employee . '">' . $c_employee . ' </option>'; } } ?> <form> <select name="c_employee"> <option value="">Select a person:</option> <?php echo $canvass_name; ?> </select> </form> I was wondering if there's a way I can write a code to GET value I select from the dynamic dropdown and use it to write a select query. Thank Hi guys. I am having a hard time finding a solution for this, is it possible to get not the value of a dropdown (oh what's it called??? ) but what is in between of the <option> tag?like, Code: [Select] <select name="catID"> <option value=$row['c_id']>$row['c_name']</option> and save it to the database??cuz I'm using a dynamic dropdown which bases the content of another dropdown by the id of the previous. And so, if i save it to the database, instead of for example "BSA" is saved, the id of "BSA" which is "1" is saved..any ideas guys? Hi everyone, I've read through the FAQs for Dynamic Dropdown Menus on this site, as well as others, and I can't figure out why my code won't work. I have two dropdown boxes that need to be populated with data from a mysql table; one menu for route types, and one for route numbers. When I choose the route from the 'Route' menu, the 'Number' menu automatically populates with all of the possible numbers, rather than only those that correspond with the route type. I can tell that the problem has something to do with the value of 'Route' not being recognized, but I don't know why. I'm a beginner when it comes to PHP, so any suggestions or help would be much appreciated! Thanks! The code is as follows: Code: [Select] <html> <body> <basefont face='calibri' color='#7E2217'> <?php // set variables $mileTable = $_GET['mileTable']; $routeType = isset($_POST['Roadtype'])? $_POST['Roadtype']: 0; include 'opendbMile.php'; include 'error.php'; // Connect to the MySQL DBMS if (!($connection = @ mysql_connect($hostName, $username, $password))) die("Could not connect"); if (!mysql_select_db($databaseName, $connection)) showerror( ); // Start a query... $query = "SELECT ID, Roadtype FROM Alabama GROUP BY Roadtype"; // execute the SQL statement $result = mysql_query($query, $connection) or die(mysql_error()); echo '<form name="mileform" method="post" action="MileQuery.php">'; echo '<p>Route: <select name="routeType" id="routeType" onchange="this.form.submit();"> <option value="0"'.($routeType == 0? ' SELECTED': '').'>Route</option>'; while($row = mysql_fetch_array($result)){ echo ' <option value="'.$row[0].'"'.(($routeType == $row[0])? ' SELECTED': '').'>'.$row[1].'</option>'; } echo ' </select> </p>'; // create the SQL statement $query2 = "SELECT ID, Roadnumber FROM Alabama GROUP BY Roadnumber"; if($mnucategory != 0){ // Filter road numbers $query2 .= " WHERE Roadtype='".$routeType."'"; } // execute the SQL statement $result2 = mysql_query($query2, $connection) or die(mysql_error()); echo '<p>Number: <select name="routeNumber" id="routeNumber" onchange="this.form.submit();"> <option value="0"'.($routeNumber == 0? ' SELECTED': '').'>Number</option>'; while($row2 = mysql_fetch_array($result2)){ echo ' <option value="', $row2[0].'"'.(($routeNumber == $row2[0])? ' SELECTED': '').'>'. $row2[1], '</option>'; } echo ' </select> </p>'; // Close the DBMS connection mysql_close($connection); ?> </form> </body> </html> The rest of my coding works however this part does not and I'm trying to figure out why. I'm sure my syntax isn't right so I hope someone can correct my mistake. $contentpageID = $_GET['id']; $query = "SELECT contentpages.contentpage, contentpages.shortname, contentpages.contentcode, contentpages.linebreaks, contentpages.backlink, contentpages.showheading, contentpages.visible, contentpages.template_id FROM contentpages WHERE contentpages.id = '" . $contentpageID . "'"; <label for="template">Template</label> <select class="dropdown" name="template" id="template" title="Template"> <option value="0">- Select -</option> <?php $query = 'SELECT * FROM templates'; $result = mysql_query ( $query ); while ( $template_row = mysql_fetch_assoc ( $result ) ) { print "<option value=\"".$template_row['id']."\" "; if($template_row['id'] == $row['template_id']) { print " SELECTED"; } print ">".$template_row['templatename']."</option>\r"; } ?> </select> I want make the following, (I have already a database with three tables (Countries, Timeline and Category)). 1: list of countries (drop down menu 1), Timeline of the countries history (drop down 2) and Category (drop down 3). 2: The selected values of the drop down menus must show take the information from the database. Can any one help me with the coding? how do i this? i have no idea....i need to incorporate it on an html form pleas help? i will get the data from this line and must be able to select one from the dropdown and get the id/name from the one selected [COLOR="Red"]$supplier_names = LpmAdnetworkPeer::getByName($catcher_id);[/COLOR] thank you i'm trying to achive this results layout: example: catagory comment comment comment catagory catagory catagory comment what is being pulled now is if their is 2 comments two 1 catagory then 2 catagorys are being returned with the same id. what i want is to return one cataogry with many comments. thanks in advance for your help. Code: [Select] <?php require_once('Connections/Del_Comments.php'); ?> <?php $all_ids = array(); $str_ids = ""; // first parent query $maxRows_sourceType = 10; $pageNum_sourceType = 0; if (isset($_GET['pageNum_sourceType'])) { $pageNum_sourceType = $_GET['pageNum_sourceType']; } $startRow_sourceType = $pageNum_sourceType * $maxRows_sourceType; mysql_select_db($database_Del_Comments, $Del_Comments); $query_sourceType = "SELECT a.Id, a.Type, a.Dates, a.UIdFk, b.Id as Did, b.comment, b.dates as Day, b.sfk as Sfk , c.sfk as sfk1, d.Memo as memo FROM asstatusupdate as a left join asstatusdata as b on a.id = b.sfk left join asmanystatusupdate as c on b.sfk = c.sfk left join ascomments as d on d.id = c.cfk where a.uidfk='1' order by Dates asc"; $query_limit_sourceType = sprintf("%s LIMIT %d, %d", $query_sourceType, $startRow_sourceType, $maxRows_sourceType); $sourceType = mysql_query($query_limit_sourceType, $Del_Comments) or die(mysql_error()); $row_sourceType = mysql_fetch_assoc($sourceType); if (isset($_GET['totalRows_sourceType'])) { $totalRows_sourceType = $_GET['totalRows_sourceType']; } else { $all_sourceType = mysql_query($query_sourceType); $totalRows_sourceType = mysql_num_rows($all_sourceType); } $totalPages_sourceType = ceil($totalRows_sourceType/$maxRows_sourceType)-1; // add the array while ($row_source = mysql_fetch_assoc($sourceType)) { $all_ids[] = $row_source['Sfk']; $str_ids .= $row_source['Sfk'].','; } // remove the array $str_ids = (substr($str_ids,-1) == ',') ? substr($str_ids, 0, -1) : $str_ids; echo $str_ids; //echo $all_ids; //second child query $maxRows_sourceComments = 10; $pageNum_sourceComments = 0; if (isset($_GET['pageNum_sourceComments'])) { $pageNum_sourceComments = $_GET['pageNum_sourceComments']; } $startRow_sourceComments = $pageNum_sourceComments * $maxRows_sourceComments; mysql_select_db($database_Del_Comments, $Del_Comments); $query_sourceComments = "SELECT c.sfk as sfk1, d.Memo as memo FROM asmanystatusupdate as c left join ascomments as d on d.id = c.cfk where c.uidfk0='1' and c.sfk in ($str_ids)"; $query_limit_sourceComments = sprintf("%s LIMIT %d, %d", $query_sourceComments, $startRow_sourceComments, $maxRows_sourceComments); $sourceComments = mysql_query($query_limit_sourceComments, $Del_Comments) or die(mysql_error()); $row_sourceComments = mysql_fetch_assoc($sourceComments); if (isset($_GET['totalRows_sourceComments'])) { $totalRows_sourceComments = $_GET['totalRows_sourceComments']; } else { $all_sourceComments = mysql_query($query_sourceComments); $totalRows_sourceComments = mysql_num_rows($all_sourceComments); } $totalPages_sourceComments = ceil($totalRows_sourceComments/$maxRows_sourceComments)-1; $resultComments = @mysql_query($query_sourceComments, $Del_Comments); $numComments = @mysql_num_rows($resultComments); $result = @mysql_query($query_sourceType, $Del_Comments); $num = @mysql_num_rows($result); // column count for parent $thumbcols = 1; // column count for parent query $thumbrows = 1+ round($num / $thumbcols); // column count for child query $thumbrowsComments = 1+ round($numComments/$thumbcols); // header print '<br />'; print '<table align="center" width="500" border="3" cellpadding="0" cellspacing="0">'; if (!empty($num)) { print '<tr><td colspan="3" align="center"><strong>Returned Num of Record Sets: ' .$num. ' and comments count' .$numComments. '</strong></td></tr>'; } // table layout for parent query function display_table() { // global variables global $num, $result, $thumbrows, $thumbcols, $resultComments, $numComments, $thumbrowsComments ; // row count for parent for ($r=1; $r<=$thumbrows; $r++) { // print table row print '<tr>'; //format the columns for ($c=1; $c<=$thumbcols; $c++) { print '<td align="center" valign="top">'; $row = @mysql_fetch_array($result); $row1 = @mysql_fetch_array($resultComments); $Id = $row['Id']; $Type = $row['Type']; $Dates = $row['Dates']; $Comment = $row['Comment']; $Sfk1 = $row['sfk1']; $Memo = $row['memo']; // test if not empty show record sets if (!empty($Id)) { // print output from parent query // grab type dates comment and format for there column echo '<td valign="top" align="center">'; echo "$Type"; echo ' '; echo "$Dates"; echo '<br />';echo '<br />';echo '<br />'; echo "$Comment"; echo '</td>'; echo '<td>'; echo "$Id"; echo '</td>'; echo '<td>'; echo "$str_ids"; echo '</td>'; echo '<tr>'; echo '<td>'; echo "$Sfk1"; echo '</td>'; echo '<td>'; echo "$Memo"; echo '</td>'; echo '</tr>'; } // closing the $id loop else { print ' '; } print '</td>'; //closing the table data } //closing the rows print '</tr>'; } // closing the outter loop //} //closing fk id loop print '</td>'; //closing the table data } //closing the rows print '</tr>'; //} // closing the main loop // call the main table display_table() ; print '</table>'; ?> <?php var_dump(substr('a', 1)); // bool(false) ?> I've searched and found numerous examples for creating dynamic forms using PHP and MySQL; however, each seems to be different and I have been unsuccessful with all of them. What I get is an empty pulldown menu instead of the contents from the MySQL table. I've worked this till I'm blue in the face and am now turning to the forums for help. I'm developing/testing code in NetBeans 8.0.2. Here is my code (name of file is 'domains.php': <body> <form method="post" action=""> <select id="domain" name="domain"> <?php // define connection variables $DBServer = "localhost"; // server name or IP address $DBUser = "xxxxxxxxx"; $DBPass = "xxxxxxxxx"; $DBName = "country"; $DBPort = "3306"; // I include the port because I have two instances of MySQL - the other is 3309 // create a connection to mysql $conn = mysqli_connect ($DBServer, $DBUser, $DBPass, $DBName, $DBPort); // check to see if a connection was made and, if yes, proceed if (mysqli_connect_errno()) { // connection failed echo "Database connection failed: " . mysqli_connect_error(); } // the domain query to get all domain names $domainQuery = "select domains from domains_subdomains_cop"; // run the query -- this works elsewhere to display the contents of a table $resultD = mysqli_query($conn, $domainQuery) or die ("Query to get data from domain failed: " . mysql_error()); // with the exception of a pulldown menu, the while loop works well to display all records, etc. // I've seen examples with MYSQLI_ASSOC and without and I've tried both without success - I use it because I // haven't had any issues elsewhere in my program while ($row=mysql_fetch_array($resultD, MYSQLI_ASSOC)) { $domainName=$row[DOMAINS]; // DOMAINS is the table attribute I'm trying to pull echo "<option> $domainName // I accidentely put a ';' here once and that did show up in the pulldown menu </option>"; } ?> </select> </form> </body> In advance, thank you for any help/insight you can provide!!! Nick. How to create Dependent Dropdown List?
<div class="form-group"> <label class="control-label col-sm-2" for="i_have">I have :</label> <div class="col-sm-10"> <select id="old" class="form-control" placeholder="Select I have" name="i_have"> <option value = "select_option">Select Option</option> <option value = "three_compact">3 Compact</option> <option value = "three_regular">3 Regular</option> <option value = "three_triple">3 Triple</option> <option value = "five_compact">5 Compact</option> <option value = "five_regular">5 Regular</option> <option value = "five_triple">5 Triple</option> <option value = "seven_compact">7 Compact</option> <option value = "seven_regular">7 Regular</option> <option value = "seven_triple">7 Triple</option> <option value = "nine_compact">9 Compact</option> <option value = "nine_regular">9 Regular</option> <option value = "nine_triple">9 Triple</option> </select> </div> </div> <div class="form-group"> <label class="control-label col-sm-2" for="i_want">I want :</label> <div class="col-sm-10"> <select id="new" class="form-control" placeholder="Select I want" name="i_want"> <option value = "select_option">Select Option</option> <option value = "three_compact">3 Compact</option> <option value = "three_regular">3 Regular</option> <option value = "three_triple">3 Triple</option> <option value = "five_compact">5 Compact</option> <option value = "five_regular">5 Regular</option> <option value = "five_triple">5 Triple</option> <option value = "seven_compact">7 Compact</option> <option value = "seven_regular">7 Regular</option> <option value = "seven_triple">7 Triple</option> <option value = "nine_compact">9 Compact</option> <option value = "nine_regular">9 Regular</option> <option value = "nine_triple">9 Triple</option> </select> </div> </div>
If the first dropdown "3 Compact " is selected second dropdown should not be able to select "3 Compact" & if first dropdown "5 Regular" is selected second dropdown should not be able to select below values of 5 Regular like "3 Compact, 3 Regular, 3 Triple, 5 Compact. The logic is, if first dropdown value selects like 5, second dropdown value must select above 5 not 4 or 3 or 2 or 1. I'm attempting to create a dropdown hover menu by following the instructions on the Suckerfish site. The list that is supposed to dropdown simply stays visible all the time. Is there anything in the code that seems to be the apparent cause of the problem? You will be able to tell that I'm new to PHP. Any suggestions would be appreciated. The following is my CSS and PHP code: CSS: Code: [Select] #nav, #nav ul{ padding: 0; margin: 0; list-style: none; } #nav a{ display: block; width: 10em; } #nav li{ float: left; width: 10em; } #nav li ul{ position: absolute; width: 10em; left: -999em; } #nav li: hover ul{ left: auto; } #nav li:hover ul, #nav li.sfhover ul{ left: auto; } PHP/JavaScript: Code: [Select] function draw_app_menu() { // draw the application menu ?> <!-- left - background-color: #cdeb8b - lime --> [color=blue]<script type="text/javascript"> shHover = function() { var sfEls = document.getElementByID("nav").getElementsByTagName("LI"); for (var i=0; i<sfEls.length;i++) { sfEls[i].onmouseover=function() { this.className+=" sfhover"; } sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); } } } if (window.attachEvent) window.attachEvent("onload",sfhover); </script>[/color] [color=green]<ul id = "nav">[/color] <?php session_start(); if (isset($_SESSION['selected_app'])) { // echo '<p> selected_app was set </p>'; foreach ($_SESSION['application_list'] as $app_list) { if (($app_list[5] == 'A') && ($app_list[0] == $_SESSION['selected_app'])) { $_SESSION['current_link'] = $app_list[2]; } if (($app_list[0] == $_SESSION['selected_app']) && (($app_list[5] == 'M') || ($app_list[5] == 'S'))) { if ($app_list[5] == 'M') { ?> [color=green]<li><a href="<?php echo $_SESSION['current_link'].'?id='.$_SESSION['selected_app'].'&modid='.$app_list[3].'&func='.$app_list[6];?>"><?php echo $app_list[1];?></a></li>[/color] <?php $_SESSION['selected_mod'] = $_GET['modid']; $_SESSION['app_function'] = $_GET['func']; } ?> [color=green] <ul>[/color] <?php if ($app_list[5] == 'S') { ?> [color=green]<li><a href="<?php echo $_SESSION['current_link'].'?id='.$_SESSION['selected_app'].'&modid='.$app_list[3].'&submodid='.$app_list[4].'&func='.$app_list[6];?>"><?php echo $app_list[1];?></a></li>[/color] <?php $_SESSION['selected_mod'] = $_GET['modid']; $_SESSION['selected_submod'] = $_GET['submodid']; $_SESSION['app_function'] = $_GET['func']; } ?> [color=green]</ul> </li>[/color] <?php } } } ?> [color=green]</ul>[/color] <script src="sfhover.js" type="text/javascript"></script> <?php } Hi guyz, I am looking to create a dymanic comment box for my website where already logged in users can comment on webpages. It is quite a challenge getting to dynamically display only the comments a particular user posted on a web page. What I mean is I would like to be able to click on a page, see only the comments logged users posted on that page, and then post my own comment on that page. At the moment I created a comment box for my webpages but the issue is my posted comments on one particular page is displaying on all web pages with is comment system..This is the problem and it is very difficult to find helpful material hopefully you guyz can come to the rescue. Please guys any help or suggestions are more than welcome. Thanks Kdiamonds Hi, I am hoping someone can help me out with a slight issue I have with php and mySQL. I have an ajax-powered form with a select (dropdown) field populated through a php function. Based on the user-selected values in this field, data is displayed on the webpage; i.e. selected value 1 returns values x and y on the page. I am now trying to call additional data (value z) from a different table in the same database, and as before, use the selected values from the dropdown to display the data. For some reason, value z is not changing according to the user-selected value. This is my code: [The function to populate the select field] Code: [Select] function kfl_get_funds_names() { $result = array(); $result['CDF'] = 'Crosby Dragon Fund'; $result['CPF'] = 'Crosby Phoenix Fund'; $result['AMZPIF'] = 'AMZ Plus Income Fund'; $result['KASBIIF'] = 'KASB Islamic Income Opportunity'; $result['KASBCPGF'] = 'KASB Capital Protected Gold Fund'; $result['KASBLF'] = 'KASB Income Opportunity Fund'; $result['KASBCF'] = 'KASB Cash Fund'; $result['KASBBF'] = 'KASB Asset Allocation Fund'; $result['KASBSMF'] = 'KASB Stock Market Fund'; return $result; } [the code calling and using the function to interact with the database] Code: [Select] $funds_to_display = kfl_get_funds_names(); $current_symbol = key( $funds_to_display ); $current_nav_rates = kfl_get_latest_rates( $current_symbol ); [the code calling additional data, value z, from the database, and using the info in the select field to filter it] Code: [Select] $cutoff = kfl_cutoff( $current_symbol ); The display of each of these items is as follows: Code: [Select] <?php echo $current_nav_rates['nav_date']; ?> <?php echo $funds_to_display[$current_symbol]; ?> <?php echo $cutoff['cutoff']; ?> I can't get the $cutoff code to display the correct values. It picks up the first symbol to display and doesn't change with user selection. The code for the selection box, by the way: Code: [Select] <select id="dailynav-funds" autocomplete="off" name="dnf"> <?php foreach ($funds_to_display as $fund_symbol => $fund_name) { echo '<option'; if( $fund_symbol == $current_symbol ) { echo ' selected="selected"'; } echo ' value="' . $fund_symbol . '">'; echo $fund_name; echo '</option>'; } ?> </select> I've tried to get data using $_GET['dnf'] into the cutoff code, but that throws up parse errors. What am I doing wrong, and how can I resolve this issue? Thanks in advance! I have the following code which works (thanks to PHP Freaks members)
foreach ($swap["sims"] as $swap) { echo $swap['voice'] . "</br>"; }But I can't figure out why the following doesn't work <select name="sim_for_swap[]"> <?php foreach ($swap["sims"] as $swap) { ?> <option value="<?php echo $swap['voice'];?>"><?php echo $swap['voice'];?></option> <?php } ?> |