<? $config = parse_ini_file('/list.ini', true); ?>
<?echo'<select id="LBox" name="listbox" size="20" style="display:none;">';
foreach($config[MPR] as $id=>$label){
switch ($id)
{
case ($id==select):
echo'<option value="0" selected="selected"></option>';
break;
case ($id>0 && $id<=10):
echo'<optgroup label="'.$label.'">';
break;
case ($id>10 && $id<=20):
echo'</optgroup>';
break;
default:
echo'<option value="'.$id.'">'.$label.'</option>';
}
}
echo'</select>';?>
Above is code that builds a hidden list box and fills its options from an INI file. I would Like to replicate this for each section in my ini, but I am unsure of the best way to do this, other than copy and paste this 8 times with a new $config[x] value. Is there a way to replicate this for each section?
Write a function that does it and takes whatever changes (e.g. $config[x]) as an argument.
Related
I need any suggestion how can i do that. Example what i trying todo:
I have option value called "Ban reason":
Cheating
Sample reason
If i choose "Cheating" i put reason "Chating" into mysql. That's ok with my code:
DB::table('server_bans')->insert(['reason' => Input::get('player_reason')
My view:
<select id="player_reason" name="player_reason"><option value="" selected="selected">-</option>
<option value="Cheating">Cheating</option>
<option value="No reason">No reason</option>
</select>
But i need to add into sql "Ban time" by reason using minutes. Example:
If i choose "Cheating" from option value, it goes reason and banlength for 360days by using minutes timer (518400 minutes)
Any suggestion how can i do that? Thanks for helping me!
You just need to switch on the reason and set a variable in your controller method when saving the ban reason.
public function banUser (Request $request) {
$reason = $request->get('player_reason');
switch ($reason) {
case 'Cheating':
$banlength = 518400;
break;
case 'No Reason':
$banlength = 1;
break;
default:
$banlength = 0;
break;
}
DB::table('server_bans')->insert(compact('reason', 'banlength'));
return back();
}
I have a cms admin section with the option comments; when i press comments on the admin menu it should take me to comments.php which includes the code below; by default it should load all my comments on a grid, however when i press comments its not displaying anything the page is blank ? My code:
<?php
if(isset($_GET['source'])){
$source1=$_GET['source'];
if(!empty($source1)){
switch($source1){
case 'add_post':
include"includes/add_posts.php";
break;
case 'edit_post':
include"includes/edit_post.php";
break;
case 'view_all_comments':
include "includes/view_all_comments.php";
break;
default:
include "includes/view_all_comments.php";
}
}
}
?>
when u load comments.php the url doesnt sent any parameter via get, on your code you are checking if the source is not empty which on your case its empty at first. Then preform switch statment, in your case it will not preform the switch as the source is empty and thats why you are not seeing anything. You can fix that by adding an else on your if and include view_all_comments.php or like the code below:
<?php
$source1=isset($_GET['source']);
switch($source1){
case 'add_post':
include"includes/add_posts.php";
break;
case 'edit_post':
include"includes/edit_post.php";
break;
case 'view_all_comments':
include "includes/view_all_comments.php";
break;
default:
include "includes/view_all_comments.php";
}
?>
I made the dropdown with PHP which works fine. When the selected item changes, I call the function changePeriod().
$options[0] = '--period--';
$options[1] = 'Daily';
$options[2] = 'Weekly';
$options[3] = 'Monthly';
<td><?php echo form_dropdown('period', $options, '0', 'id="period" onchange="changePeriod()"'); ?></td>
Here you can see the HTML source code which is a result of the code above.
<td>
<select name="period" id="period" onchange="changePeriod()">
<option value="0" selected="selected">--period--</option>
<option value="1">Daily</option>
<option value="2">Weekly</option>
<option value="3">Monthly</option>
</select>
</td>
In this function I need to get the value of the selected item, but the 2 alerts above the switch both give Undefined as a result. Does anyone has an idea why I get undefined and not the values of the selected option? It worked with a dynamic dropdown filled with a foreach from the database.
function changePeriod() {
alert(document.getElementById("period").selectedIndex);
alert(document.getElementById("period").value);
switch (document.getElementById("period").selectedIndex) {
case 1:
alert("daily");
break;
case 2:
alert("weekly");
break;
case 3:
alert("monthly");
break;
}
}
Basically: Why can't I get the values of the selected option and how can I fix it?
Thanks for helping.
Is the HTML generated like this:
<select onchange="changePeriod()" id="period">
<option value="0">--period--</option>
<option value="1">Daily</option>
<option value="2">Weekly</option>
<option value="3">Monthly</option>
</select>
<script type="text/javascript">
function changePeriod(event) {
alert(document.getElementById("period").selectedIndex);
alert(document.getElementById("period").value);
switch (document.getElementById("period").selectedIndex) {
case 1:
alert("daily");
break;
case 2:
alert("weekly");
break;
case 3:
alert("monthly");
break;
}
}
</script>
If yes, it works for me.
Why don't you use jquery, you could do everything with less code.
EDIT:
The solution with jQuery:
$("#period").change(function(){
alert("The Value: "+$(this).val());
switch ($(this).val()) {
case 1:
alert("daily");
break;
case 2:
alert("weekly");
break;
case 3:
alert("monthly");
break;
}
});
take a look here: http://jsfiddle.net/rfWjd/
I'm learning yii framework for an e-commerce project and it was going great so far. I have an addition form for estates and that form is generating using database. The code below, generates the form (/views/ad/_form), and giving names to input fields like detail["ad-title"], detail["ad-image"] etc.
<?php
$connection = Yii::app()->db;
$command = $connection->createCommand("SELECT * FROM eml_ozellikler");
$options = $command->queryAll();
$command = $connection->createCommand("SELECT * FROM eml_kurallar");
$rules = $command->queryAll();
$i = 0;
foreach($options as $option){
echo '<div class="row">';
echo $form->labelEx($model, 'detail["'.$option['name'].'"]');
switch($option['tur']){
case "textfield":
echo $form->textField($model, 'detail["'.$option['name'].'"]');
break;
case "textarea":
echo $form->textArea($model, 'detail["'.$option['name'].'"]', array('rows'=>'5','cols'=>'40'));
break;
case "integer":
echo $form->textField($model, 'detail["'.$option['name'].'"]');
break;
case "selectbox":
CHtml::dropDownList($option['label'], 'detail["'.$option['name'].'"]', $rules[$i]['values']);
break;
case "radio":
break;
case "file":
echo $form->fileField($model, 'detail["'.$option['name'].'"]');
break;
case "image":
break;
}
echo $form->error($model,'detail["'.$option['name'].'"]');
echo '</div>';
$i++;
}
?>
The problem is when giving rules to them. Rules are working just for looking, when i add to rules this
array('detay["ad-title"]', 'required'),
Then, that field is being required and getting a (*). But when i submit the form, then it gives an error saying "Ad.detail["ad-title"]" value isn't defined.
Without rules, i can post and get the posted value correctly using $_POST['Ad']['detail']["ad-title"] etc.
Also; i checked the Yii Framework docs but couldn't find any useful thing except tabular input and Form Builder, and i couldn't implement it to my code. Because i don't want to create variables at my model, i just want to send data using just one variable and rule.
Thanks, çağlar.
I did not find any rule regarding this as you are giving.
array('detay["ad-title"]', 'required'),
if ad-title is your table field name, then you may write.
array('ad-title', 'required'),
that's it ...
otherwise you need to learn rules, below is the one of the link where you can learn.
http://www.yiiframework.com/wiki/56/
Thanks.
I created 3 language packs for my site: English, Spanish and French. I am just having trouble implementing them based on user selection. I have the following drop down menu:
<select onchange='document.location.href=this.options[this.selectedIndex].value;'>
<option>Select</option>
<option value="?lang=eng">US English</option>
<option value="?lang=esp">Español</option>
<option value="?lang=fra">Français</option>
</select>
How can I include the language files based on what the user selects, I just don't know what to put as the condition in the if statement.
Thanks.
As you're bringing in the option via a query string, you can access it with
$lang = $_GET['lang']
At first, save the value that the user selected in the user session. e.g.:
switch($_POST['lang']) {
case 'en': $_SESSION['lang'] = 'English'; break;
case 'sp': $_SESSION['lang'] = 'Spanish'; break;
default: $_SESSION['lang'] = 'English'; break;
}
On every page request, fetch the language files from the relevant language folder according to the value the you saved.
For example, this how will look the files structure:
English
Global.php
Register.php
Spanish
Global.php
Register.php
Then, whenever you need to load a text file, use:
function load_text_file($filename) {
include 'languages/' . $_SESSION['lang'] . '/' . $filename.'php';
return $txt; // $txt should be an array
}
//...
$text = array();
$text += load_text_file('Global');
$text += load_text_file('Register');
For my template, that piece of code is
$_SESSION['language'] = 'english';