Removing an option from dropbox after selected - php

I have a state guessing guess I wrote. I'm trying to remove a capital from the dropbox menu after it has been guessed. Any clues on how to go about doing that?
I have a comment on line 44 which is code that I believe may work but I havent been able to get working.
Thanks for reading and thanks in advance!
Heres my code:
<?php
require_once "include/session.php";
if (!isset($session->valid)) {
header("location: login.php");
exit();
}
require_once "include/city_info.php";
/* DO NOT MODIFY THE ABOVE LINES !!!!! */
$states = array_keys($state_capitals);
$capitals = array_values($state_capitals);
$cities = array_merge($capitals, $other_cities);
sort($cities);
$params = (object) $_REQUEST;
if (isset ($params->guess) ) {
$state = $session->statename;
$capital = $params->city;
$city = $params->city;
$session->guess ++ ;
//if they guess correctly
if ($capital == $state_capitals[$session->statename]){
$response = "You've Guessed Correct After $session->guess Guesses";
}
//if they guess incorrectly
else {
$response = " You've Guessed Wrong $session->guess Times";}
}
else {
$index = rand( 0, count($states)- 1 );
$state = $states[ $index ];
$city = $state_capitals[ $state ];
$session->statename = $state;
$guess = (0);
$session->guess = (0);
$response = "Try To Get Less Than 3 Guesses";
// create initial selections
//$session->selections = array();
// foreach($city as $value) {
// $session->selections[$value] = 1;
//}
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta http-equiv="Cache-Control"
content="no-cache, max-age=0, no-store, must-revalidate" />
<title>State Capital Guessing Game</title>
<style type="text/css">
body {
background-color:#ffff4d;
}
div {
position:center;
width: 350px;
padding: 10px;
border: 3px solid black;
border-radius: 10px;
color: black;
background-color:#3399ff;
}
}
h1{
padding:5px;
}
h2 {
text-align: center;
font-size:20px;
}
h3 {
text-align:center;
}
h4 {
text-align:center;
}
h5 {
position: absolute;
top:0px;
right:0px;
}
#logout {
position: absolute;
top: 0px;
right: 0px;
}
</style>
</head>
<body>
<a id="logout" href="logout.php">Log out</a>
<h1>
State Capital Guess Game
<form action="program.php" method="get">
<button type="submit">Reset</button>
</h1>
</form>
<div>
<form action="program.php" method="post">
<input type="hidden" name="answer" value="<?php echo $state?>" />
<h2>
Guess the capital of: <?php echo "$session->state" ?>
</h2>
<h3>
<select name="city">
<?php
$options = "";
foreach ($cities as $value){
$options .= '<option value="' . $value . '"';
if ($value == $params->city)
$options .= ' selected';
$options .= '>' . $value . '</option>';
}
echo $options;
?>
</select>
<input type="submit" name="guess" value="Guess" />
</form>
</h3>
<h4><?php echo $response ?></h4>
</div>
<h5><?php echo "The Correct Answer Is: $state_capitals[$state]" ?><h5>
</body>
</html>​

Related

I got a problem with select option and value

