dropdown on custom shipping method magento - magento-1.9

I want to add a dropdown at checkout page which has option of pick up time and pickupdate. currently I added shipping methods in dropdown I want to add pick up date and time instead of it.
<?php if (($_shippingRateGroups = $this->getEstimateRates())): ?>
<form id="co-shipping-method-form-drop" action="<?php echo $this->getUrl('checkout/cart/estimateUpdatePost') ?>">
<select id='drop_estimate_method' name="estimate_method">
<option value='-1'>Please Select Shipping Method</option>
<?php
foreach ($_shippingRateGroups as $code => $_rates) {
$str = $this->getCarrierName($code);
foreach ($_rates as $_rate){
$str2 = $str . ' - ' . $_rate->getMethodTitle();
$_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax());
$_incl = $this->getShippingPrice($_rate->getPrice(), true);
$str2 .= ' ['. $_excl;
if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl) {
$str2 .= ' '. $this->__('Incl. Tax'); echo $_incl;
}
$str2 .= '] ';
?>
<option <?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' selected="selected"' ?> value="<?php echo $this->htmlEscape($_rate->getCode()) ?>"><?php echo $str2;?></option>
<?php }
} ?>
</select>
</form>
<script type="text/javascript">
document.observe("dom:loaded", function() {
$('drop_estimate_method').observe('change',function(){
if($('drop_estimate_method').getValue() == -1){
alert('Please Select Shipping Method');
}else{
$('co-shipping-method-form-drop').submit();
}
});
});
</script>
<?php endif; ?>

Related

Trying to echo a table but it's not working

