PHP - Splitting For Dropdown Into 2 Variable
Hi,
I have a form with a dropdown Code: [Select] <select name="county" id="county"> <option selected="selected">Choose A County</option> <option value="1">Dublin</option> <option value="2">Westmeath</option> <option value="3">Galway</option> <option value="4">Roscommon</option> </select> What I am trying to do is seperate for example the value '1' and the option 'Dublin'. The results are passed to hidden field on a second form page. This is what I have, but it doesnt seem to be working... Code: [Select] <input type="hidden" name="county" value="<?php echo ($_POST['county']); ?>" /> <input type="hidden" name="county1" value="<?php echo ($_POST['county']); ?>" /> so I was wondering if anyone might be able to give me a pointer in the right direction. I have tried using an array on the processing page to split it but its not working either.. like this: Code: [Select] $county = (float) $_POST['county']; $county1 = in_array($county, array(1, 2, 3, 4)) ? $county : 5; $county1 = $_POST['1']='Dublin'; $county1 = $_POST['2']='Westmeath'; $county1 = $_POST['3']='Galway'; $county1 = $_POST['4']='Roscommon'; $county1 = $_POST['5']='Cork'; I have been trying to get this to work for a few days and I have searched everywhere for the answer, but I can't find it anywhere. I would be so grateful if someone could help me with this and it the last part I need to do before I move on to the next part of my project. Thanking you Eoin Similar TutorialsI have been pulling my hair out for about 2 weeks with this problem. I am doing this on a localhost set up, not a live server. Here are the fields in the categories table in question: id, cattitle, caturl, catdesc, orderby, parentid What I am trying to accomplish is to create a dropdown list from the values in cattitle and parentid fields which I have done successfully. Here is the code from my "categories_modify.php" file where the dropdown is displayed. <form action="" method="POST"> <table cellspacing="5" cellpadding="1" border="0"> <tr> <td> Change Parent Category To: </td> <td> <select name="location"> <?php foreach ($categories as $loc): ?> <option name="parid" value="<?php htmlout($loc['parentid']); ?>"><?php htmlout($loc['cattitle']); ?></option> <?php endforeach; ?> </select> </td> </tr> <tr> <td> </td> <td> <input type="hidden" name="id" value="<?php htmlout($id); ?>" /> <input type="submit" value="Update" /> </td> </tr> </table> </form> The code generating the values in the form is in my controller script called index.php. Here is the code for that part. **Note that the top section of the script below populates a series of text boxes with current values in the database for editing/updating I did not show "edit" form in the code above as it works fine. The part of code populating my dropdown box values starts with the "locat... line except for my db.inc.php database connection at the top (which also works fine). if (isset($_POST['action']) and $_POST['action'] == 'Edit') { include $_SERVER['DOCUMENT_ROOT'] . './includes/db.inc.php'; { $id = mysqli_real_escape_string($link, $_POST['id']); $sql = "Select id, cattitle, orderby, caturl, catdesc, parentid from categories where id = '$id'"; $result = mysqli_query($link, $sql); if (!$result) { $error = 'Error fetching category details ' . mysqli_error($link); include 'error.php'; exit(); } $row = mysqli_fetch_array($result); $pagetitle = 'Edit Category'; $action = 'editform'; $id = $row['id']; $cattitle = $row['cattitle']; $orderby = $row['orderby']; $caturl = $row['caturl']; $catdesc = $row['catdesc']; $button = 'Update'; $locate = "Select id, cattitle, parentid from categories order by cattitle asc"; $res = mysqli_query($link, $locate); if (!$res) { $error = 'Error fetching category details ' . mysqli_error($link); include 'error.php'; exit(); } while ($locat = mysqli_fetch_array($res)) { $categories[] = array('id' => $locat['id'], 'cattitle' => $locat['cattitle'], 'parentid' => $locat['parentid']); } } include 'categories_modify.php'; exit(); } Now for the code that gets the POSTED info from the dropdown window. if (isset($_GET['location'])) { include $_SERVER['DOCUMENT_ROOT'] . './includes/db.inc.php'; $id = mysqli_real_escape_string($link, $_POST['id']); $parentid = mysqli_real_escape_string($link, $_POST['parid']); $parentid++; $sql = "Update categories set parentid = '$parentid' where id = '$id'"; if (!mysqli_query($link, $sql)) { $error = 'Error updating categories ' . mysqli_error($link); include 'error.php'; exit(); } header('Location: .'); exit(); } The goal is to take the parentid value and increase it by 1 so I can create subcategories based on the parentid value. (maybe not the best way but I'd still like to figure out why I can't make this work.) This line is where I think the problem is, or atleast part of it: $parentid = mysqli_real_escape_string($link, $_POST['parid']); I believe it is coming back blank because when I re-run the script for my "test" value it will always comeback as 1 (the default value for parentid is 0) 0 + 1 = 1. If I update the form again where the parentid now equals 1 it still equals 1, can't get it to 2. BTW I have tried every variation of the above line I could think of with no luck hence this post. Thanks for any help. I hope this was clear enough. Hopefully someone can help, firstly i am a newbie at php coding but keen to learn more.
Here is my problem
The database is built correctly with all the information i need, the first part is the dropdown menu which you select a car, next you choose a month and mileage - from there it shall show you the correct price for each one. There is columns for each price, mileage and months i just need to figure out how best to start this thing.
I first started by this
$query = "SELECT DISTINCT Full_Description FROM import"; 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 I have found postings close, but not close enough to find my error. I am looking up data from a MySql table and putting it in a dropdown box on a form. I can select the item, but apparently not really. I am not able to echo it, or post it to a record. I'm sure I am missing something simple, but... Code attached if anyone can show me the errors of my ways. Thank you. I have a dropdown list which have some elements. I want to get all the elements of the dropdown list into a variable of type array. Any Idea??? http://mobsters-fb-apache-dynamic-lb.playdom.com/mob_fb/get_hit_list?user_id=100000952273457&target_id=100000556624340&level=300&auth_key=cb07c7575b38df48d82dd53619385faa884db5a2 When going to this URL, it gives entries between <entry> and </entry>, what I am trying to do, is collect the <user_id> ONLY if the <amount> is over a certain value. Any ideas to how I could do this (I am a complete PHP noob). All help is appreciated Heya guys! What's up? OK here's my problem: I got a variable, $var1, which is to have values like "groan,100,200,350,50" I need to know how to split this $var1 into $split1, $split2, $split3, $split4, $split5, where $split1 = "groan"; $split2 = "100"; $split3 = "200"; $split4 = "350"; $split5 = "50"; Thanks in advance people! P.S. In my case I am going to use some of the values for calculations. So I don't think that its easy with arrays, which are difficult for me to understand . P.S.S. When I am retrieving data from the database, many variables like $var1 that need to be split are being extracted. I hope that you understand. Thanks and Regards, Thauwa I have a text field that contains the following (example text used): 1 2 3 4 5 6 As you can see the first few are split by a single space, with the last few numbers split by a double space. My aim is to put each of these numbers into a table in a MYSQL database. But I'm having trouble breaking them up. Hi guys Say for example I have a text field with value 20/10/2011 how do I define it so that $x=20, $y=10 and $z=2011 so that I have three variables Thanks Okay I need a little bit of help on this as strings constantly confuse me and reading tutorials actually got me a bit more loss then before. I have developed this mod that has become pretty popular and I'm debugging it. What I have are two variables. $username (The user's username, no html markup in it) $musername (The user's username, with html markup in it) So for example: $musername = <b><u>$username</u></b> The php code above would be the equivolant to what $musername is equal to. What I need to do is create an array or two variables, whatever is easier and grab all that html markup. The first variable would be all the html or anything really before the $username variable, and the other would take all of that html after the $username variable. I need to store those html markups in either two seperate variables or an array so i can call upon it later in the script. I need this to fix a bug issue. I have a string like this: Code: [Select] Something,Somthing Else,"keyword1,keyword2,keyword3",Yet another I need to split that string by the ,. However, I need the data that is n the quotes to remain as one even though it has commas because it is one item. I assume I need to use preg_split and have tried some code but none of it seems to work properly. If anyone has a better method or knows how I can split this up using preg_split the help is appreciated. I could use some suggestions on how to break up my HTML and PHP. Currently I have a file called "payment_form.php" It looks like this... Code: [Select] <body> <?php // HANDLE FORM. if (isset($_POST['submitted'])){ // Handle Form. // Determine if any errors. if (empty($errors)){ // Process Payment. // PHP code to send payment to Payment Gateway... // Do not return to Payment Form!!! exit(); } } ?> <!-- HTML PAYMENT FORM --> <form id="payment" action="" method="post"> <fieldset> <legend>Billing Details</legend> <ol> <!-- First Name --> <li> <label for="firstName">First Name:</label> <input id="firstName" name="firstName" class="text" type="text" maxlength="20" value="<?php echo $firstName; ?>" /> <?php if (!empty($errors['firstName'])){ echo '<span class="error">' . $errors['firstName'] . '</span>'; } ?> </li> I would like to keep the Form Validation PHP in the same file as the HTML Form so the user isn't ping-ponged between two pages if they make data entry errors. However, I am thinking it would be better to break out the Payment Processing PHP and place that in a different file. How should I do that? Maybe I could add a Redirect after this code... Code: [Select] if (empty($errors)){ // Process Payment. // PHP code to send payment to Payment Gateway... Suggestions welcome!! Thanks, Debbie The sample string is KmSO4 Every upper case alphabet should be identified and splitted until another upper case alphabet comes. the string should be splitted so that output array looks like this Array ( => Km [1] => S [2]=>O4 ) can any one help regarding this issue? Hi Guys, does anyone know how split a text into groups depending on how many words are in the text e.g $text = "If you are new to PHP and want to get some idea of how it works, try the introductory tutorial. "; I want a maximium of 5 words in each group, so the above text will be split as such $text1 = 'If you are new to'; $text2 = 'PHP and want to get'; $text3 = 'some idea of how it '; $text4 = 'works, try the introductory tutorial.'; But if I want a maximium of 10 words in each group, so the above text will then be split like this $text1 = 'If you are new to PHP and want to get'; $text2 = 'some idea of how it works, try the introductory tutorial.'; $text3 = ''; $text4 = ''; Is this possible? Please any help will be much appreciated thanks Hello, I have a variable that holds a piece of text that looks something like this: "world,blue,big". Is there anyway to split the text into the separate words as an array, and remove the commas? Code: [Select] $text_to_split = "world,blue,big"; $splitArray = array(); //Do some kind of php function that splits text\\ echo splitArray[0]; // world echo splitArray[1]; //blue echo splitArray[2]; //big Would appreciate it, thanks I have a database full of strings which are basically URL's with ports, so by default my strings look like: http://example.com:1234/ http://example2.com:3030/ http://example.com:9876/ http://example.com:5432/ What I am looking for is a way to separate the host from the post so the output would be something like: Host: example.com Port: 1234 Note: I once need to check one string at a time, so what I am after is something like: $string = "http://example.com:1234/"; And the result would be something like: $host (would be example.com without http://) $port (would be the port without ending /) Any help would be great Thanks for your time reasing this. Hi All How do I go about splitting a multidimensional array into seperate smaller ones? Currently I have $grade[region][userid]=value. I'd like to split as $region1[userid]=value $region2[userid]=value $region3[userid]=value $region4[userid]=value $region5[userid]=value $region6[userid]=value Is there an inbuilt function for this? I'll be creating a script that will get the keywords from uploaded pictures and what i cant figure out is how to actually get only the keywords from the iptc data this is the code i have for getting the iptc data right now: Code: [Select] <?php $size = getimagesize('images/Sections/pinkpanthers/20102011/Session1/1-15-11/1.jpg', $info); if(isset($info['APP13'])) { $iptc = iptcparse($info['APP13']); var_dump($iptc); ?> } and this outputs Code: [Select] array(4) { ["1#090"]=> array(1) { [0]=> string(3) "%G" } ["2#000"]=> array(1) { [0]=> string(2) "" } ["2#025"]=> array(1) { [0]=> string(5) "Tyler" } ["2#080"]=> array(1) { [0]=> string(15) "Christian" } } all i want from the above string is the Tyler Hey guys,
I have an array of names sorted alphabetically. I'm trying to loop through them and create new arrays keyed by the letters of the alphabet containing the names which start with that letter.
so in the end i'm trying to create something like this:
$newarray = array( 'a' => array('anna','alan','andrew'),
'b' => array('bert','ben','bob'), 'c' => array('cait','carry'), etc,etc ); thanks hey guys just a quick onei having a blank moment i have an array at themoment pulling from a database. i basically want to split this array based on a min and max value. divide it equally and then give it a value on each smaller array and where each array starts... to make it clearer - say i have an array with 600 values in i want it split up into 8 smaller arrays link so Array ( => Array ( [start] => 0 [split] => 75 ) [1] => Array ( [start] => 75 [split] => 75 ) [2] => Array ( [start] => 150 [split] => 75 ) carrying on till the end ) how would i do this. |