I hope this is not a duplicate but I have not found it yet.
To be honest I found this method online and and cant find where I original found it or I would search there for the answer. The below is a test page I am testing my code.
My question is this how do I keep the clock value in the href and add the cellnumber to the href ?? Right now I get dropdowntest.php?cellnumber=8&?clock=8 which is the same value as the cellnumber I believe is in the line:
+ ['?cellnumber', $(this).val()].join('=') + ['&?clock', $(this).val()].join('=');
I have tried changing $(this) on the clock but I could not find the correct syntax.. below is all the code:
<?php
session_start();
require('/db_connection/connect.db.php');
require('settings.php');
?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.clock').on('change', function() {
location.href = location.href.split('?')[0]
+ ['?clock', $(this).val()].join('=');
});
$('.cellnumber').on('change', function() {
location.href = location.href.split('?')[0]
+ ['?cellnumber', $(this).val()].join('=') + ['&?clock', $(this).val()].join('=');
});
});
</script>
<?php
$clock = mysqli_query($connection, "SELECT username FROM user WHERE wocreate = 1 and hide = 1");
echo "<select class='clock' name='clock' style='width:200px'>";
echo "<option size =30 ></option>";
while($row = mysqli_fetch_array($clock)){
echo "<option value='".$row['username']."''>".$row['username']."</option>";
}
echo "</select>";
if (isset($_GET['clock'])) {
$_SESSION['clock'] = $_GET['clock'];
echo "<p></p>";
echo 'Person Requesting Ticket is '.$_SESSION['clock'].'';
echo "<p></p>";
}
?>
<?php
echo "<br>";
$cellnumbers = mysqli_query($connection, "SELECT DISTINCT location FROM machinenumber WHERE status = 1 ");
echo "<select class='cellnumber' name='cellnumber' style='width:200px'>";
echo "<option size =30 ></option>";
while($row = mysqli_fetch_array($cellnumbers)){
echo "<option value='".$row['location']."''>".$row['location']."</option>";
}
echo "</select>";
if (isset($_GET['cellnumber'])) {
$_SESSION['cellnumber'] = $_GET['cellnumber'];
echo "<p></p>";
echo 'Person Requesting Ticket is '.$_SESSION['clock'].'';
echo "<br>";
echo 'Cell '.$_SESSION['cellnumber'].' is the location';
echo "<p></p>";
}
?>
<?php
if (isset($_GET['cellnumber'])) {
$cellnumber=$_GET['cellnumber'];
echo "<h3>Choose Machine Number</h3>";
$machinenumber = mysqli_query($connection,"SELECT number FROM machinenumber WHERE location =".$cellnumber." ;");
echo "<select class='machinenumber' name='machinenumber' style=width:200px>";
echo "<option size =30 ></option>";
while($row = mysqli_fetch_array($machinenumber)) {
echo "<option value='".$row['number']."'>".$row['number']."</option>";
}
echo "</select>";
}
?>
Related
I have below code which creates drop-down from php. I want to achieve 2 things here.
1. I want to set one of the option to be set default. It may be hard coded or selected from query.
2. When hit button, it should retain selected option. I could retrieve selected option using session data with this: echo $print_version1[array_keys($print_version1)[0]];
Drop-down code:
$result = $conn->query("SELECT DISTINCT nx_version FROM workflow1 ORDER BY id DESC");
echo "<form action='http://localhost/w_5aug/process.php' method='get'>";
echo "<html>";
echo "<body>";
echo "<p></p>";
echo "<center>";
echo "<strong> Select Base Verison To Compare With : </strong>";
echo "<select name='nx_version' id='nx_version'>";
while ($row = $result->fetch_assoc()) {
$nx_version = $row['nx_version'];
echo '<option>'.$nx_version.'</option>';
}
echo "</select>";
echo " <button type='submit'><b>Add Base Verison</b></button>";
echo "</center>";
echo "</body>";
echo "</html>";
echo "<p></p>";
$array_select = $_SESSION['data'];
print_r($array_select);
echo "<form>";
i assume that the option that should be selected is$print_version1[array_keys($print_version1)[0]
while ($row = $result->fetch_assoc()) {
$nx_version = $row['nx_version'];
if($_SESSION["id"]) {
if($nx_version == "the hardcode value you want to be selected"){
echo '<option selected="selected">'.$nx_version.'</option>';
}else{
echo '<option>'.$nx_version.'</option>';
}
}else{
if($print_version1[array_keys($print_version1)[0]] == $nx_version){
echo '<option selected="selected">'.$nx_version.'</option>';
}else{
echo '<option>'.$nx_version.'</option>';
}
}
}
I have below code which creates drop-down from php. I want to achieve 2 things here.
1. I want to set one of the option to be set default. It may be hard coded or selected from query.
2. When hit button, it should retain selected option. I could retrieve selected option using session data with this: echo $print_version1[array_keys($print_version1)[0]];
Drop-down code:
$result = $conn->query("SELECT DISTINCT nx_version FROM workflow1 ORDER BY id DESC");
echo "<form action='http://localhost/w_5aug/process.php' method='get'>";
echo "<html>";
echo "<body>";
echo "<p></p>";
echo "<center>";
echo "<strong> Select Base Verison To Compare With : </strong>";
echo "<select name='nx_version' id='nx_version'>";
while ($row = $result->fetch_assoc()) {
$nx_version = $row['nx_version'];
echo '<option>'.$nx_version.'</option>';
}
echo "</select>";
echo " <button type='submit'><b>Add Base Verison</b></button>";
echo "</center>";
echo "</body>";
echo "</html>";
echo "<p></p>";
$array_select = $_SESSION['data'];
print_r($array_select);
echo "<form>";
i assume that the option that should be selected is$print_version1[array_keys($print_version1)[0]
while ($row = $result->fetch_assoc()) {
$nx_version = $row['nx_version'];
if($_SESSION["id"]) {
if($nx_version == "the hardcode value you want to be selected"){
echo '<option selected="selected">'.$nx_version.'</option>';
}else{
echo '<option>'.$nx_version.'</option>';
}
}else{
if($print_version1[array_keys($print_version1)[0]] == $nx_version){
echo '<option selected="selected">'.$nx_version.'</option>';
}else{
echo '<option>'.$nx_version.'</option>';
}
}
}
I have been trying to work this out for a while.
I have created a form with a dropdown box that gets results from a database. from this i then $_POST that from to another page. From that second page i wish to get the ID number and then get the records and display them on screen.
I will then put them in a table to organise the results better.
can anyone help me in achieving this.
Here is the code for the form (which works and sends the $PlantID)
$sql = "SELECT DISTINCT * FROM PLANTS";
$result = mysqli_query($mysqli,$sql)or die(mysqli_error());
//********************* Botannical name drop down box
echo "<form name='selection' id='selection' action='profile.php' method='post'>";
echo "<select name='flower'>";
while($row = mysqli_fetch_array($result)) {
$plantid = $row['FlowerID'];
$plantname = $row['Botannical_Name'];
$plantcommon = $row['Common_Name'];
/* $plantheight = $row['Height'];
$plantav = $row['AV'];
$plantcolours = $row['Colours'];
$plantflowering = $row['Flower_Time'];
$plantspecial = $row['Special_Conditions'];
$plantfrost = $row['Frost_Hardy'];
$plantaspect = $row['Aspect'];
$plantspeed = $row['Growth_Speed'];*/
echo "<option value=".$plantid.">".$plantname." -> AKA -> ".$plantcommon."</option>";
}
echo "</select>";
echo "<br />";
//********************* End of form
echo "<input type='submit' name='submit' value='Submit'/>";
echo "</form>";
I have created this page to get the ID and display that ID on screen. AS you can tell i have probably doubled up on ways to try work this out.
$sql = "SELECT * FROM PLANTS";
$result = mysqli_query($mysqli,$sql)or die(mysqli_error());
if(isset($_POST['submit'])){
$selected_val = $_POST['Botannical_Name']; // Storing Selected Value In Variable
echo "You have selected :" .$selected_val; // Displaying Selected Value
}
echo "<br />";
echo "well:".$_POST["Botannical_Name"]."<br/>";
echo "now:".$plantquery."<br />";
echo $_POST;
echo "<table>";
foreach ($_POST as $key => $value) {
echo "<tr>";
echo "<td>";
echo $key;
echo "</td>";
echo "<td>";
echo $value;
echo "</td>";
echo "</tr>";
}
echo "</table>";
Any help would be greatly appreciated.
you should use following to get the selected value,
$selected_val = $_POST['flower'];
if(isset($_POST['submit'])){
$selected_val = $_POST['flower']; // Storing Selected Value In Variable
echo "You have selected :" .$selected_val; // Displaying Selected Value
$sql = "SELECT * FROM PLANTS WHERE FlowerID='.$selected_val.'";
$result = mysqli_query($mysqli,$sql)or die(mysqli_error());
while ($row=mysqli_fetch_assoc($result))
{
echo $row['Botannical_Name'];
}
}
echo "<br />";
print_r($_POST);
if(!empty(_POST)) {
echo "<table>";
foreach ($_POST as $key => $value) {
echo "<tr>";
echo "<td>";
echo $key;
echo "</td>";
echo "<td>";
echo $value;
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
I have a working select that is generated by PHP.
Code:
echo "<form method='post'><select name='selectid'>";
$result_select = mysql_query("SELECT * FROM DB.Table");
while($row_select = mysql_fetch_array($result_select))
{
echo "<option ";
if ($row['Value'] == $row_select['Value'] ) echo 'selected';
echo ">{$row_select['Value']} {$row_select['Value']}
</option>";
}
echo "</select></form>";
Now the problem is, I want to $_POST the selected value from select. It is working, too. But I want to get the string without  
I have tried:
$text_description=" Helloworld! ";
$text_description = str_replace(' ', '', $text_description);
echo $text_description;
And it's working. But when I replace
$text_description=" Helloworld! ";
to
$text_description=$_POST['selectid'];
it's not working any more.
You can just add a value attribute to your options:
echo "<form method='post'><select name='selectid'>";
$result_select = mysql_query("SELECT * FROM DB.Table");
while($row_select = mysql_fetch_array($result_select))
{
echo "<option value='{$row_select['Value']}'";
if ($row['Value'] == $row_select['Value'] ) echo 'selected';
echo ">{$row_select['Value']} {$row_select['Value']}
</option>";
}
echo "</select></form>";
I have some jQuery that handles a click event on a table row,which is built with PHP, when it is clicked. It works fine as long as the table is built in the same file. It however will not work if I have jQuery go out to a PHP file, have the PHP build the table, then send the output back to be written in a div tag. I have tried adding .live to the event but that didn't work either? Any suggestions?
The html and jQuery:
<html>
<head>
<script type='text/javascript' src='jquery.js'></script>
<script type='text/javascript'>
var name;
var text;
var subject;
var id;
var key;
$(document).ready(function(){
buildMsgTable();
//Load Message Data in click
$('#messages tr').click(function(){
$(this, 'tr').each(function(index, tr) {
var lines = $('td', tr).map(function(index, td) {
return $(td).text();
});
key = lines[0];
name = lines[1];
textarea = lines[2];
subject = lines[3];
//alert(textarea);
$('#name').val(name);
$('#subject').val(subject);
$('#body').val(textarea);
})
});
function buildMsgTable(){
$.post('/php_webfiles/edit/buildMsgTable.php',
{},
function(output){ $('#existingMessagesDiv').html(output); });
}
</script>
</head>
</body>
<div id='existingMessagesDiv'></div>
<div id = 'debug'></div>
</body>
</html>
And the php called by buildMsgTable:
<?php
include "hawkfunctions.php";
$tsql = "SELECT * FROM Messages";
$conn = mssqlConnect();
$stmt = sqlsrv_query($conn, $tsql);
//$stmt2 = sqlsrv_query($conn, $tsql2);
if ($stmt1 === false) {
echo "Error in query preparation/execution (contacts_in_list).<br/>$tsql1<br/>";
//die( print_r( sqlsrv_errors(), true));
echo "Errors while connecing attempting to run query:<br/><ol>";
$i = 1;
foreach (sqlsrv_errors() as $masterError) {
$errorlist .= "<li>Heading $i<ol>";
foreach ($masterError as $root => $error) {
if (!is_numeric($root)) {
$errorlist .= "<li><b>$root:</b> $error</li>\n";
}
}
$errorlist .= "</ol></li>\n";
$i++;
}
$errorlist .= "</ol>";
die($errorlist);
}
echo "<table border='1' id= 'messages'><th>Key</th><th>Name</th><th>Text</th><th>Subject</th>";
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC)){
echo "<tr><td class='key'>";
echo $row['MessageKey'];
echo "</td>";
echo "<td class = 'name'>";
echo $row['Name'];
echo "</td><td class = 'text'>";
echo $row['Text'];
echo "</td><td class = 'subject'>";
echo $row['Subject'];
echo "</td>";
echo "<td class = 'delete'>";
echo "<input type='button' value='Delete' id='delete' onclick='deleteMessage(".$row['MessageKey'].")' />";
echo "</td>";
echo "</tr>";
}
/* Free statement and connection resources.*/
sqlsrv_free_stmt( $stmt);
sqlsrv_close($conn);
echo "</table>";
?>
Think I cut out all the fluff that doesn't pertain to my question.