The table is called bookings. I'm trying to echo rows from the table, but I'm getting errors in some places according to user_id. Dreamweaver tells me the last few lines have errors, but I'm not sure what's the problem.
<?php
require 'connect.php';
include("auth.php");
$user = $_SESSION['username'];
$uid = $_SESSION['user_id'];
$sql = "SELECT * FROM bookings WHERE user_id =". $uid;
$result = mysqli_query($conn, $sql);
if ($result->num_rows > 0) { // if the mysqli_query performed above works
echo "<br>";
echo '<table border="1">';
echo '<tr>
<th>booking_id</th>
<th>"Room_name"</th>
<th>"booking_date"</th>
<th>"period_name"</th>
<th>"booking_id"</th>
<th>"Cancel Booking"</th>
</tr>';
while ($row = mysqli_fetch_assoc($result)) { // important line
echo '<tr>';
echo '<td>'.$row["booking_id"].'</td>';
echo '<td>'.$row["Room_name"].'</td>';
echo '<td>'.$row["booking_date"].'</td>';
echo '<td>'.$row["date_booked"].'</td>';
echo '<td>'.$row["period_name"].'</td>';
echo '<td>'.$row["booking_id"].'</td>';
echo "</tr>";
echo "</table>";
}
else echo '<p>You have no bookings.</p>';
I have made some change
And here is the code-
require 'connect.php';
include 'auth.php';
$user = $_SESSION['username'];
$uid = $_SESSION['user_id'];
$sql = "SELECT * FROM bookings WHERE user_id ='". $uid."'";
$result = mysqli_query($conn, $sql);
if ($result->num_rows > 0) { // if the mysqli_query performed above works
echo "<br>";
echo '<table border="1">';
echo '<tr>
<th>booking_id</th>
<th>Room_name</th>
<th>booking_date</th>
<th>period_name</th>
<th>booking_id</th>
<th>Cancel Booking</th>
</tr>';
while ($row = mysqli_fetch_assoc($result)) { // important line
echo '<tr>';
echo '<td>'.$row["booking_id"].'</td>';
echo '<td>'.$row["Room_name"].'</td>';
echo '<td>'.$row["booking_date"].'</td>';
echo '<td>'.$row["date_booked"].'</td>';
echo '<td>'.$row["period_name"].'</td>';
echo '<td>'.$row["booking_id"].'</td>';
echo '</tr>';
}
echo '</table>';
} else echo '<p>You have no bookings</p>';

show/hide button not working

I am creating a php page which shows mcq questions with options and answers from database. Here i am using a html button for show/hide answers. but its working only for the first question but while clicking on other questions it works for the first question only. kindly help
<script>
function myFunction() {
var x = document.getElementById('myDIV');
if (x.style.display === 'none') {
x.style.display = 'block';
} else {
x.style.display = 'none';
}
}
</script>
<?php
while($row = mysqli_fetch_array($result))
{
echo "<h4 style=font-weight:bold; text-align:justify>";
echo "Q $row[slno]) $row[question]";
echo "</h4><br>";
echo "<ul class=list-group>";
echo "<li class=list-group-item>1) $row[option1]</li>";
echo "<li class=list-group-item>2) $row[option2]</li>";
echo "<li class=list-group-item>3) $row[option3]</li>";
echo "<li class=list-group-item>4) $row[option4]</li>";
echo "<li class=list-group-item>5) $row[option5]</li>";
echo "<div id=myDIV style=display:none><li class=list-group-item><b>Correct Option : ($row[correct_option])</b></div></li>";
echo "<li class=list-group-item><button onclick=myFunction()>View Answer</button></li>";
echo "</ul>";
echo "<hr color=#FF0000 size=5 width=100%>";
}
?>
Any suggestions...
Try this..
<script>
function myFunction(num) {
var x = document.getElementById('myDIV'+num);
if (x.style.display === 'none') {
x.style.display = 'block';
} else {
x.style.display = 'none';
}
}
</script>
<?php
$num=1;
while($row = mysqli_fetch_array($result))
{
echo "<h4 style=font-weight:bold; text-align:justify>";
echo "Q $row[slno]) $row[question]";
echo "</h4><br>";
echo "<ul class=list-group>";
echo "<li class=list-group-item>1) $row[option1]</li>";
echo "<li class=list-group-item>2) $row[option2]</li>";
echo "<li class=list-group-item>3) $row[option3]</li>";
echo "<li class=list-group-item>4) $row[option4]</li>";
echo "<li class=list-group-item>5) $row[option5]</li>";
echo "<div id=myDIV".$num." style=display:none><li class=list-group-item><b>Correct Option : ($row[correct_option])</b></div></li>";
echo "<li class=list-group-item><button onclick=myFunction('".$num."')>View Answer</button></li>";
echo "</ul>";
echo "<hr color=#FF0000 size=5 width=100%>";
$num++;
}
?>
Try this:
Your Id must be unique for each records.
<script>
function myFunction(elem) {
var x = document.getElementById('myDIV'+elem);
if (x.style.display === 'none') {
x.style.display = 'block';
} else {
x.style.display = 'none';
}
}
</script>
<?php
while($row = mysqli_fetch_array($result))
{
echo "<h4 style=font-weight:bold; text-align:justify>";
echo "Q $row[slno]) $row[question]";
echo "</h4><br>";
echo "<ul class=list-group>";
echo "<li class=list-group-item>1) $row[option1]</li>";
echo "<li class=list-group-item>2) $row[option2]</li>";
echo "<li class=list-group-item>3) $row[option3]</li>";
echo "<li class=list-group-item>4) $row[option4]</li>";
echo "<li class=list-group-item>5) $row[option5]</li>";
echo "<div id=myDIV'".$row['slno']."' style=display:none><li class=list-group-item><b>Correct Option : ($row[correct_option])</b></div></li>";
echo "<li class=list-group-item><button onclick=myFunction('".$row['slno']."')>View Answer</button></li>";
echo "</ul>";
echo "<hr color=#FF0000 size=5 width=100%>";
}
?>

Setting User based preferences in PHP using Cookies

I'm doing an assignment where I need to be able to change the color of ones log in page according to preference. Now I have been able to successfully do that BUT no matter what I do the color will not take up the whole page only around the FORM itself leaving the rest white, can you please tell me where I have made the mistake? Please see my coding below:
<?php
include('session.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>Your Home Page</title>
</head>
<body>
<div id="profile">
<b id="welcome">Welcome : <i><?php echo $login_session; ?></i></b>
<b id="logout">Log Out</b>
<?php
$red = "";
$blue = "";
$green = "";
$gold = "";
$silver = "";
$purple = "";
$hour = time() + 3600;
if (isset($_POST['order']))
{
$color = $_POST['order'];
$$color = " selected";
setcookie("Free_cookies", $color, $hour);
}
else if(isset($_COOKIE['Free_cookies']))
{
$color = $_COOKIE['Free_cookies'];
$$color = " selected";
}
else
{
$color = "red";
$red = " selected";
}
$red = "";
$blue = "";
$green = "";
$gold = "";
$silver = "";
$purple = "";
$hour = time() + 3600;
// first check for a new value, and use it as well as saving it for next time
if (isset($_POST['order']))
{
$color = $_POST['order'];
$$color = " selected";
setcookie("Free_cookies", $color, $hour);
}
// if there's no new value, THEN check for a previous value in a cookie
else if(isset($_COOKIE['Free_cookies']))
{
$color = $_COOKIE['Free_cookies'];
$$color = " selected";
}
// otherwise default to red
else
{
$color = "red";
$red = " selected";
}
?>
<form method='post' <?php echo "STYLE='background-color:".$color.";'";?> ><p id='txtorder' >color: </p>
<select name='order' id='order'>
<option value="red" <?php echo $red; ?> >red</option>
<option value="blue" <?php echo $blue; ?> >blue</option>
<option value="green" <?php echo $green; ?> >green</option>
<option value="gold" <?php echo $gold; ?> >gold</option>
<option value="silver" <?php echo $silver; ?> >silver</option>
<option value="purple" <?php echo $purple; ?> >purple</option>
</select>
<input type='submit' value='sort'/>
</form>
</div>
</body>
</html>

HTML select option values from mysql db via php are not coming properly inside the tag

I am creating a html form, in which select dropdown is used.
The values in select are coming from MySql db using PHP.
The problem is, the values from DB are not coming inside the select options, but printing outside of it, while i am writing code like this:
$result = mysqli_query($link,$sql);
if ($result != 0) {
echo '<select name="name" >';
$num_results = mysqli_num_rows($result);
for ($i=0;$i<$num_results;$i++) {
$row = mysqli_fetch_array($result);
$name = $row['name'];
echo '<option value="' .$name. '">' .$name. '</option>';
}
echo '</select>';
}
But when i put one more select, the values comes inside of the select options.
$result = mysqli_query($link,$sql);
if ($result != 0) {
#Extra select#
echo '<select>';
##############
echo '<select name="name" >';
$num_results = mysqli_num_rows($result);
for ($i=0;$i<$num_results;$i++) {
$row = mysqli_fetch_array($result);
$name = $row['name'];
echo '<option value="' .$name. '">' .$name. '</option>';
}
echo '</select>';
}
But of-course, there is one select box coming for no use.
What is wrong in this code ?

Unable to display post titles with SQL Tables

I'm trying to display a list of titles in a modify/delete page. They load fine since I get the correct amount of rows, put for some reason I can't the text printed.
Here's the function which corresponds to the issue.
function manage_content()
{
echo '<div id="manage">';
$sql = "SELECT * FROM content";
$res = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($res)): ?>
<div>
<h2 class="title"><?php $row['title'] ?></h2>
<span class="actions">Edit | Delete</span>
</div> <?php
endwhile;
echo '</div>'; //End of Manage Div
}
And this is the full code:
<?php
class blog {
private $host;
private $username;
private $password;
private $db;
private $link;
public function __construct($host, $username, $password, $db){
$this->db = $db;
$this->link = mysql_connect($host, $username, $password, $db);
mysql_select_db($this->db, $this->link) or die (mysql_error());
}
function get_content($id=''){
if($id !=NULL):
$id = mysql_real_escape_string($id);
$sql = "SELECT * FROM content WHERE id = '$id'";
$return = '<p>Vover al Indice</p>';
else:
$sql = "SELECT * FROM content ORDER by id DESC";
endif;
$res = mysql_query($sql) or die (mysql_error());
if(mysql_num_rows($res) !=NULL):
while($row = mysql_fetch_assoc($res)){
echo '<h1>'.$row['title'].'</h1>';
echo '<p>'.$row['body'].'</p>';
}
else:
echo '<p>Oops, post not found!</p>';
endif;
if(isset($return)){
echo $return;
}
}
function add_content($p){
$title = mysql_real_escape_string($p['title']);
$body = mysql_real_escape_string($p['body']);
if(!$title OR !$body):
if(!$title):
echo "<p>You have to fill the title.</p>";
endif;
if(!$body):
echo "<p>You have to fill the body.</p>";
endif;
echo '<p>Try again!</p>';
else:
$sql = "INSERT INTO content VALUES (null, '$title', '$body')";
$res = mysql_query($sql) OR DIE (mysql_error());
echo "Added sucessfully!";
endif;
}
function manage_content()
{
echo '<div id="manage">';
$sql = "SELECT * FROM content";
$res = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($res)): ?>
<div>
<h2 class="title"><?php $row['title'] ?></h2>
<span class="actions">Edit | Delete</span>
</div> <?php
endwhile;
echo '</div>'; //End of Manage Div
}
}// End of Class
?>
You're forgetting an echo in your manage_content() function:
<?php $row['title'] ?>
Should be:
<?php echo $row['title']; ?>
That's part of the problem anyway.