I am try this code
<script>
var rightNow = new Date();
var jan1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);
var temp = jan1.toGMTString();
//document.hari.maliya.value=temp;
//alert(temp);
document.write(temp);
<script>
But i want in php file
You have to pass this value to your php-script as a cookie, http-parameter or with an ajax-call.
hi i solved this question answer :
<script>
$(document).ready(function() {
var rightNow = new Date();
//alert(temp);
document.harimaliya.timezone.value=rightNow;
});
</script>
and html code is:
<form name="harimaliya" id="harimaliya" action="" method="post">
time zone :<input type="text" name="timezone" id="timezone" value='' size="50"/>
<input type="submit" value="Test Diffrent time Zone" name="timezonetest" id="timezonetest">
</form>
PHP Code Calaculate diff between two Time Zone:
<?php
if(isset($_POST['timezonetest']))
{
echo "User Time Zone -:"." ".$usertimezone = "(GMT-12:00)-International Date Line West";
echo "<br>";
$usertimezone = substr ($usertimezone, 1,9);
echo $usertimezone= str_replace(':',"",$usertimezone);
echo "<br>";
echo date(strtotime("$usertimezone"));
echo "<br>";
echo "System Time Zone -:"." ".$systemtimezone= $_POST['timezone'];
$systemtimezone = strstr($systemtimezone, 'G');
echo "<br>";
echo $systemtimezone = substr ($systemtimezone, 0,8);
echo "<br>";
echo date(strtotime("$systemtimezone"));
echo "<br>";
echo $diff=date(strtotime("$usertimezone"))-date(strtotime("$systemtimezone"));
echo "<br>";
echo $diff=($diff/60)." "."minits";
echo "<br>";
echo $diff=($diff/60);
}
?>
Related
I want to use the value from my first dropdown in a MySQL query to generate a second dropdown. I'm doing this in wordpress and have tried to modify code I have used for a form plugin to apply to a coded form. But the code I have doesn't populate the second dropdown.
<form id="page-changer" action="" method="post"> <?php
$chart_types = $wpdb->get_results( "SELECT page_id, title FROM master_chart WHERE mod_id=$mod_id AND (geo_type=$geo_type OR geo_type IS NULL) ORDER BY sequence" );
echo '<select id="chart_type" required style="width: 100%; margin-bottom: 15px;"><option value="" disabled selected>Select Chart Type</option>';
foreach ($chart_types as $chart_type) :
echo '<option value="'.$chart_type->page_id.'">'.$chart_type->title.'</option>';
endforeach;
echo '</select>'; ?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#chart_type').change(function(){
var chartPOP=jQuery('#chart_type').val();
jQuery('#response').empty();
jQuery.ajax({
url:"<?php bloginfo( 'wpurl' ); ?>/wp-admin/admin-ajax.php",
type:'POST',
data:'action=populate_chart&pageID=' + chartPOP,
success:function(results) {
jQuery('#response').append(results);
}
});
});
});
</script> <?php
echo '<select id="response"><option value="" disabled selected>Select Frequency</option></select>';
function populate_chart() {
if( isset( $_POST['pageID'] ) ) :
$page_id=$_POST['pageID'];
global $wpdb;
$frequencies = $wpdb->get_results( "SELECT title FROM master_chartmeta WHERE measure >= $measure_toggle AND page_id=$page_id");
foreach( $results as $rows ) :
$option .= '<option value="'.$rows->title.'">';
$option .= $rows->title;
$option .= '</option>';
endforeach;
echo $option;
die();
endif;
}
add_action( 'wp_ajax_nopriv_populate_chart', populate_chart );
add_action( 'wp_ajax_populate_chart', populate_chart );
So I'm trying to merge two solutions together to form one..
I've been using the code from this answer to remove the "(Incl. Tax)" from the product page option selector for configurable products, and it works well.
As shown in the linked answer, in app/design/frontend/rwd/myTheme/template/catalog/product/view/type/configurable.phtml i've changed the line
<script type="text/javascript">
var spConfig = new Product.Config(<?php echo $this->getJsonConfig(); ?>);
</script>
to the following:
<?php // get current drop down string
$currentstring = $this->getJsonConfig();
// create new string with true set to false using str_replace function (string replace)
$newstring = str_replace( '"showBothPrices":true,"','"showBothPrices":false,"', $currentstring );?>
<!-- render dropdown but with new var ($newstring) -->
<script type="text/javascript">
var spConfig = new Product.Config(<?php echo $newstring ?>);
</script>
This has the desired result of hiding the (Incl. tax) and makes me happy.
Later, I was asked if we could change the text in the select box from reading "Choose an option" to the name of the option or "Select (option name):"
I found the following answer which works perfectly - it replaces the complete contents of the same file with
<?php
$_product = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());?>
<?php if ($_product->isSaleable() && count($_attributes)):?>
<dl>
<?php foreach($_attributes as $_attribute): ?>
<dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt>
<dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
<div class="input-box">
<?php $chooseText = $this->__('Select %s', $_attribute->getLabel()); ?>
<select data-choose-text="<?php echo $chooseText; ?>" name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
<option><?php echo $chooseText; ?></option>
</select>
</div>
</dd>
<?php endforeach; ?>
</dl>
<script type="text/javascript">
Product.ConfigDefaultText = new Class.create(Product.Config, {
fillSelect: function($super, element) {
$super(element);
var chooseDefaultText = element.getAttribute('data-choose-text');
$(element).options[0] = new Option(chooseDefaultText, '');
}
});
var spConfig = new Product.ConfigDefaultText(<?php echo $this->getJsonConfig() ?>);
</script>
Now this works great, we can set the option labels to anything we like, but in the process our "(Incl. tax)" returned to ruin my day.
I'm looking for someone to show me how i can merge these two bits of code and make them play nicely together so I can have both custom product option text and prevent the "(Incl. tax)" string from appearing.
Any help most appreciated.
Found my own solution:
Firstly, scrap the code from the first answer, use the code from the second, and then change your varien/configurable.js (or for better better form, create an overridden version) as follows:
var str = option.label;
if(price){
if (this.taxConfig.showBothPrices) {
//CHANGE THIS
//str+= ' ' + this.formatPrice(excl, true) + ' (' + this.formatPrice(price, true) + ' ' + this.taxConfig.inclTaxTitle + ')';
// TO THIS:
str+= ' ' + this.formatPrice(price, true);
} else {
str+= ' ' + this.formatPrice(price, true);
}
}
return str;
i have try multiple ways but i need to update an specific row from an existing user by a webform i have try this code but i have some thing wrong on the code.
<?php
session_start();
include_once 'dbconnect.php';
if(!isset($_SESSION['user']))
{
header("Location: index.php");
}
$res=mysql_query("SELECT * FROM users WHERE user_id=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);
while($row = mysqli_fetch_array($result)){
echo '<form action="" method="post">';
echo '<div style="float:left">';
echo '<table border="1" bordercolor="#000000">';
echo '<tr>';
echo '<td>link</td>';
echo '<td><input type="text" name="user_wallet" value="'.$row['user_wallet'].'"></td>';
echo '</tr>';
echo '</table></div>';
echo '</form><br /><br /><br /><br /><br /><br /><br /><br />';
}
}
if(isset($_POST['update'])){
$user_wallet = $_POST['user_wallet'];
$sql = mysqli_query("UPDATE users SET user_wallet = '$user_wallet' WHERE id = '$id'");
$retval = mysqli_query( $sql, $con );
if(! $retval ){
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
}
?>
My code is to fetch questions of users saved in the database by a foreach loop and let the admin answer each question and save the answer of each question after checking of validation rules in the database , Here we go :
Model is :
public function get_questions(){
$this->db->select('id,user_name, question, date');
$this->db->order_by("id", "desc");
$query=$this->db->get('t_questions');
return $query->result();
}
My view is:
foreach ($questions as $id => $row) :
?>
<?php
echo "<h5>".$row->question;
echo "<br>";
echo "from : ".$row->user_name."</h5>";
echo date('Y-m-d H:i');
echo "<br>";
$q_no='save'.$row->id;
$ans_no='answer'.$row->id;
echo "<h4> Answer:</h4>";
echo form_open('control_panel');
?>
<textarea name='<?php echo 'answer'.$row->id; ?>' value="set_value('<?php echo 'answer'.$row->id; ?>')" class='form-control' rows='3'> </textarea>
<input type='hidden' name='<?php echo $q_no ; ?>' value='<?php echo $q_no; ?>' />
<input type='hidden' name='<?php echo $ans_no ; ?>' value='<?php echo $ans_no ; ?>' />
<?php
echo form_error($ans_no);
echo "
<div class='form-group'>
<div >
<label class='checkbox-inline'>
<input type='checkbox' name='add_faq' value='yes' />
Adding to FAQ page .
</label>
</div>
</div>
<p>";
?>
<input type='submit' name='<?php echo 'save'.$row->id; ?>' value='<?php echo 'save'.$row->id; ?>' class='btn btn-success btn-md'/>
<?php
echo 'answer'.$row->id;
?>
<hr>
<?php endforeach; ?>
and my controller is :
$this->load->model('control_panel');
$data['questions']=$this->control_panel->get_questions();
$data['no_of_questions']=count($data['questions']);
if($this->input->post($q_no))
{
$this->form_validation->set_rules($ans_no,'Answer','required|xss_clean');
if($this->form_validation->run())
{
/* code to insert answer in database */
}
}
of course it did not work with me :
i get errors :
Severity: Notice
Message: Undefined variable: q_no
i do not know how to fix it
I am using codeigniter as i said in the headline.
In your controller on your post() you have a variable called q_no you need to set variable that's why not picking it up.
I do not think name="" in input can have php code I think it has to be text only.
Also would be best to add for each in controller and the call it into view.
Please make sure on controller you do some thing like
$q_no = $this->input->post('q_no');
$ans_no = $this->input->post('ans_no');
Below is how I most likely would do lay out
For each Example On Controller
$this->load->model('control_panel');
$data['no_of_questions'] = $this->db->count_all('my_table');
$data['questions'] = array();
$results = $this->control_panel->get_questions();
foreach ($results as $result) {
$data['questions'][] = array(
'question_id' => $result['question_id'],
'q_no' => $result['q_no'],
'ans_no' => $result['ans_no']
);
}
//Then validation
$this->load->library('form_validation');
$this->form_validation->set_rules('q_no', '', 'required');
$this->form_validation->set_rules('ans_no', '', 'required');
if ($this->input->post('q_no')) { // Would Not Do It This Way
if ($this->form_validation->run() == TRUE) {
// Run Database Insert / Update
// Redirect or load same view
} else {
// Run False
$this->load->view('your view', $data);
}
}
Example On View
<?php foreach ($questions as $question) {?>
<input type="text" name="id" value="<?php echo $question['question_id'];?>"/>
<input type="text" name="q_no" value"<?php echo $question['q_no'];?>"/>
<input type="text"name="a_no" value="<?php echo $question['a_no'];?>"/>
<?php }?>
Model
public function get_questions(){
$this->db->select('id,user_name, question, date');
$this->db->order_by("id", "desc");
$query=$this->db->get('t_questions');
return $query->result_array();
}
The code below is the display of search result of my project. The code below will display more than 1 row of result which I will put a link to every $value['name'] to proceed to the next page. I need to get which link is clicked and I need to get the $value['name'] which corresponds to the link clicked. Can someone help me please.
<div id="searchBox">
<?php
foreach( $row as $value ) // VALUE IS A ROW
{?>
<?php echo " Name: ";
?> <a href='<?php echo base_url()."main/moreinfo" ?>'><?php echo $value['name']; ? ></a>
<?php
echo '<p>';
echo " Type: ";
echo $value['type'];
echo '<p>';
echo "________________________________________________________________________";
echo '<p>';
}
?>
</div>
You achieve this adding an id $value['id'] to your <a href>. Then you are able to query more info in your controller, after the link was clicked:
<div id="searchBox">
<?php
foreach( $row as $value ) {
$url=base_url( "main/moreinfo/".$value['id'] );
echo 'Name: ';
echo '<a href='.$url.'>'.$value['name'].'</a>';
echo '<p>';
echo ' Type: ';
echo $value['type'];
echo '<p>';
echo '____________________________________________________________';
echo '<p>';
}
?>
</div>