PHP - Problem With Listbox And Sort Variable
Similar Tutorials<?php /* Define the Transact-SQL query. Use question marks (?) in place of the parameters to be passed to the stored procedure */ $tsqlNavDiv_callSP = "{call sp_services_content_navigation_module( ?, ?, ?, ?, ?, ?, ?, ?, ?)}"; /* Define the parameter array. By default, the first parameter is an INPUT parameter. The second parameter is specified as an OUTPUT parameter. To ensure data type integrity, output parameters should be initialized before calling the stored procedure, or the desired PHPTYPE should be specified in the $params array.*/ $opt_out_eap = $_SESSION['id_eap']; $opt_out_company = $_SESSION['id_company']; $content_languages_list = $_SESSION['id_language']; $publish = 'public'; $id_eap = $_SESSION['id_eap']; $today=(date("Y-m-d")); $total=''; $id_module=''; $paramsNavDiv = array( array($opt_out_eap, SQLSRV_PARAM_IN), array($opt_out_company, SQLSRV_PARAM_IN), array($content_languages_list, SQLSRV_PARAM_IN), array($publish, SQLSRV_PARAM_IN), array($id_eap, SQLSRV_PARAM_IN), array($today, SQLSRV_PARAM_IN), array($id_division, SQLSRV_PARAM_INOUT), array($total, SQLSRV_PARAM_OUT), array($id_module, SQLSRV_PARAM_OUT) ); /* Execute the query. */ $stmtNavDiv = sqlsrv_query( $conn, $tsqlNavDiv_callSP, $paramsNavDiv); if( $stmtNavDiv === false ) {echo "Error in executing statement 3.\n"; die( print_r( sqlsrv_errors(), true));} $i='120'; $i <= '141'; while ($obj=sqlsrv_fetch_object($stmtNavDiv)) { // SET PARAMETERS $total= $obj->total; $id_division= $obj->id_division; $id_module= $obj->id_module; $i++; if ($total > 0) { echo "<li><a href=\"".$_SESSION['pwfurl']."/p_module.php?id_division=".$id_division_menu."&id_module=m".$id_module."\">".$_SESSION['m'.$id_module]."</a></li>"; } } /*Free the statement and connection resources. */ sqlsrv_free_stmt( $stmtNavDiv); ?>I pull a menu back in my website that has an id number (300, 305, 302, 303, 304, 301, 306) -This number is stored in SQL. Each of the menu numbers is associated with a slot number (121, 122, 123, 124, 125, 126, 127) These are not in SQL. Right now, my stored procedure is ordering by the id number instead of the slot number. So my question is, once I pull back my records, can I re-order the array by my PHP slot numbers? Hi,
I need help in populating data from DB in the 2nd listbox depending on 1st listbox data (where the data of 1st listbox is also fetched from DB), in the same form.
Thanks,
Jessentha
optionsT Does not show any results.Dont know where is the problem.
<script type="text/javascript" language="javascript"> function AddItemInList(fromLeftToRight, isAll){ var list1 = document.getElementById('listBoxF'); var list2 = document.getElementById('listBoxT'); if(Boolean(fromLeftToRight) == true){ MoveItems(list1,list2,isAll); }else{ MoveItems(list2,list1,isAll); } return false; } function MoveItems(listFrom, listTo, isAll){ var toBeRemoved = ""; if(listFrom.options.length > 0){ for (i=0; i<listFrom.length; i++){ if (listFrom.options[i].selected || (isAll == true)){ if(Exist(listTo, listFrom.options[i].value) == 0){ listTo[listTo.length] = new Option(listFrom.options[i].text, listFrom.options[i].value, true); toBeRemoved = toBeRemoved + listFrom.options[i].value + ';'; } } } ClearSelection(listTo); RemoveFromList(listFrom, toBeRemoved); }else{ alert('Unable to Move Items. List is Empty!'); } } function RemoveFromList(listFrom, items){ var toBeRemoved = items.split(';'); for (var i=0; i < toBeRemoved.length; i++){ for (var j = 0; j < listFrom.length; j++){ if (listFrom.options[j] != null && listFrom.options[j].value == toBeRemoved[i]){ listFrom.options[j] = null; } } } } function ClearSelection(list){ list.selectedIndex = -1; } function Exist(list, value){ var flag = 0; for (var i=0; i < list.length; i++){ if (list.options[i].value == value){ flag = 1; break; } } return flag; } </script> <?php $opt = isset($_POST['optionsT']) ? $_POST['optionsT'] : ''; if(!empty($_POST['submit'])){ print $opt; } print" <form method=\"POST\"> <table style=\"width:100%\"> <tr valign=\"top\"> <td>Options</td> <td> <select multiple size=\"5\" name=\"optionsF\" id=\"listBoxF\" style=\"width:350px\"> <option value=\"1\">1</option> <option value=\"2\">2</option> <option value=\"3\">3</option> <option value=\"4\">4</option> </select> <div align=\"center\"> <input type=\"button\" onclick=\"return AddItemInList(true,true)\" value=\"+ All\"> <input type=\"button\" onclick=\"return AddItemInList(true,false)\" value=\"+\"> <input type=\"button\" onclick=\"return AddItemInList(false,false)\" value=\"-\"> <input type=\"button\" onclick=\"return AddItemInList(false,true)\" value=\"- All\"> </div> <select multiple size=\"5\" name=\"optionsT[]\" id=\"listBoxT\" style=\"width:350px\"> </select> </td> </tr> <tr> <td></td> <td><input type=\"submit\" name=\"submit\" value=\"Submit\"></td> </tr> </table> </form>"; ?> Say I have this array: Code: [Select] array( 0 => time 1 => time 2 => to 3 => to 4 => to 5 => fly ); and 2 variables - $occMin and $occMax as number of occurrences. If: Code: [Select] $occMin = 2; $occMax = 3; I want to produce sorted list with most occurrences at the top: Code: [Select] array( 0 => array('to', 3), 1 => array('time', 2) ); My face just melted at the thought of even beginning to tackle this. Is this somewhat possible? would it require a monster function or am I missing some native php functions which could lend a hand? Hi All i am wanting a column list like this http://extensions.joomla.org/extensions basically the database is set up as (id, category, parent) I want the parent to group the category section and list like the the joomla example in three columns search various threads throughout the internet but none seem to cover this entirely can any one please help????? Hi, I've done a search and cant find anything related to my problem. I have a newsfeed on my site and i want it to display with the latest news at the top. I have this code: Code: [Select] $get_news = "SELECT title, text, DATE_FORMAT(datetime, '%e %b %Y at %T') AS datetime FROM newsfeed ORDER BY datetime DESC"; This works fine on one of my sites but on another i've just hit a problem. It seems to sort only by the day, not the rest of the date. I made a news post today with date and time of "27 Mar 2011 at 12:54:02" but a post from "28 Jan 2011 at 19:59:52" is above it. Any ideas why this is happening? Thanks, Alex Ok i'm trying to make a dropdown menu to sort content on my site. The dropdown looks like this: Code: [Select] <select> <option selected="selected">Date</option> <option>Clicks</option> <option>Ratings</option> <option>Comments</option> </select> The content that the dropdown needs to sort are taken from my MySQL database and put on the site using these lines of code: (there is alot more code to do other stuff aswell, but that isn't importand for my problem) $sql = "SELECT * FROM links LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $dyn_table = '<table class="main_table">'; while ($row = mysql_fetch_assoc($result)) { etc... The dropdown and the php script that inserts the content on the page are (and needs to be) in two seperate files. So how can i make so that when a user selects "Sort by: Clicks" for example, the page refresh and maybe inserts "ORDER BY clicks ASC" into "$sql = "SELECT * FROM links LIMIT $offset, $rowsperpage";"or something?? I'm really open for ideas here, Javascript and jQuery is also welcome if it needs to be used! Hi! every body. This is my first post in this form. Hope u people will help me. I'm using PHP 5.3. I've the following listboxes. From "emp_list" i've double click the value, which goes to "sel_list". I'm selecting multiple values. How can i get these values on the target page using PHP. <html><head> <script language="javascript"> function moveItem( box1, box2 ){ for ( var i=0; i < box1.options.length; i++ ){ if ( ( box1.options.selected == true ) ){ strItemToAdd = box1.options.text; box2.options[box2.length] = new Option(strItemToAdd); box1.options = null; i--; } } } </script> </head><body> <form id="project" name="project" action="" method="POST"> <select id='emp_list' name='emp_list' size='5' STYLE="width:170;" multiple onDblclick="moveItem( project.emp_list, project.sel_list)"> <option value='a1'>a1</option> <option value='a2'>a2</option> <option value='a3'>a3</option> </select> <select id='sel_list' name='sel_list' size='5' STYLE="width:170;" multiple onDblclick="moveItem(project.sel_list, project.emp_list )"> </select> <input type='submit' name='submit' value='submit'> </form> </body></html> Hi guys, I have a list box. say the code is Code: [Select] <select name="drop1" id="Select1" size="4" multiple="multiple"> <option value="1">item 1</option> <option value="2">item 2</option> <option value="3">item 3</option> <option value="4">item 4</option> <option value="0">All</option> </select> The user will select few items. How do i capture the data through the "POST" method. Code: [Select] $data = $_POST['drop']; would not work coz there is an array if data. Can any one help or point me in the right direction? Thanks in advance Hi, Im starting to write a simple (so I thought! ) project at work, I have no problems with the HTML, CSS or even the php mysql setup, but I am struggling with a simple piece of code! I have a list box, that populates from a table column using the following code: Code: [Select] <?php function select(){ $query="SELECT appname FROM kpe_apps"; $result = mysql_query($query); echo '<select name="item" onchange="this.form.submit()">'; while($nt=mysql_fetch_array($result)){ echo '<option value="' . $nt['id'] . '">' . $nt['appname'] . '</option>'; } echo '</select>'; } ?> I then called the function on the page I needed. which works fine, now all I need is whatever is selected in the listbox other columns in the same table relating to the selected item are seen. I just cant seem to do it, loads of people are using jquery and other code, surely this can be done in php? any help would really be appreciated.. Many Thanks MOD EDIT: code tags fixed, linefeeds and indenting added. Hello, I'm using PHP and I have a list box where I should be able to select multiple values, that I then submit to run multiple reports. However, when I select two values I only get results for the last selected value instead of both value a & value b. Can anyone help me with my problem? Code: [Select] <td style="text-align: right">Job Type:</td> <td> <select name="job_type" multiple="multiple" size="4"> <option value="0" selected>ALL</option> {section name=jt loop=$job_type_list} <option value="{$job_type_list[jt][0]}">{$job_type_list[jt][1]}</option> {/section} </select> </td> I've read that I can change name="job_type" to name="job_type[]", but I'm not getting any luck with that... <script type="text/javascript"> function listBoxSearch(){ var input = document.getElementById('searchBox'), output = document.getElementById('listBoxF'); if(input.value != ''){ for (var i = 0; i < output.options.length; i++){ if(output.options[i].text.substring(0, input.value.length).toUpperCase() == input.value.toUpperCase()){ output.options[output.options.length] = new Option(output.options[i].innerHTML, output.options[i].text); } } if (output.options.length == 1) { output.selectedIndex = 0; } } } </script>It dosen`t work. It should work like this[DEMO in attached filed] Attached Files listbox_with_keybord_search.htm 7.9KB 3 downloads needing some help on this, i have a form with a dynamic listbox and and textfields, what i need to do is when i select item from listbox i need it to fetch the data from DB and fill out rest of fields in form. i 'm using dreamweaver and can post code if required kenny Hi all, I have a listbox on a form that gets it's data from a MySQL query, all of which is working fine. I make a selection in my listbox and then submit the form which is reloading itself. However on the reload I would like the listbox to display the selection made by the user, instead it reverts to the first item in the list. I have included the code, if someone could point me in the right direction that would be great. I have searched these forums and tried a few things that are suggested but I still can't get it to work. Code: [Select] <?php include("dbconn.php"); $query = "SELECT location.location_name, printer.model_number, location_printer.serial_number" . " FROM location, printer, location_printer" . " WHERE location.location_id = location_printer.location_id" . " AND printer.printer_id = location_printer.printer_id"; $result = mysql_query($query); echo "<table>"; echo "<th>Location</th>"; echo "<th>Printer</th>"; echo "<th>Serial No</th>"; while(($row = mysql_fetch_array($result))) { echo "<tr>"; echo "<td>".$row['location_name']."</td>"; echo "<td>".$row['model_number']."</td>"; echo "<td>".$row['serial_number']."</td>"; echo "</tr>"; } echo "</table>"; if(isset($_POST['location'])) { $loc = $_POST['location']; echo "<p>Location = <b> $loc </b>"; } ?> <html> <head> <title>Loop Results</title> </head> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" > <table> <tr> <td> <?php $query = "SELECT * FROM location ORDER BY location_name"; $result = mysql_query($query); $default = $_POST['location']; echo "<p>Location: "; echo "<select name='location'>"; while(($row = mysql_fetch_array($result))) { echo "<option value='{$row['location_id']}"; //Selected value if($row['location_id'] == $default) echo " selected "; echo "'>{$row['location_name']}</option>\n"; } echo "</select>"; ?> </td> </tr> <tr> <td> <input type="submit" /> </td> </tr> </table> </form> </body> </html> Hi everyone,
I'm a complete newbie here. I've looked around for help and tried a few solutions without success, so because time is short I'm asking for help.
I have a registration form which includes address details. The form holds a country field which is a listbox, the values being selected from a MySQL table. How do I assign the selected country option to a field list in the insert statement?
Here's what I have so far:
Registration page form:
<div class="form-group"> Hi, I'm coding a page that starts with a select list loaded from a database and I want to make a different query depending on the item selected, I have been searching around and I can't find a php version of the selectedIndex of a listbox in javascript, any idea? thanks.
I'm coding a google map script in php/javascript, and I'm having a hell of a time with the address. It seems to not like any spaces for what I can tell (and I'm no php programmer). Code: [Select] /* Create an array of address values */ addresses = [ <?php for($i=0; $i < count($dataArray); $i++) { $p = $dataArray[$i]; $p = explode(":", $p); $addr = $p[4]; echo "$addr,\n"; } ?> ]; Here is data file (just one line for testing): 1315414069:41.100908:-81.442699:33:150 North Ave Tallmadge OH:1 Here is "view source" from browser: /* Create an array of address values */ addresses = [ 150 North Ave Tallmadge OH, ]; I'm stumped The map will not display with this. If I change the $addr to another variable in the array, it works fine. Trying to put the address in an info window on the map. TIA, Roots Hi guys, I have a bit of a problem, Im using php and mysql and have succeded in storing variables inside of a URL: echo "<a href='report.php?id=$varmemberid&colour=$varcolour'>test</a> "; i retrieve varmemberid and colour from the mysql database: $tbl_name = "members"; mysql_select_db($db_name) or die (mysql_error()); $query="SELECT * FROM $db_name ORDER BY `members`.`the_members` ASC"; $result=mysql_query($query); $num=mysql_numrows($result); $i=0; while ($i < $num) { $varmemberid=mysql_result($result,$i,"member_id"); $varcolour=mysql_result($result,$i,"colour"); that works all fine and dandy for numbers eg: "123" however if i go to insert a member id of "123t" i get this error: Code: [Select] Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 12 in /home/flashx/public_html/login/report-header.php on line 47 im guessing it has something to do with the 'int' in this line: $memberid = (int) $_GET['memberid']; how do i fix this? Cheers So. I wrote this class that redirects a user to a new url: Code: [Select] <?php class PotentGate{ private $endURL, $sourceURL = 'http'; private function Gate_setURL(){ //THE BLOCK BELOW WIL ULTIMATELY REFERECE A DATABASE BACKEND FOR DESTINATION URLS. if ($this->sourceURL=="http://blah.com/blah/misc.php"){$this->endURL="http://blah.com/blah/misc2.php?r=" . $this->Gate_sourceURL;} else {} } public function Gate_getURL(){ $this->Gate_sourceURL(); echo $this->sourceURL . "<br />"; $this->Gate_setURL(); //set our destination URL based on source echo $this->endURL . "<br />"; return header('Location:' . $this->endURL); //redirect } private function Gate_sourceURL() { //TODO: Fix the $_SERVER['HTTPS'] below for https:// support. //if ($_SERVER['HTTPS'] == "on") {$this->sourceURL .= "s";} $this->sourceURL .= "://"; if ($_SERVER['SERVER_PORT'] != "80") { $this->sourceURL .= $_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI']; } else { $this->sourceURL .= $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; } return $this->sourceURL; } }//end It is implemented as such: Code: [Select] <?php include("PotentGate.php"); $gate = new PotentGate(); $gate->Gate_getURL(); //IGNORE //function below will acquire get variable //echo "You came from:" . $gate->Gate_getReferrer(); ?> This works all well and good, as far as redirection goes, but refuses to add the $Gate_sourceURL to the end url. I am left with a url like: http://blah.com/blah/misc2.php?r= and what I am trying to achieve is that it assign $Gate_sourceURL to r (so I can use the source url as a value later on), as opposed to be being blank. ex. http://blah.com/blah/misc2.php?r=http://blah.com/blah/misc1.php Any Ideas? |