PHP - Select Dropdown Box Function
Ive tried to create a function to create a dropdown select box but im getting alot of errors to do with the if statement saying the ($_POST[$name]) value is not set???
function selectBox($name, $firstvalue, $limit, $increment) { // echo "<br>"; // echo $name; // echo "<br>"; // print_r($_POST[$name]); // echo "<br>"; $select ="selected=\"selected\""; $body = "<select name='$name' id='$name' method='POST'> <option value=''>$name</option>"; for ($value = $firstvalue; $value <= $limit; $value += $increment) { $body .= "<option value= '$value' "; if ($_POST["$name"] === $value) { $body .= $select; } $body .= ">$value</option>"; } $body .= "</select>"; // echo $value; // echo $_POST[$name]; // echo $_POST['Width']; return $body; } Any help would be greatly appreciated Similar TutorialsI have the following code currently: Code: [Select] <?php foreach ((array)$node->field_buy_at as $item) { ?> <?php print $item['view'] ?> <?php } ?> I would like to make the list a drop down with a link so that when a user selects, he goes to a new page. I tried the following: Code: [Select] <select name="select"> <?php foreach ((array)$node->field_buy_at as $item) { ?> <?php $url = $node->field_buy_at[0]['url']; $store = $item['view']; ?> <? echo "<option value='$url'>$store</option>";?> <?php } ?> </select> I'm pretty sure it's this "$url = $node->field_buy_at[0]['url'];" that I don't have correct. Hi I'm trying to create a form where people first select the number of children they have, and then a table should appear where they fill in the extra information (name, sex, dob) about every child. The code works except for that i don't know how to add the year of the date of birth of every child with a loop. Appartly i cannot use php in javascript? Any solutions? thanks! Code: [Select] function addKindForms(aantal) { if (aantal != "-") { var output = ""; output = output + "<table cellpadding='2' cellspacing='0'>"; output = output + "<tr><td><b>Naam:</b></td><td><b>Geslacht:</b></td><td><b>Geboortedatum:</b></td><td></td><td></td></tr>"; for(i=1;i<=aantal;i++) { output = output + "<tr><td><input type='text' name='kind"+i+"_name' size='15' value=''></td><td><select name='kind"+i+"_sex'><option value='m'>jongen</option><option value='f'>meisje</option></select></td><td><select name='kind"+i+"_gebdatumdag'><option value=''></option><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'> 8</option><option value='9'>9</option><option value='10'>10</option> <option value='11'> 11</option><option value='12'>12</option><option value='13'>13</option><option value='14'>14</option><option value='15'>15</option><option value='16'>16</option><option value='17'>17</option><option value='18'>18</option><option value='19'>19</option><option value='20'>20</option><option value='21'>21</option><option value='22'>22</option></select></td><td><select name='kind'+i+'_gebdatummaand'><option value=''></option><option value='1'>jan</option><option value='2'>feb</option></select></td><td><select name='kind'+i+'_gebdatumjaar'><option value=''></option><?php for ($y=date('Y');$y>=(date('Y')-125);$y--){if($_POST['bdaykind_jaar']==$y){$selected='selected';}echo'<option value=''.$y.'' '.$selected.'>'.$y.'</option>';$selected = '';}?></select></td></tr>"; } output = output + "</table>"; document.getElementById("kindforms").innerHTML = output; } } Hey guys, I am wanting to select a dropdown value based on the value of 'level' in the row of the user select by a $_GET. It will house the ranks of the user. Here is my script. RANK <?php mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("chat"); $result = mysql_query("SELECT * FROM users WHERE user_id = '$_GET[id]'"); $row = mysql_num_rows($result); ?> <form id="main_form" name="main_form" method="post" action=""> <select name="rank"> <option value="0" <?php if($row['level']=="0") { echo "selected"; }?>>Unactivated</option> <option value="1" <?php if($row['level']=="1") { echo "selected"; }?>>Banned</option> <option value="2" <?php if($row['level']=="2") { echo "selected"; }?>>Regular User</option> <option value="3" <?php if($row['level']=="3") { echo "selected"; }?>>Donator</option> <option value="4" <?php if($row['level']=="4") { echo "selected"; }?>>Moderator</option> <option value="5" <?php if($row['level']=="5") { echo "selected"; }?>>Administrator</option> <option value="6" <?php if($row['level']=="6") { echo "selected"; }?>>Owner</option> </select> <input type="submit" id="main_submit" name="main_submit" value="submit" /> </form> It is not selecting for some reason at all. Can someone tell me what I am doing wrong? I'm trying to pull up an identical form after submission by using its "id" and ECHO for the form lines. Question: What is the correct approach for ECHOing an HTML dropdown that is written as: <select name='chixcutlet' value='' > <option value='0.00' selected> --- </option> <option value='1.00'> 1 </option> <option value='2.00'> 2 </option> <option value='3.00'> 3 </option> </select> I want it to get the info from the database so that the option that is saved in the database will be new default when the page is loaded. If I don't change it to the previous info it will update the database with the default option rather then the actual option. I'm trying to figure out why the options aren't appearing inside the select dropdown. Any ideas why? Code: [Select] echo "<label for=" . $row2['fullName'] . ">" . $row2['fullName'] . "</label>"; echo "<select name=" . $row2['fullName'] . " id=" . $row2['fullName'] . " class=dropdown title=" . $row2['fullName'] . " />"; if ($styleID == 1 || $styleID == 2 || $styleID == 6) { $charactersQuery = " SELECT characters.ID, characters.characterName FROM characters WHERE characters.styleID = 3 ORDER BY characters.characterName"; $charactersResult = mysqli_query ( $dbc, $charactersQuery ); // Run The Query while ( $row3 = mysqli_fetch_array ( $charactersResult, MYSQL_ASSOC ) ) { print "<option value=" . $row3['ID'] . ">" . $row3['characterName'] . "</option>\r"; } } else { $charactersQuery = " SELECT characters.ID, characters.characterName FROM characters WHERE characters.styleID IN (1,2,6) ORDER BY characters.characterName"; $charactersResult = mysqli_query ( $dbc, $charactersQuery ); // Run The Query while ( $row3 = mysqli_fetch_array ( $charactersResult, MYSQL_ASSOC ) ) { print "<option value=" . $row3['ID'] . ">" . $row3['characterName'] . "</option>\r"; } } echo "</select>"; } Hi, I am doing an EDIT user page and would like to check records with a dropdown and then set as selected, please help! <select name="BrokerID" class="small-input"> <option value="Please select an option">Please select a Broker</option> <?php while($row2 = mysql_fetch_array($broker)) { echo '<option name="BrokerID" value="'.$row2['BrokerID'].'">'.$row2['BrokerName'].'</option>'; } ?> </select> Hi, I have a search form where users can search by age and country. Users can also save their search so they can go back and do it again but the problem is when they reload their saved search, I need it to select the country that has been saved in the drop down. So if someone searched the United Kingdom, I need it to show United Kingdom in the select drop down instead of (Select Country). Is there any easy and quick way around this? Many Thanks Hi, I'm a php newbie, with some mysql experience. I have a mysql database as follows: Database=watch, Table=events - fields id, reportno, sdate, comments What I need is: 1. A dropdown list to display reportno from mysql database. 2. Depending on which reportno I choose, I'd like to open a popup(or separate) page to display the stored information. Tks in advance for any help I am designing my own framework, and I have created a select function. I have set a parameter to be an array by default, with the default value of *. When I check if it's an array (with is_array) it says that it isn't. Does anyone have any idea why it would say that? Code: [Select] function select($table, $rows = array('*'), $cond = "") { $query = "SELECT {$rows} FROM `{$table}`"; if (isset($cond)) { $query .= " WHERE {$cond}"; } if (is_array($rows)) { if (isset($rows) && $rows != "*") { foreach ($rows as $v) { print_r($v); } } } //return mysql_query($query); } Any help is appreciated. Thanks. hy I want to make a select in a class: Code: [Select] class test { var $unu = array(); function __construct(){ $link = mysql_connect("", "", "") or die("Couldn't make connection."); $db = mysql_select_db("", $link) or die("Couldn't select database"); //$this->unu = $textin; } function show($col){ $q = mysql_query("SELECT $col FROM categorie"); $qw = mysql_fetch_array($q); $this->unu = $qw; return $this->unu; } } If I want to show how many rows are in that table: Code: [Select] $box = new test(); echo count($box->show("titlu")); it show me that are only 2, although in "categorie" table are 10 rows. Can you please tell me where is the error ? Thanks When i use this code it show everything except for the first record in the table. I have also tried it with the users for the login system im using and then it doesnt show the person im logged in to or also the first record in the table and i need it too show all the records How do i solve this? I thought it had something to do with: Code: [Select] <?php while ($rij = mysql_fetch_array($result)){ echo ("<tr><td>". $rij['ID'] . " </td> " . "<td>" . $rij['naam'] . " " . $rij['telefoon'] . " </td> " . "<td>" . $rij['adres'] . " </td> " . "<td>" . $rij['mobiel`'] . " </td>". "</td></tr>\n "); } ?> But i dont know how to solve it. Code: [Select] <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("root123", $con); $sql= "SELECT * FROM root123 ORDER BY ID;"; $result = mysql_query($sql, $con); $rij = mysql_fetch_array($result); ?> <table width="80%" align="center"> <tr> <th>ID</th> <th width="150px">Naam</th> <th>Gebruikersnaam</th> <th width="300px">Wachtwoord</th> </tr> <?php while ($rij = mysql_fetch_array($result)){ echo ("<tr><td>". $rij['ID'] . " </td> " . "<td>" . $rij['naam'] . " " . $rij['telefoon'] . " </td> " . "<td>" . $rij['adres'] . " </td> " . "<td>" . $rij['mobiel`'] . " </td>". "</td></tr>\n "); } ?> </table> Hi, I'm an novice/intermediate PHP prgogrammer, so excuse me if this is a stupid question. I have one php program that consist of a few functions. Inside the function taht is the starting point I pickup a few entries from a MYSQL database, and display those in my html page. I wish to dynamically put a link on those entries that makes it possible for the users to click those entries an get directed to other functions inside this very same PHP program WITH a parameter. The parameters that should accompany the url/link into the selected function to be able to select apropriate records from the mysql tables. Any hints and tips for this would be highly appreciated! Kind Regsrds, Terje Hvidsten. I have a DB It gets records from a sensor every 5 min This is then displayed on a Chart When I request 4 Hrs I get 48 records x 12 Sensors, Not a issue When I request 12 Hrs I get 144 records x 12 Sensors, A little Slower but Still OK But as I start to request longer periods Like 7 Days I start getting larger and Larger data sets causing time out issues with the AJAX Calls (4-30MB per sensor downloads of data) When looking at 4 weeks I really cant see the fine detail so is there a way to request records from MYSQL that drops some records in between Kinda like the Step function in a For loop If I request a period that has 2048 records but only want 204 records is there a way to say give me From -> To dates Step 10 and only return every 10th Record in the data set Thanks I am currently using a javascript to redirect the page using a select tag and the onchange property. Each page calls a different function. I want to be able to pass the <select> value to a variable that I can use within a php condition statement on the same page. This will generate the required output based on the <select> value. This way I dont require a seperate page for each query. So onchange.... $select_value == this.value? Then within my page: Code: [Select] if ($select_value == 'alpha') { get_query_alpha(); } if ($select_value == 'bravo') { get_query_bravo(); } This is my current set up... Code: [Select] <p>Order by: <select name="query" id="query" onchange="gotourl(this.value)"> <option value="query1.php" >Sort by A</option> <option value="query2.php" >Sort by B</option> <option value="query3.php" >Sort by C</option> <option value="query4.php" >Sort by D</option> </select></p> <table> <?php get_query_1();?> </table> and js... Code: [Select] function gotourl(url){ window.location= url; } function selectsubject(){ alert("Please select a subject!"); } Is there a simple way to do this? Thanks. Hi, I am making a login page which consists of 2 pages, index.php and config.php Following is a code of config.php Code: [Select] <?php define("HOST", "localhost"); define("USER", "aaaabbbccc"); define("PASS", "aaabbbccc"); define("DATABASE", "pricetagindia"); $connection = @mysql_connect(HOST, USER, PASS); $select_db = @mysql_select_db(DATABASE, $connection); if(!$connection) { echo "<h1>Cannot connect to database</h1>"; exit(0); } if(!$select_db) { echo "<h1>Cannot select database</h1>"; exit(1); } ?> Here is a coding of index.php Code: [Select] <?php include('config.php'); $_error = "<p></p>"; if (isset($_POST['username']) || isset($_POST['password'])) { $username = $_POST['username']; $password = $_POST['password']; if($username == NULL || $password == NULL) { $_error = "<p>Username and Password, both fields are required.</p>"; } else { // Check in DB $password = md5($password); $checkuser_query = "SELECT * FROM users WHERE username = '$username.' AND password = '$password'"; $checkuser_result = mysql_query($checkuser_query); $checkuser_count = mysql_num_rows($checkuser_result); if($checkuser_count == 1) { echo "match found"; } else { echo "nothing found error, username was ".$username." and pass is ".$password; echo "<p></p>"; echo $checkuser_result; } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Price Tag India</title> </head> <body> <center> <h1>Price Tag India</h1> <p> </p> </center> <center> <form action="index.php" method="post" target=""> <table width="389" height="168" border="0"> <tr> <td width="141">Username :</td> <td colspan="2"><label for="username"></label> <input type="text" name="username" id="username" /></td> </tr> <tr> <td>Password :</td> <td colspan="2"><label for="password"></label> <input type="password" name="password" id="password" /></td> </tr> <tr> <td> </td> <td width="56"><input type="submit" name="button" id="button" value="Submit" /></td> <td width="223"><input type="reset" name="button2" id="button2" value="Reset" /></td> </tr> <tr> <td> </td> <td colspan="2"> <?php echo $_error; ?> </td> </tr> </table> <p> </p> </form> </center> </body> </html> I have attached the screenshot of database. Problem is when I do valid login i.e. with user admin and its password, it is not working, I spent 1 hour for solving this issue but didnt find any solution. Its frustrating now.....I know its simple but still its not working. It is giving me error as Code: [Select] nothing found error, username was admin and pass is 62cc2d8b4bf2d8728120d052163a77df Resource id #5 Hi Guys I don't know if this is possible but can someone point me in the right direction. I have a php function which takes two inputs and returns an output. for simplicity's sake let's say it's an addition function. What I want to do is use a mysql select statement to show all the rows from a database where field1 and field2 equal '3'. Here's the sort of thing I mean. function addNumbers($one,$two) { return $one + $two; } mysql_query("SELECT * FROM table WHERE 'addNumbers(field1,field2)' = '3'"); What I actually want to do is a lot more complex than this but I am trying to understand how to make the syntax work in simple terms first. Can anybody help? Many Thanks Dan Here is my query: Code: [Select] $db->query("SELECT cache.*,u.username from search_cache cache LEFT Join users as u ON u.id = 'NEED HELP HERE' where ident = '{$username}' ORDER BY DATE DESC") or error('Unable to send the message.', __FILE__, __LINE__, $db->error()); Here is my data inside my search_cache Here is my while loop: Code: [Select] while($recent = $db->fetch_assoc($rec)){ $data = unserialize($recent['search_data']); } Now I can use $data['search_type'] as a array and If I use echo $data['search_type']['2'] it echo's out the user_id 32 as seen in the screenshot at the very end. Problem is, I want to use that 'NEED HELP HERE' to join with that id 32 dynamically, how the hell is that possible with mysql or is it? Or would it be easier to just add a new row/column named user_id and just join of that instead of trying to do all this? would that be faster? Hi, i got help earlier with the this code-- exploding a field and getting an array, then inserting the array into a multiselect box-- That part is easy and works fine. Now the explode function gives an array of words with duplicate words in it: I tried several ways most either give a blank option/value, or the array word.. here is the code: $query = "SELECT DISTINCT property_functionsexperience FROM #__users_profiles WHERE published = '1' ORDER BY property_functionsexperience ASC"; $functionsexperiencelistgeneral=doSelectSql($query); foreach($functionsexperiencelistgeneral as $words) $property_funcexperilist=$words->property_functionsexperience; $wording = explode(', ', $property_funcexperilist); foreach($wording as $funciex) $funcexi=array_unique($funciex); $funcexpList .= "<option value=\"".$funcexi.','."\">".$funcexi."</option>"; $funcexpList .= "</optgroup>"; } $funcexpList.="</select>"; $output['FUNCEXPLIST']=$funcexpList; this code is adapted slightly from the working original that gives the double words-- this code gives a blank, but i think its on the correct track!? Hi all. Here is my scripts which allow user to check multiple rows of data and delete it , but it require select data and click for twice to delete the rows , what should be the error? Code: [Select] <form name="frmSearch" method="post" action="insert-add.php"> <table width="600" border="1"> <tr> <th width="50"> <div align="center">#</div></th> <th width="91"> <div align="center">ID </div></th> <th width="198"> <div align="center">First Name </div></th> <th width="198"> <div align="center">Last Name </div></th> <th width="250"> <div align="center">Mobile Company </div></th> <th width="100"> <div align="center">Cell </div></th> <th width="100"> <div align="center">Workphone </div></th> <th width="100"> <div align="center">Group </div></th> </tr> </form> <? echo "<form name='form1' method='post' action=''>"; while($objResult = mysql_fetch_array($objQuery)) { echo "<tr>"; echo "<td align='center'><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$objResult[addedrec_ID]\"></td>"; echo "<td>$objResult[addedrec_ID] </td>"; echo "<td>$objResult[FirstName]</td>"; echo "<td>$objResult[LastName] </td>"; echo "<td>$objResult[MobileCompany] </td>"; echo "<td>$objResult[Cell] </td>"; echo "<td>$objResult[WorkPhone] </td>"; echo "<td>$objResult[Custgroup] </td>"; echo "</tr>"; } echo "<td colspan='7' align='center'><input name=\"delete\" type=\"submit\" id=\"delete\" value=\"Delete\">"; if (isset($_POST['delete']) && isset($_POST['checkbox'])) // from button name="delete" { $checkbox = ($_POST['checkbox']); //from name="checkbox[]" $countCheck = count($_POST['checkbox']); for($d=0;$d<$countCheck;$d++) { $del_id = $checkbox[$d]; $sql = "DELETE from UserAddedRecord where addedrec_ID = $del_id"; $result2=mysql_query($sql) or trigger_error(mysql_error());;; } if($result2) { $fgmembersite->GetSelfScript(); } else { echo "Error: ".mysql_error(); } } echo "</form>"; Thanks for every reply. |