PHP - Combo Box Using Arrays
i am trying to create a combo box so the user can order topics by asc or desc. The problem is trying to get the name of the option to Ascending or Descending and the value to asc or desc. Heres what i have so far:
$order_name = array('Ascending', 'Descending'); $order_value = array('asc' => 'Ascending', 'desc' => 'Descending'); echo "<div style=\"float:right;\">"; echo "<form name=\"order_form\" action=\"{$site_root}/index.php\" method=\"GET\">"; echo "<input type=\"hidden\" value=\"{$forum_id}\" name=\"forum\" />"; echo "<select name=\"order_by\" style=\"margin-left:5px;\">"; foreach ($order_name as $i) { echo "<option name=\"order_by_option\" value=\"{$order_value}\"/>"; echo "Order By: {$i}"; echo "</option>"; } echo "</select>"; when i try to order them the GET value is Array. Any ideas? Similar TutorialsI have this thing that i am trying to make but i cant get it to work.. can anyone help? Code: [Select] function sql_read( $dbname,$dbusername,$dbpassword ) { $names = array(); $password = array(); $connect = @mysql_connect("mysql11.000webhost.com",$dbusername,$dbpassword) or die("Could Not Connect"); @mysql_select_db ($dbname) or die("Could not find DataBase"); $query = mysql_query("select * from users"); $numrows = mysql_num_rows($query); if ($numrows > 0){ while($row = mysql_fetch_assoc($query)){ $names[] = $row["uname"]; $password[] = $row["password"]; $id = $row["id"]; } $return = array($names,$password,$id); }else{ $return = array(); } return $return[]; } $names = array(); $names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0]; The error i get is Code: [Select] Parse error: syntax error, unexpected '[' in /home/a5480952/public_html/sql/index.php on line 28 Line 28 is "$names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0];" Please help... i REALLLLD need help with this.. ask questions if you want to know more about what i am trying to do... thanks! I'm having troubling with trying to create a function to spit out a single array with the following array. I can write it in a away that looks through the arrays manually. the results i am trying to generate is that each item in generated array. Array to convert array( "account" => array( "login", "register", "logout", "edit", ), "p" => array( "report", ), "array1.0" => array( "array2.0" => array( "array3.0", "array3.1 ), "array2.1", ), generating the array will look like this
Array ( [0] => account [1] => account/login [2] => account/register [3] => account/logout [4] => account/edit [5] => p [6] => p/report [7] => array1.0 [8] => array1.0/array2.0 [9] => array1.0/array2.0/array3.0 [10] => array1.0/array2.0/array3.1 [11] => array1.0/array2.1 ) The idea is that id generates a single array with combined labels and arrays inside, etc. I just can't figure out how to create a script that will create this array even If I add a new value or array.
All, Looking for source exampe that lets you select between FTP, SFTP and SCP for file downloads, including ability to catalog all subdirectories and their files. Would appreciate quick shout with URL. Thanks! OMR This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=319848.0 Hello Guys, I need your advises. I am looking for the extension or a tutorial of how to make a multiple combo boxes with condition. For Example: Let's say I'm gonna have 3 combo boxes, and each of them will work according to the previous selection of previous combo box. Like, if I select state Illinois from the first combo box, the second combo box will show only the cities of Illinois (Chicago, and etc...). Is there a specific extension or any advises will help thank you guys Hi, I am developing a web application using PHP and MySQL. I am filling my combobox with the value fetched from the MySQL database. I want to retain the selected value of the combo box in postback. I am able to do it with the statiic values. But in this case I am binding the combbox dynamically with the values from the database. Can anybody please help me? Thanks, Regards, Viji Hi there, I am working on a PHP web form and I have a combo box and I'm trying to sort the values in it. The values in the combo box are filled using an arraylist: $WeightArray = array('' => '', '0|100' => '100g or Less', '101|250' => '101g to 250g', '251|500' => '251g to 500g', '501|1000' => '501g to 1kg', '1000|2000' => '1kg to 2kg', '2000|3000' => '2kg to 3kg', '3000|4000' => '3kg to 4kg', '4000|5000' => '4kg to 5kg', '5000|6000' => '5kg to 6kg', '6000|7000' => '6kg to 7kg', '7000|8000' => '7kg to 8kg', '8000|9000' => '8kg to 9kg', '9000|10000' => '9kg to 10kg', 'customValues' => 'Custom Values' ); The values get properly filled in the combo box. Thats fine. Its just that the values are not sorted the way I want them to. The Grams and Kilograms are all mixed. It should output in the order defined in the array. See the ScreenShot I've taken and see the difference in the values defined and the output. I tried few sorting methods like ksort($WeightArray); But still the same output. Whats the good trick to sort values in Combo as per the array. All comments and feedback are always welcomed. Thank you. Hi there. I am trying to sort values in a combo box stored in an array. The array is written in t his way. Here this is in proper sorting: $WeightArray = array('' => '', '100gOrLess' => '100g or Less', '101g-250g' => '101g to 250g', '251g-500g' => '251g to 500g', '501g-1kg' => '501g to 1kg', '1kg-2kg' => '1kg to 2kg', '2kg-3kg' => '2kg to 3kg', '3kg-4kg' => '3kg to 4kg', '4kg-5kg' => '4kg to 5kg', '5kg-6kg' => '5kg to 6kg', '6kg-7kg' => '6kg to 7kg', '7kg-8kg' => '7kg to 8kg', '8kg-9kg' => '8kg to 9kg', '9kg-10kg' => '9kg to 10kg', '10kg-11kg' => '10kg to 11kg', '11kg-12kg' => '11kg to 12kg' ); Now when I call this array and put in a combo it is displayed as shown in the Screenshot. It is displaying as, 10kg, 11kg 1kg ... in the incorrect order. I tried few sort() functions but I am not able to sort the array as shown in the screenshot attached. Kindly let me know how I can sort the values in the Combo box. Thank you!! Hi there... I am working on a PHP web form. I have Group name and its Member details stored in the database. The Group names from the database table gets populated in a combo box. Now what I'm trying to accomplish is, as soon I select a Group name, all its members should appear in a Label (or something) under the combo box with a textbox field next to the member name for me to assign the member position. How can we go about doing this. Please see the Screenshot I've attached and you'll have the idea as to what we're trying to accomplish here. All comments and feedback are welcomed! Thank you! I am trying to make a function that will generate a random number letter combo but the letters can only be abcde, no others. It must come out in the format, 1a~3d~9b~ etc. This is what I have so far: Code: [Select] function randomNumLet($amount){ $theNos = array('1', '2', '3', '4', '5', '6', '7', '8', '9'); $theLet = array('a', 'b', 'c', 'd', 'e'); $combo = ''; for($i=0;$i<$amount;++$i) { $rand_num = array_rand($theNos, 1); $rand_let = array_rand($theLet, 1); $combo .= $theNos[$rand_num[0]].$theLet[$rand_let[0]].'~'; } return $combo; } $num_let = randomNumLet(2); echo $num_let; And it returns just '~~' with no numbers or letters. I'm a bit stuck here and would appreciate any help. How can I make the function output 1a~4d~ etc? Cheers, Joe Hi Guys. Hopefully someone can help me with this...New to coding and pretty lost on this. I have a Mysql database which is displaying results to my webpage with no problems. However I would like to be able to add a combo box to my webpage that would update the mysql database results based on the combo box selection. For example if Ford is chosen from the combo box, the webpage would refresh and show all the results for Ford in the webpage. Can someone please help me? Here is the code I have at the moment that works just fine. But results of the database are based on the WHERE statement. Quote <?php $con = mysql_connect("server","database","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("a5525005_cars", $con); $result = mysql_query("SELECT * FROM `cars` WHERE Makel='Ford'"); echo "<table class='ex1' border='0' width='113%' style=text-align:center; cellpadding='6' cellspacing='0'> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr style=font-family:verdana;font-size:80%;>"; echo "<td width=13%>" . $row[""] . "<img src=\"" . $row["Photo"] . "\"></a>"; echo '<td width="14%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Model'] . '</a></td>'; echo '<td width="5%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Year'] . '</a></td>'; echo '<td width="4%"><a class="mylink" href="' . $row['URL'] . '">' . $row['Fuel'] . '</a></td>'; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> I have two arrays, both with the same key values. I'd like to combine them. So for instance... Code: [Select] <?php $array1['abcd'] = array( 'value1' => "blah", 'value2' => "blahblah"); $array1['efgh'] = array( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz"); $array2['abcd'] = array('value3' => "three", 'value4' => "four"); $array2['efgh'] = array( 'value3' => "hohoho", 'value6' => "six6"); function combine_arrays($array1,$array2) { //*combining* return $single_array; } echo "<pre>"; print_r(combine_arrays($array1,$array2)); echo "</pre>"; /* would produce ['abcd'] = ( 'value1' => "blah", 'value2' => "blahblah", 'value3' => "three", 'value4' => "four" ) ['efgh'] = ( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz", 'value3' => "hohoho", 'value6' => "six6" ) */ ?> What's the easiest way to do this? I have a simple database table that has the names of countries listed with just 2 fields ID & country.
I want to use this in a form to choose the country and provide statistics regarding that country.
I know how to get the data from MySQL, but I don't know how I can use this in the form as a selection?
How do I get the options to iterate all of the countries so that when the form is displayed a combo type box is displayed with a dropdown list?
I have not shown any code as I am not sure if this is possible.
Please can anyone advise if this is possible and if so some example code?
Hi there, I am having a PHP form with simple combo box. Here is the code: <form name="form1" method="get" action=""> <select name="select" onChange="form1.submit()"> <option value='value1'>My Value1</option> <option value='value2'>My Value2</option> <option value='value3'>My Value3</option> </select> </form> Now the form is successfully being submitted upon 'onChange' event. The only thing I am trying to do is to retain the value of the new option. As every time I select the value from the combo, it goes back and displays the 'value 1' even when I select value 3 or 2. How do I make the combo box retain the value as 3 (when I select option 3) after the form is submitted. Please reply. Thank you! Hi Good day Can someone pls help me regarding with this matter. I have a page for inserting records. And I have a combobox that is fetched through the specific field in database. I also have a table of records, for each row i have an href edit which throws the values to its respective texbox and combobox. THE PROBLEM is that when i click the href edit, the value from a selected row was not displayed from the combobox Arrays in C are fixed length:
#define MAX_SIZE 5 int main(void){ int n[ 5 ]; for(int i=0;i<MAX_SIZE;i++){ n[i]=i; } return 1; }If I try to insert an eleement into the array, it will result in undefined behavior. Java compensates for this by creating an actual object class called ArrayList or LinkedList, the former an internal store of array elements that dynamically resizes and the latter just a node tree with pointers to next and previous elements. ArrayList<Integer> arr = new ArrayList<Integer>(); arr.add(1); arr.add(2);It seens that the array() construct in PHP is not a function or a class but an internal construct. How does it dynamically resize arrays? Ok so this link returns HTML $hitlist = file_get_contents($iMobLink."get_hit_list?user_id=".$iStore[2]."&level=10&auth_key=".$iStore[3]); now to parse it out I have this $entry = explode('<entry>', $hitlist); $hitlist = file_get_contents($iMobLink."get_hit_list?user_id=".$iStore[2]."&level=10&auth_key=".$iStore[3]); $user_id = explode('<user_id>', $hitlist); $user_id = explode('</user_id>', $user_id[1]); $mobname = explode('<mob_name>', $hitlist); $mobname = explode('</mob_name>', $mobname[1]); $paiduser = explode('<paid_user>', $hitlist); $paiduser = explode('</paid_user>', $paid_user[1]); $amount = explode('<amount>', $hitlist); $amount = explode('</amount>', $amount[1]); $paid_time = explode('<placed_time_ago>', $hitlist); $paid_time = explode('</placed_time_ago>', $paid_time[1]); $level = explode('<level>', $hitlist); $level = explode('</level>', $level[1]); $entry = explode('</entry>', $entry[1]); echo $user_id[0]."\n"; echo urldecode($mobname[0])."\n"; echo $amount[0]."\n"; echo $paid_time[0]."\n"; echo $level[0]."\n"; echo $entry[0];} Ok now.... this only returns one entry of the xml when there are more than 10. I need it to return all ten+ of the entrys here is what the xml looks like <outer> − <xml> − <entry> − <target_user> <user_id>512433892</user_id> <mob_name>MR%2025TATT00S%2C%20Level%2015</mob_name> </target_user> − <paid_user> <user_id>554190549</user_id> <mob_name>PRINCE%20OF%20NEW</mob_name> </paid_user> <amount>48000000000</amount> <is_npc>false</is_npc> <placed_time_ago>3 days ago</placed_time_ago> <level>15</level> </entry> − <entry> − <target_user> <user_id>530120192</user_id> <mob_name>EVILNESS%20SIMPLIFIED%2C%20Level%2013</mob_name> </target_user> − <paid_user> <user_id>539494114</user_id> <mob_name>StompinDatAzz</mob_name> </paid_user> <amount>1478608800</amount> <is_npc>false</is_npc> <placed_time_ago>1 day ago</placed_time_ago> <level>13</level> </entry> − <entry> − <target_user> <user_id>526183645</user_id> <mob_name>snatch%20rider%2C%20Level%20112</mob_name> </target_user> − <paid_user> <user_id>450207248</user_id> <mob_name>ShiftyShellShock</mob_name> </paid_user> <amount>999999999</amount> <is_npc>false</is_npc> <placed_time_ago>22 hours ago</placed_time_ago> <level>112</level> </entry> − <entry> − <target_user> <user_id>542145086</user_id> <mob_name>Riding%20Raider%2C%20Level%2043</mob_name> </target_user> − <paid_user> <user_id>513441119</user_id> <mob_name>Level%20U%20uP</mob_name> </paid_user> <amount>334616000</amount> <is_npc>false</is_npc> <placed_time_ago>18 hours ago</placed_time_ago> <level>43</level> </entry> − <entry> − <target_user> <user_id>554043828</user_id> <mob_name>klaibers%20limited%2C%20Level%2011</mob_name> </target_user> − <paid_user> <user_id>522432052</user_id> <mob_name>Sloppy%20Seconds</mob_name> </paid_user> <amount>39344504405</amount> <is_npc>false</is_npc> <placed_time_ago>17 hours ago</placed_time_ago> <level>11</level> </entry> − <entry> − <target_user> <user_id>496266215</user_id> <mob_name>Geheim%20Abwher%2C%20Level%207</mob_name> </target_user> − <paid_user> <user_id>216904061</user_id> <mob_name>yve1</mob_name> </paid_user> <amount>2499912800</amount> <is_npc>false</is_npc> <placed_time_ago>16 hours ago</placed_time_ago> <level>7</level> </entry> − <entry> − <target_user> <user_id>524874924</user_id> <mob_name>MYLILFRIEND%2C%20Level%20104</mob_name> </target_user> − <paid_user> <user_id>536745842</user_id> <mob_name>SUC%20MY%20GLOCK</mob_name> </paid_user> <amount>1615247200</amount> <is_npc>false</is_npc> <placed_time_ago>15 hours ago</placed_time_ago> <level>104</level> </entry> − <entry> − <target_user> <user_id>531185082</user_id> <mob_name>THE%20RAGE%20WITHIN%2C%20Level%2031</mob_name> </target_user> − <paid_user> <user_id>512862859</user_id> <mob_name>The%20Kozmik%20Slop</mob_name> </paid_user> <amount>16536800</amount> <is_npc>false</is_npc> <placed_time_ago>14 hours ago</placed_time_ago> <level>31</level> </entry> − <entry> − <target_user> <user_id>494326270</user_id> <mob_name>RIDE%20HIS%20CUCUMBER%2C%20Level%2016</mob_name> </target_user> − <paid_user> <user_id>554794332</user_id> <mob_name>STDS%20R%20BAD%20MMKAY</mob_name> </paid_user> <amount>337825600</amount> <is_npc>false</is_npc> <placed_time_ago>14 hours ago</placed_time_ago> <level>16</level> </entry> − <entry> − <target_user> <user_id>558355598</user_id> <mob_name>DEATH%20TO%20HITLIST%2C%20Level%2011</mob_name> </target_user> − <paid_user> <user_id>558349535</user_id> <mob_name>Gangsta%20Love</mob_name> </paid_user> <amount>181600000</amount> <is_npc>false</is_npc> <placed_time_ago>10 hours ago</placed_time_ago> <level>11</level> </entry> − <entry> − <target_user> <user_id>545114043</user_id> <mob_name>Ridin%20Dirty%2C%20Level%20130</mob_name> </target_user> − <paid_user> <user_id>510805692</user_id> <mob_name>iced%20baby</mob_name> </paid_user> <amount>481680800</amount> <is_npc>false</is_npc> <placed_time_ago>10 hours ago</placed_time_ago> <level>130</level> </entry> Notice there is more than one energy.. now how to I parse it out to where I can define each entry by a variable or something... any help is appreciated.. Thanks Can someone help? I am new to PHP and trying to get some training in before I commence study in September. Below you will see the code for a very simple Lucky Lotto number generator, which generates six numbers at random from the $numbers array via the shuffle(). Being that I am a learner, in the most simple way possible I want to place the resulting 6 numbers in a new array, so I can use other functions to ascertain comparisons and results etc. Code: [Select] <?php class Game { public $count; public $draw = array(1,15,16,27,30,18); public $numbers = array (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35 ,36,37,38,39,10,41,42,43,44,45,46,47,48,49); function display($sub1) { $this->count = $sub1; while ($this->count>0) { shuffle($this->numbers); for($j=0;$j<6;$j++) echo $this->numbers[$j] . " "; echo "<br />"; shuffle($this->numbers); $this->count--; } } } $object1 = new Game(); $object1->display(1); ?> Hello, I'm trying to extract information about a ticket through osTicket SOAP API, but I can't seem to figure out how! This is the return from the script (var_dump): array(1) { [0]=> object(stdClass)#2 (2) { ["question"]=> object(stdClass)#3 (4) { ["id"]=> int(25) ["created"]=> string(25) "2011-01-05T01:19:43+01:00" ["name"]=> string(4) "test" ["message"]=> string(4) "qasd" } ["answers"]=> array(1) { [0]=> object(stdClass)#4 (4) { ["id"]=> int(25) ["created"]=> string(25) "2011-01-05T01:25:06+01:00" ["name"]=> string(17) "Andreas Haakonsen" ["message"]=> string(3) "ler" } } } } A ticket can have several answers. I just can't seem to figure out how to extract/use this data and present it on my webpage. Too many arrays for me to understand I guess :p Is there anyone who can help me with some small code to help me figure this one out? Thanks! |