Update:
It looks like it is very complicated as I have had many views but no comments, could someone tell me how to check through the array {NAME} to find where it loses it's content please?
Original question:
I have been debugging an older php script and this is the last bit where I am struggling. The date does not show up when I have the drop down list:
This is what the output is in HTML:
<select name="trans_date2_month" style="width: {WIDTH}" >
<option value="{VALUE}" {SELECTED}>{NAME}</option>
<option value="{VALUE}" {SELECTED}>{NAME}</option>
<option value="{VALUE}" {SELECTED}>{NAME}</option>
<option value="{VALUE}" {SELECTED}>{NAME}</option>
<option value="{VALUE}" {SELECTED}>{NAME}</option>
<option value="{VALUE}" {SELECTED}>{NAME}</option>
<option value="{VALUE}" {SELECTED}>{NAME}</option>
<option value="{VALUE}" {SELECTED}>{NAME}</option>
<option value="{VALUE}" {SELECTED}>{NAME}</option>
<option value="{VALUE}" {SELECTED}>{NAME}</option>
<option value="{VALUE}" {SELECTED}>{NAME}</option>
<option value="{VALUE}" {SELECTED}>{NAME}</option>
</select>
Could someone help to find out how to track back in php please? I am more than happy to give more code's but I didn't want to overload the first page.
This was generated by the following code:
<!--S:DateSelectOption-->
<option value="{VALUE}" {SELECTED}>{NAME}</option>
<!--E:DateSelectOption-->
How to find {value} and {name}? - (please don't say that the search bar will help - I have done it:)
Update:
case "year":
if ($field["fields"]["year"]["empty"] == "true") {
$years[0] = "--" ;
}
for ($i = $field["fields"]["year"]["from"] ; $i <= $field["fields"]["year"]["to"] ; $i++ )
$years[$i] = $i;
$current_field .= $html->FormSelect(
$field["name"]."_year" ,
$years ,
$this->templates ,
"DateSelect",
$year_selected ,
array() ,
array("DISABLED" => ($field["fields"]["year"]["editable"] == "false") ? "DISABLED" : "")
);
$current_field .= $val["separator"];
break;
Update II:
A little bit more code, after searching for name... as a bad habit...
function HNDCData($parser,$cdata) {
$cdata = str_replace("[amp]","&",$cdata);
//echo "<br>" . $cdata;
// create the proper tree node if NAME attribute is set
if ($this->attr["NAME"] != "")
$this->tags[count($this->tags) - 1] = $this->attr["NAME"];
// cleanup cdata
$cdata = trim($cdata);
//$cdata = preg_replace("/(\015\012)|(\015)|(\012)/","",$cdata);
// only parse if cdata not void
if ($cdata != "") {
//print_r($this->attr);
//echo "<br>" . $cdata;
// prepare dynamic code
foreach ($this->tags as $key => $val)
$code[] = "\"" . strtolower($val) . "\"";
// build code
$code = "\$this->vars[" . implode("][",$code) . "] = \"" . $cdata . "\";";
// and finally execute
eval($code);
}
}
Update:
I have changed the for loop to numbers rather than variables but no difference.
for ($i = 2004 ; $i <= 2050 ; $i++ )
Related
I have a country list of every country in a form to get a parcel quote.
When a user presses the "Get Quote" button, all the text forms retain the information previously entered using PHP.
How can I do this with the country list box? As I can't have PHP on every option checking if that is the country selected and adding "Selected" to the html.
Is there a better way other than generating the country list from a file in a loop?
EDIT:
Going for the method of looping through a file, and checking..
This is what I have so far:
$countries = fopen("includes/countries.txt", "r");
$countries = explode(";", $countries);
Then in the HTML:
<select id="countries" name="countries">
<?php
foreach ($countries as $country){
echo("<option value=\"" . $country . "\">" . $country . "</option>");
}
?>
</select>
Not yet finished.
I assume you have an array with your countries stored. You could try something like this:
$countries = array('Albania', 'Egypt');
$selected_country_id = $_GET['c_id']; // You may need to change this to match with your code
$country_selected = array();
foreach($countries as $country) {
if($country['id'] == $selected_country_id) {
$country_selected[ $country['id'] ] = ' selected ';
} else {
$country_selected[ $country['id'] ] = '';
}
}
Then, assuming that you dynamically add your Select-Options, do this:
// In your each-fn
echo '<option value="' . $country['id'] . '" ' . $country_selected[ $country['id'] ] . '>' . $country['name'] . '</option>';
Something like this would be better
foreach ($countries as $country) {
?>
<option value="<?php echo $country" <?php echo ($country == $_POST['country'] ? 'selected' : ''; ?>><?php echo $country; ?></option>
<?php
}
<select id="countries" name="countries">
<?php
foreach ($countries as $country){
if(isset($_POST["country"]) && $_POST["country"] == $country){
$sel = "selected";
}else { $sel= ""; }
echo("<option value=\"" . $country . "\"" .$sel.">" . $country . "</option>");
}
?>
</select>
Get All Country-State-City Selectbox ....!!!
See Link : GitHub
I am trying to create something similar to an auction/bidding table/form.
If a value (current bid) is 1000, I am trying to create a selection box that allows another user to bid in intervals of 500, so for this example the outcome would be like:
Current Bid: 1000
Buy Now: 5000
<select class="form-control">
<option value="1500">1500</option>
<option value="2000">2000</option>
<option value="2500">2500</option>
<option value="3000">3000</option>
<option value="3500">3500</option>
<option value="4000">4000</option>
<option value="4500">4500</option>
</select>
Something like this:
<?php
$query = $db->query('SELECT * FROM auctions WHERE available = 1 LIMIT 1');
$num = $query->num_rows;
if($num > 0) {
echo '<select class="form-control">';
foreach($query as $row) {
$currentBid = $row['currentBid']; // 1000
$buyNow = $row['buyNow']; // 5000
$bids = ?? // this is where I am stuck, how can I make the difference between $currentBid and $buyNow show as options divided by 500's
echo '
<option value="'.$bids.'">'.$bids.'</option>
';
}
echo '</select>';
}
else {
echo "No auctions available";
}
?>
...
$currentBid = $row['currentBid'];
$buyNow = $row['buyNow'];
...
$options = '';
for($p = $currentBid + 500; $p <= $buyNow; $p += 500) {
$options .= '<option value="'.$p.'">'.$p.'</option>';
}
I have a list of items, each with a date/time option. I need for each list item to have the correct time displayed for it.
But this doesn't seem to work. It will return the correct 'am' or 'pm' value for $duedateA, but when I try to set the selected attribute value is gets wonky and will either show the wrong am or pm, or both.
Am I doing something wrong?
if(!empty($resInvoice[0]["due_date"])){
$duedateA = date("a",strtotime($resInvoice[0]['due_date']));
}
if($duedateA == "am"){
$selected_am = 'selected="selected"';
}
if($duedateA == "pm"){
$selected_pm = 'selected="selected"';
}
<select name="due_time[a]">
<option value="am" '.$selected_am.'>am</option>
<option value="pm" '.$selected_pm.'>pm</option>
</select>
date_default_timezone_set('America/New_York');
$resInvoice[0]["due_date"] = '2012-10-26 03:21:44';
$selected_am = '';
$selected_pm = '';
$duedateA = '';
if(!empty($resInvoice[0]["due_date"])){
$duedateA = date("a",strtotime($resInvoice[0]["due_date"]));
}
if($duedateA == "am"){
$selected_am = ' selected="selected"';
}
if($duedateA == "pm"){
$selected_pm = ' selected="selected"';
}
echo '<select name="due_date[a]">
<option value="am"'.$selected_am.'>AM</option>
<option value="pm"'.$selected_pm.'>PM</option>
</select>';
sorry for all the variables, i have my errors set to strict.
I am looking for some method to select a php combobox "<select>" based on results from mysql.
Actually I am working on a php form that will be used to edit existing values in mysql table. My first form will simply pass the id of the record to be edited, and this goes something like this Click to edit
Code on editCalendar.php is as follows:
<?php
include("dbpath.php");
$id = htmlspecialchars($_GET["id"]);
$sql="Select * from event_Date where eventid=" . $id;
$result=mysql_query($sql);
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result)
{
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
while($row = mysql_fetch_assoc($result))
{
$name=$row["EventTitle"];
$close=$row["OpenOrClose"];
$remarks=$row["Remarks"];
$date=$row["EventDate"];
$type=$row["Type"];
}
?>
The value obtained in $close will be used to select "SelectClosedOrOpen" on the same form, i.e. the user will get pre selected option from the populated list.
<select id="SelectClosedOrOpen">
<option value="3">Select</option>
<option value="0">Open</option>
<option value="1">Closed</option>
</select>
Means, if $close has 0, then <option value="0">Open</option> must be selected else if $close has 1 then <option value="1">Closed</option> should be automatically selected on formload.
You'll just need to write the selected attribute in there. Try this
<select id="SelectClosedOrOpen">
<option value="3" <?php echo ($close == 3) ? 'selected="selected"': ''; ?>>Select</option>
<option value="0" <?php echo ($close == 0) ? 'selected="selected"': ''; ?>>Open</option>
<option value="1" <?php echo ($close == 1) ? 'selected="selected"': ''; ?>>Closed</option>
</select>
I created this function some years back. I hope it helps you.
It basically requires an array of your options and the value of the option to be pre-selected. It returns the OPTIONS for your select, so you still have to create the SELECT tags, which allows you to customise the ID, JS etc..
function drop_down_box_options_from_array($choices,$default="")
{
$output= '';
// $choices is contructed using $choices[]=array("value","Displayed Choice");
while (list ($key, $val) = each ($choices))
{
$output.= '<option value="';
$output.= $choices[$key][0];
if ($default==$choices[$key][0])
{
$output.= '" selected="selected" >';
}
else
{
$output.= '">';
}
$output.= $choices[$key][1];
$output.= '</option>';
$output.= "\n";
}
return $output;
}
Using your scenario:
<select id="SelectClosedOrOpen" name="OpenOrClose">
<?php
// defined here for clarity, but can be defined earlier ie in a config file
$choices[]=array('3', 'Select');
$choices[]=array('0', 'Open');
$choices[]=array('1', 'Closed');
echo drop_down_box_options_from_array($choices, $row['OpenOrClose']);
?>
</select>
Well, I am writing class that creates a DOB selection dropdown.
I am having figure out the dropdown(), it seems working but not exactly. Code just creates one drop down, and under this dropdown all day, month and year data are in one selection. like:
<label>
<sup>*</sup>DOB</label>
<select name="form_bod_year">
<option value=""/>
<option selected="" value="0">1</option>
<option value="1">2</option>
<option value="2">3</option>
<option value="3">4</option>
<option value="4">5</option>
<option value="5">6</option>
..
<option value="29">30</option>
<option value="30">31</option>
<option value="1">January</option>
<option value="2">February</option>
..
<option value="11">November</option>
<option value="12">December</option>
<option selected="" value="0">1910</option>
<option value="1">1911</option>
..
<option value="98">2008</option>
<option value="99">2009</option>
<option value="100">2010</option>
</select>
Here is my code, I wonder that why all datas are in one selection. It has to be tree selction - Day:Month:Year.
//dropdown connector
class DropDownConnector
{
var $dropDownsDatas;
var $field_label;
var $field_name;
var $locale;
function __construct($dropDownsDatas, $field_label, $field_name, $locale)
{
$this->dropDownsDatas = $dropDownsDatas;
$this->field_label = $field_label;
$this->field_name = $field_name;
$this->locale = $locale;
}
function getValue(){
return $_POST[$this->field_name];
}
function dropdown(){
$selectedVal = $this->getValue($this->field_name);
foreach($this->dropDownsDatas as $keys=>$values){
foreach ($values as $key=>$value){
$selected = ($key == $selectedVal ? "selected" : "" );
$options .= sprintf('%s',$key,$value);
};
};
return $select_start = "$this->field_desc".$options."";
}
function getLabel(){
$non_req = $this->getNotRequiredData();
$req = in_array($this->field_name, $non_req) ? '' : '*';
return $this->field_label ? $req . $this->field_label : '';
}
function __toString()
{
$id = $this->field_name;
$label = $this->getLabel();
$field = $this->dropdown();
return 'field_name.'">'.$label.''.$field.'';
}
}
function generateForm ($lang,$country_list,$states_list,$days_of_month,$month_list,$years){
$xx = array(
'form_bod_day' => $days_of_month,
'form_bod_month' => $month_list,
'form_bod_year' => $years);
echo $dropDownConnector = new DropDownConnector($xx,'DOB','bod','en-US');
}
// Call php class to use class on external functionss.
$avInq = new formGenerator;
$lang='en-US';
echo generateForm ($lang,$country_list,$states_list,$days_of_month,$month_list,$years);
While this might or might not work for you, I would suggest taking a look at the Jquery UI Datepicker. It provides a very nice and highly customizable calendar that might be able to save you a lot of time.