I try to keep the value from selected options after the button is clicked.
For now, I have done this with my inputs(range,text) and it's working but I can't figure how to do this with my select option.
ADDITIONAL THINGS(you have to create them to run it)
c13ustawienia.php
<?php
$serwer='localhost';
$uzytk='root';
$haslo='';
$baza='komis';
?>
c13dane.txt
1993|Volkswagen|Passat|19000
1973|Opel|Blitz|12000
1997|Volkswagen|Passat|17000
2010|Mercedes|M5|29000
2001|Volkswagen|Passat|29000
1990|Volkswagen|Passat|23000
2018|Tesla|Super|129000
2018|sla|Super|9000
1992|Volkswagen|Passat|10000
2006|Audi|B9|74000
2009|Volkswagen|Passat|89000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Baza</title>
<style>
table {border-collapse: collapse;}
td,th {border: 1px blue solid;}
th {background-color: azure;}
.id {width: 20px; text-align: center;}
.mar {width: 90px;}
.mod {width: 70px;}
.rok {width: 40px; text-align: right;}
.cena {width: 50px; text-align: right;}
.zolty {background-color: yellow;}
.pomar {background-color:orange;}
[type=text] {width:60px;}
header {height: 60px; background-color:greenyellow;}
header>img {height: 75%; text-align: center;}
nav {height: 400px; width: 30%; background-color:khaki;
float: left;}
main {height: 400px; width: 70%; background-color:moccasin;
float: left;}
footer {height: 40px; background-color: powderblue;
clear: both; text-align: center; color:blue;}
</style>
<script>
function wartosc() {
min=document.getElementById('cmin');
max=document.getElementById('cmax');
wmin=document.getElementById('wmin');
wmax=document.getElementById('wmax');
minint=parseInt(min.value);
maxint=parseInt(max.value);
if(maxint<minint)
maxint=minint+1;
wmin.value=minint;
min.value=minint;
wmax.value=maxint;
max.value=maxint;
}
</script>
</head>
<body>
<?php
function tworz_baze() {
require('c13ustawienia.php');
$link=mysqli_connect($serwer, $uzytk, $haslo);
mysqli_query($link, "DROP DATABASE $baza");
mysqli_query($link, "CREATE DATABASE $baza");
mysqli_query($link, "USE $baza");
mysqli_query($link, "CREATE TABLE auta (
ID int(8) NOT NULL AUTO_INCREMENT PRIMARY KEY,
marka varchar(20),
model varchar(25),
rok int(4),
cena double)");
return $link;
} // tworz_baze()
function czytajdane($plik) {
$f=fopen($plik, 'r');
while(!feof($f)) {
$linia=rtrim(fgets($f));
if(strlen($linia)>5)
$tab[]=explode('|', $linia);
}
return $tab;
} // czytajdane($plik)
function dobazy($link, $tablica) {
foreach ($tablica as $sam) {
list($rok, $mar, $mod, $cena)=$sam;
mysqli_query($link, "INSERT INTO auta VALUES
(NULL, '$mar', '$mod', $rok, $cena)");
}
} // dobazy($link, $tablica)
function pisz($li, $marka, $cenamin, $cenamax) {
echo "<h3>Wybrano:<br>marka: $marka<br>
zakres cen: $cenamin - $cenamax zł</h3>";
echo "<table>
<tr><th>id</th><th>marka</th><th>model</th>
<th>rok</th><th>cena</th></tr>";
$wyn=mysqli_query($li, "SELECT * FROM auta WHERE
marka='$marka' AND cena>=$cenamin AND cena<=$cenamax");
$licznik=FALSE;
while($wiersz=mysqli_fetch_array($wyn)) {
list($id, $mar, $mod, $rok, $cena)=$wiersz;
$kolor = $licznik ? 'zolty' : 'pomar';
echo "<tr class=\"$kolor\"><th class=\"id\">$id</td>
<td class=\"mar\">$mar</td>
<td class=\"mod\">$mod</td>
<td class=\"rok\">$rok</td>
<td class=\"cena\">$cena</td></tr>";
$licznik=!$licznik;
}
echo '</table>';
mysqli_close($li);
} // pisz($li, $model, $cenamax)
function filtry() {
if(isset($_GET['cmin']))
$tab['cmin']=$_GET['cmin'];
else
$tab['cmin']=0;
if(isset($_GET['cmax']))
$tab['cmax']=$_GET['cmax'];
else
$tab['cmax']=CENAMAKS;
if(isset($_GET['marka']))
$tab['marka']=$_GET['marka'];
else
$tab['marka']='Volkswagen';
return $tab;
} // filtry()
function lista($link) {
$w=mysqli_query($link, "SELECT DISTINCT marka
from auta ORDER BY marka");
while($m=mysqli_fetch_array($w))
echo '<option value="'.$m['marka'].'">'
.$m['marka'].'</option>';
// $x=$m['marka'];
// "<option value=\"$x\">....
} // lista($link)
?>
<header>
<img src="auto.png" alt="auto">
<span>Komis samochodowy</span>
</header>
<nav>
<h3>Filtry:</h3>
<form action="c41.php" method="GET">
Cena:<br>
od: <input type="range" name="cmin" id="cmin"
min="0" max="<?php echo CENAMAKS ?>" value="<?php echo $tf['cenamin'];?>"
onchange="wartosc()">
<br>
do :<input type="range" name="cmax" id="cmax"
min="0" max="<?php echo CENAMAKS ?>"
value="<?php echo $tf['cenamin'];?>"
onchange="wartosc()">
<br>
<input type="text" name="wmin" id="wmin" disabled
value="<?php echo $tf['cenamin'];?>"
> -
<input type="text" name="wmax" id="wmax" disabled
value="<?php echo $tf['cenamax'];?>"
><br>
<select name="marka" id="marka">
<?php lista($li); ?>
</select>
<input type="submit" value="Filtruj">
<input type="reset" value="Czyść">
</form>
</nav>
<main>
<?php pisz($li, $tf['marka'], $tf['cmin'], $tf['cmax']); ?>
</main>
<footer>
Adam Kowal ©
</footer>
</body>
</html>
To make inputs work I have giving them variable of function and pointed right key of database to have what I want, but i have no clue how to make it work with select option
frame of code that gives me what i want in inputs: value="<?php echo $tf['cenamin'];?>"
Change your code with the following:
First add a new parameter to the "lista" function to be able to mark the selected value, e.g.
function lista($link, $selected = "default") {
// function code here
}
Secondly, modify the function to respect the passed value and match it to the value gotten from the database:
while($m=mysqli_fetch_array($w)) {
$status = "";
if ($selected == $m['marka']) $status = "selected";
echo '<option '.$selected.' value="'.$m['marka'].'">' .$m['marka'].'</option>';
}
Thirdly, pass the selected value to the function in your code, e.g.:
<?php lista($li, $_GET['marka']); ?>
NB! You should NOT use your current code in any production environments: it includes several SQL injections and isn't built up by best practises (e.g. separating html from the program code etc).

How can I save my previous dice rolls when I refresh the page?

So I have to roll 6 six sided die and display their corresponding images. I also have to save up to 10 previous roles and append the new ones each time I roll. I'm so far able to create the array of 6 random numbers and link them to their images. I just need to save that role on page refresh. I've just started learning PHP but from what I've gathered I know sessions are needed. All the examples I looked at didn't help.
<?php
// Start the session
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dice Roller</title>
</head>
<style>
h1, input {
margin-left: auto;
margin-right: auto;
}
img {
width: 70px;
height: 70px;
}
</style>
<body>
<h1>Dice Roller</h1>
<input type="button" value="Roll">
<?php
$newRoll = array(rand(1, 6), rand(1, 6), rand(1, 6), rand(1, 6), rand(1, 6), rand(1, 6));
$oldRoll = $newRoll;
foreach($newRoll as $num) {
echo '<img src="img/dicefaces/dice0' . $num . '.png" alt="">';
}
echo "<br>";
foreach($oldRoll as $num) {
echo '<img src="img/dicefaces/dice0' . $num . '.png" alt="">';
}
?>
</body>
</html>
You can use $_SESSION to 'store' the old rolls, following logic might help you on your way:
We store the history in $_SESSION['oldrolls'] allowing us to display up to 10 previous rolls (you can set the number you want to show with $max)
Also created a button to allow for session clear, to start with a clean slate.
<?php
// Start the session
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dice Roller</title>
</head>
<style>
table, td, th {
table-layout: fixed;
width: 100%;
border-collapse: collapse;
border: 3px solid black;
text-align: center;
}
h1, input {
margin-left: auto;
margin-right: auto;
}
img {
width: 70px;
height: 70px;
}
</style>
<body>
<h1>Dice Roller</h1>
<!-- allow user to clear the session -->
<form action='' method ='POST'>
<input type="submit" name='clear' value="clear session">
</form>
<!-- submit a roll -->
<br />
<form action='' method ='POST'>
<input type="submit" name='submit' value="Roll">
</form>
<?php
if(isset($_POST['clear'])){
$_SESSION = []; // clear session array
}
if(isset($_POST['submit'])) {
$newRoll = array(rand(1, 6), rand(1, 6), rand(1, 6), rand(1, 6), rand(1, 6), rand(1, 6));
$max = 10; // store up to 10 previous rolls
$count = isset($_SESSION['oldrolls']) ? count($_SESSION['oldrolls']) : 0;
if($count <= $max) {
$_SESSION['oldrolls'][] = $newRoll; // add new
} else {
array_shift($_SESSION['oldrolls']); // remove oldest
$_SESSION['oldrolls'][] = $newRoll; // add new
}
$_SESSION['oldrolls-reverse'] = array_reverse($_SESSION['oldrolls']); // show last first
echo 'Current roll...';
echo '<br />';
foreach ($newRoll as $num) {
echo $num;
echo '<br />';
}
echo "<br>";
echo 'previous rolls...';
echo '<br />';
echo '<table>';
foreach ($_SESSION['oldrolls-reverse'] as $key => $num) {
if($key === 0) continue;
echo '<tr>';
foreach($num as $roll) {
echo '<td>' . $roll . '</td>';
}
echo '</tr>';
}
echo '</table>';
}
?>
</body>
</html>

if isset $_POST output fail

I'm trying to create a banning system for a chat that I made and it has a separate "console" only seen by admins. Im using Mac OS 10.11.4, I am the owner and am using Mamp with php version 5.6.10
Ban.php
<?php
$ban = $_POST['ban'];
$mybfile = fopen("banned.txt", 'a');
$txtb = ($ban." , ");
//Makes sure ip banned it not an admins
if (isset($_POST['ban'])) {
//example ip addresses
if ($ban === '1.1.1.1' || 192.168.1.132) {
echo 'Can\'t ban an Admin';
} else {
echo 'IP banned';
fwrite($mybfile, $txtb);
fclose($mybfile);
}
}
?>
<style>
.ban {
background-color: black;
width:30em;
height:5em;
color: #7ACC52;
}
.buttonBAN {
border:1px solid black;
width: 85px;
height: 55px;
background-color: white;
color: black;
position: absolute;
}
</style>
<body>
<form method="POST">
BanCMD<br />
<input type="text" name="ban" class="ban">
<input type="submit" value="Enter" class="buttonBAN">
</form>
</body>
Chat.php:
<?php
require "blocked.php";
require "connect.inc.php";
require "core.inc.php";
require "commands.php";
$sent = $_POST['chat'];
$myfile = fopen("chat.txt", 'a') or die("Unable to open file!");
$txt = ($sent."\n");
$first = getuserfield('username');
$active = ($first.":".$ip_addr);
$activef = fopen("ip-user.txt", 'a');
$myFile = "domains/domain_list.txt";
if (loggedin()) {
echo 'Welcome, '.$first,'<br />';
if ($first != 'SnR' || 'Koi') {
fwrite($activef, $active."\n"."=");
}
} else if (!loggedin()) {
die('Not logged in');
}
if (isset($_POST['chat'])) {
if (!empty($sent)) {
fwrite($myfile, $first.': '.$txt.'=');
fclose($myfile);
} else if (empty($sent)) {
echo 'Cant send an empty message','<br />';
}
}
$file = "chat.txt";
$linecount = 0;
$handle = fopen($file, "r");
while(!feof($handle)){
$line = fgets($handle);
$linecount++;
}
fclose($handle);
if ($linecount > 49) {
unlink($file);
} else {
echo 'Line count: '.$linecount,'<br />';
}
echo 'Chat will reset at 50 lines','<br />';
echo 'Your IP:';
echo $ip_addr,'<br />';
?>
<html>
<head>
</head>
<body>
<!-- <a href='active.txt'>Online users</a><br /> -->
<iframe id='reload' src='refresh.php'>
<fieldset class="field">
<div id="list"><p><?php
$filename = 'chat.txt';
$handle = fopen($filename, 'r');
$detain = fread($handle, filesize($filename));
$chat_array = explode('=', $detain);
foreach($chat_array as $chat) {
echo $chat.'<br />';
}
?></p></div>
</fieldset>
</iframe>
<form action="chat.php" method="POST">
<input type="text" name="chat" class="textbox">
<input type="submit" value="Send" class="button">
</form>
</body>
</html>
<?php
if ($first == 'SnR' && 'Koi') {
include 'AdminCMD.php';
include 'ban.php';
?>
<iframe id='reload' src='refresh2.php' class="field2">
<fieldset class="field">
</fieldset>
</iframe>
<?php
}
?>
The problem is that everything is fine until you give an input, no matter what you put into the box the output is always "Can't ban an Admin" meaning that it doesn't write to the given file
Thank you for any help.
Your code contains an error, preventing the file from being written. The first line of PHP code,$ban = $_POST['ban'];, could fail if no post data was sent. You need to first check if the $_POST['ban'] was set. A fixed version of your code can be found below.
<?php
//Makes sure ip banned it not an admins
if (isset($_POST['ban'])) {
$ban = $_POST['ban'];
$mybfile = fopen("banned.txt", 'a');
$txtb = ($ban." , ");
if ($ban === '1.1.1.1') {
echo 'Can\'t ban an Admin';
} else {
echo 'IP banned';
fwrite($mybfile, $txtb);
fclose($mybfile);
}
}
?>
<style>
.ban {
background-color: black;
width:30em;
height:5em;
color: #7ACC52;
}
.buttonBAN {
border:1px solid black;
width: 85px;
height: 55px;
background-color: white;
color: black;
position: absolute;
}
</style>
<body>
<form method="POST">
BanCMD<br />
<input type="text" name="ban" class="ban">
<input type="submit" value="Enter" class="buttonBAN">
</form>
</body>
When i ran your code it returns undefined index ban, you can try this and make sure what is not working for you.
<?php
$ban = isset($_POST['ban']) ? $_POST['ban'] : null;
$mybfile = fopen("banned.txt", 'a');
$txtb = ($ban." , ");
//Makes sure ip banned it not an admins
if(isset($ban)){
if ($ban === '1.1.1.1') {
echo 'Can\'t ban an Admin';
} else {
echo 'IP banned';
fwrite($mybfile, $txtb);
fclose($mybfile);
}
}
?>
<style>
.ban {
background-color: black;
width:30em;
height:5em;
color: #7ACC52;
}
.buttonBAN {
border:1px solid black;
width: 85px;
height: 55px;
background-color: white;
color: black;
position: absolute;
}
</style>
<body>
<form method="POST">
BanCMD<br />
<input type="text" name="ban" class="ban">
<input type="submit" value="Enter" class="buttonBAN">
</form>
</body>

Php dropdown menu from another file

I'm trying to create a state capital guessing game where a state will randomly generate and then from the dropdown list which contains all the capitals the user will have to guess the capital. Anyway, he wants us to have a separate file with an array. The file is called city_info.php and the arrays look like this
$state_capitals = array(
'Alabama' => 'Montgomery',
I'm having trouble getting the drop down list populate with all the capitals.
<?php
require_once "include/session.php";
if (!isset($session->valid)) {
header("location: login.php");
exit();
}
require_once "include/city_info.php";
/* DO NOT MODIFY THE ABOVE LINES !!!!! */
$states = array_keys($state_capitals);
$capitals = array_values($state_capitals);
$cities = array_merge($capitals, $other_cities);
sort($cities);
$params = (object) $_REQUEST;
print_r($params);
if (isset($params->guess)) {
$state_capitals = $params->capitals;
$answer = $params->answer;
$cities = $params->city;
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta http-equiv="Cache-Control"
content="no-cache, max-age=0, no-store, must-revalidate" />
<title>State Capital Guess Game</title>
<style type="text/css">
body {
padding: 10px 20px;
}
#logout {
position: absolute;
top: 40px;
right: 40px;
}
div {
width: 320px;
padding: 10px;
border: 3px solid black;
border-radius: 10px;
color: black;
text-align:center;
background-color:#3399ff;
display:inline-block
}
/*
More style rules
*/
</style>
<script type="text/javascript">window.onunload = function(){}</script>
</head>
<body>
<a id="logout" href="logout.php">Log out</a>
<h2>State Capital Guess Game</h2>
<form action="program.php" method="get">
<button type="submit">Start Over</button>
</form>
<!--- computational form -->
<div>
<p>What is the Capital of PA</p>
<select name="cities">
<?php
foreach ($city as $value):
?>
<option <?php
if ($value == $params->city)
echo "selected";
?>
><?php
echo $value;
?></option>
<?php
endforeach;
?>
</select>
<input type="submit" name="choose" value="Choose" />
</form>
</div>
<?php
echo $state_capitals;
?>
</body>
</html>
The way you phrase your question, this sounds like it could be homework. Many people on SO are glad to help with homework, however, some are not; so as a courtesy when asking a question about homework follow these guidelines: https://meta.stackexchange.com/questions/10811/how-do-i-ask-and-answer-homework-questions. You may already know this, but wanted to cover the basics just in case.
On to your question. I'll clean things up a bit so it's not so hard to follow the HTML/PHP. This should work if you substitute your current code:
<select name="cities">
<?php
$options = "";
foreach ($cities as $value){
$options .= '<option value="' . $value . '"';
if ($value == $params->city)
$options .= ' selected';
$options .= '>' . $value . '</option>';
}
echo $options;
?>
</select>
This way you're only switching between HTML/PHP once. Hope that helps!

Load Google Maps on webpage using Javascript and PHP through drop down form

I am having two drop down lists on a html page. The data is coming from a mysql database and contains information like latitude, longitude and address. The user selects one item from the drop down and clicks on submit.
At this stage, I want to display a google map and put a marker at the latitude and longitude. Then, when the user selects the option from second drop down, I want to just add a marker on that map.
Currently, I am able to load the map once he clicks the submit from first drop down but all the options I tried to drop the pins are not working.
Here is the code I have achieved till now:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once('auth.php');
include ('LoginConfig.php');
include ('FetchAgentDetails.php');
include ('FetchDeliveryDetails.php');
?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Delivery Management System</title>
<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyA0Rm5aK0BYu1f_TzhjkG97cchHHlQfrQY&sensor=false">
</script>
<style type="text/css">
html {height:100%}
body {height:100%;margin:0;padding:0}
#googleMap {height:100%}
</style>
<script>
function initialize()
{
var mapProp = {
center:new google.maps.LatLng(51.508742,-0.120850),
zoom:5,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap")
,mapProp);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<style type="text/css">
<!--
.style1 {
font-size: 20px;
font-weight: bold;
}
-->
</style>
<style type="text/css">
table.collection {width:250px;border:2px solid black;border-style: outset;border-collapse:collapse;}
table.collection tr {background-color:#fff; border-bottom: 1px #99b solid;padding:10px;}
table.collection tr:hover {background-color:#ffe;}
table.collection td {display:table-cell;border-bottom: 1px #99b solid; padding:10px;}
table.collection td a {text-decoration:none; display:table-row; padding:0px; height:100%;}
</style>
</head>
<body bgcolor="#8E8E38"
<div style="clear: right;">
<p align="left" class="style1">Welcome Delivery Manager! </p>
<img style="position: absolute; top: 0; right: 0;" src="./Images/logo.jpg" alt="Company Logo" width="90" height="60" align="middle"></img>
</div>
<p align="left">Home</p>
<hr></hr>
<!-- START Main Wrap -->
<form method="post">
<fieldset>
<div style="clear: left;float:left;">
<label for="deliveryList">Delivery Items:</label>
<select name="deliveryList" id="deliveryList">
<option value="Select delivery item" selected="selected">Select delivery item</option>
<?php
$deliveryHandler = new FetchDeliveryDetails();
$itemNameArray = $deliveryHandler->getItemNames();
foreach ($itemNameArray as $innerArray) {
if (is_array($innerArray)) {
$value = $innerArray['itemName'];
echo "<option value=\"$value\"";
if (isset($_POST['deliveryList']) && $_POST['deliveryList'] == $value)
echo 'selected';
echo ">" . $value . "</option>\n";
}
}
?>
</select>
<input type="submit" name="submit" id="submit" value="Submit"/>
</div>
<div style="clear: right;float:right;">
<label for="agentList">Avaliable Agent:</label>
<select name="agentList" id="agentList">
<option value="" selected="selected">Select agent to assign</option>
<?php
$agentHandler = new FetchAgentDetails();
$agentNameArray = $agentHandler->getAgentNames();
foreach ($agentNameArray as $innerArray) {
if (is_array($innerArray)) {
$agentId = $innerArray['agentId'];
$firstNameValue = $innerArray['firstname'];
$lastNameValue = $innerArray['lastname'];
$fullName = $firstNameValue . ' ' . $lastNameValue;
echo "<option value=\"$agentId\">$fullName</option>\n";
}
}
?>
</select>
<input type="submit" name="agentSubmit" id="agentSubmit" value="Check Location"/>
</div>
</fieldset>
</form>
<?php
if (isset($_POST['deliveryList'])) {
$selectedItemName = $_POST['deliveryList'];
$deliveryHander = new FetchDeliveryDetails();
$itemDetailsArray = $deliveryHander->getAllDeliveryDetails($selectedItemName);
foreach ($itemDetailsArray as $valuesArray) {
$itemNameValue = $valuesArray['itemName'];
$itemDescriptionValue = $valuesArray['itemDescription'];
$ownerFirstname = $valuesArray['firstName'];
$ownerLastname = $valuesArray['lastName'];
$dateAdded = $valuesArray['dateAdded'];
$deliveryDate = $valuesArray['deliveryDate'];
$deliveryAddress = $valuesArray['deliveryAddress'];
$deliveryLatitude = $valuesArray['deliveryLatitude'];
$deliveryLongitude = $valuesArray['deliveryLongitude'];
$assignedAgent = $valuesArray['assignedAgentId'];
if ($assignedAgent == 0) {
$assignedAgent = "-";
}
echo "<table border=\"1\" align=\"left\" class =\"collection\">\n";
echo "<tr>\n";
echo "<td >Item Name:<b>$itemNameValue</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Item Description: <b>$itemDescriptionValue</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Owner Name: <b>$ownerFirstname $ownerLastname</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Date Added: <b>$dateAdded</td>\n";
echo "</tr>\n";
echo "<tr>";
echo "<td>Delivery Date: <b>$deliveryDate</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Delivery Address: <b>$deliveryAddress</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Assigned Agent: <b>$assignedAgent</td>";
echo "</tr>";
echo "</table>";
echo "<div id=\"googleMap\" style=\"width:500px;height:380px;\"></div>";
}
}
if (isset($_POST['agentList'])) {
}
?>
</body>
</html>
I almost forgot, this is my first PHP application, in fact my first web application. So please go easy on me. Point out other errors also, but please stick to the question.
Ok got it working by using iframe :) and a bit of php
Reference:
http://www.youtube.com/watch?v=HTm-3Cduafw
echo "<iframe style =\"display: block;
width: 800px;
padding-top: 2px;
height: 400px;
margin: 0 auto;
border: 0;\" width=\"425\" height=\"350\" align=\"center\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\"
src=\"https://maps.google.com/maps?f=d&source=s_d&saddr=$agent_map_url&
daddr=$map_url&hl=en&z=10&t=m&mra=ls&ie=UTF8&output=embed\"></iframe><br/>";

Categories