i am searching for a way to pass variable ($result[1]) to a session variable from while loop within a link. will be glad for some help
while ($result = mysqli_fetch_array($dataset,MYSQLI_NUM)){
echo "<tr>";
echo " <td >", "<a href='Rate_Supplier.php'>" . $result[1] ."
</a>","</td>" ;
echo " <td >" . $result[0] . "</td>" ;
echo " <td >" . $result[2] . "</td>" ;
echo "</tr>\n";
}
Related
I'm trying to make a way to take a certain quantity of a product from all displayed from the database, for example I want to take 3 out of 5 possible ones with me but I have no idea what I need to add to make it so, right now it displays the data like this:
foreach ($order->get_items() as $item ){
$unitprice = $item->get_total() / $item->get_quantity();
echo "<input type='checkbox' name='productinfo[]' value='" .$item->get_name() . "|" . $item->get_quantity() . "|" . $item->get_total() ."'>";
echo '<p>';
echo __('Product name: ' ) . $item->get_name() . '<br>';
if($item->get_quantity() > 1) {
echo "Amount: " . "<input type='number' name='numberqty' value='" . $item->get_quantity() . "'max='" .$item->get_quantity() . "' min='0' > " . "<br/>";
}
else {
echo __('Amount: ' ) . $item->get_quantity() . '<br>';
}
echo __('Product individual price: ') . $unitprice . '€' . '<br/>';
echo __('Product total: ' ) . wc_price($item->get_total()) . '</p>' . '<br/>';
}
echo '<p>'. __('Order total: ') . $order->get_total() . '</p>';
I'm not very good at making questions so ask if something is unclear.
When I echo this table :
echo "<table class='aTable' border='1'>
<tr>
<th>ID</th>
<th>Nombre</th>
<th>Apellido</th>
<th>Telefono</th>
<th>Fecha</th>
<th>Ver Orden</th>
</tr>";
while($row = $gsent->fetch(PDO::FETCH_ASSOC))
{
echo "<tr>";
echo "<td>" . $row['IdOrder'] . "</td>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['Apellido'] . "</td>";
echo "<td>" . $row['Phone'] . "</td>";
echo "<td>" . $row['TimeStamp'] . "</td>";
echo "<td>" ."<input type='submit' name='ID' value='VER' onclick='showOrder({$row['IdOrder']})'>"."</td>";
echo "</tr>";
}
echo "</table>";
I want the last column to show a button which triggers a Javascript function
<script>
function showOrder(IdOrder){
jQuery('#list-data').val(IdOrder);
document.getElementById("formOrder").submit();
console.log('PHP: ' + IdOrder );
var delayMillis = 500;
setTimeout(function() {
window.location.href = 'ask.php';
}, delayMillis);
}
</script>
Everything works fine when the button $row['IdOrder'] contains a number, eg 1521 or 00254 but when it has a hexadecimal number it wont work or behaves in a strange way eg on ADAC in
chrome console this error shows up:
Uncaught ReferenceError: ADAC is not defined
at HTMLInputElement.onclick
Or if the Hex is 39E3 the function runs but I get this number in the function 39000 which I dont know why but is correct because in google if I put 39E3 to decimal I get that number but I dont want the 39E3 to convert itself to 39000 so my guess is that the variable $row['IdOrder'] is beeing Treated different if its start with a number or with a letter, I want $row['IdOrder'] always be treated like a text to avoid this weird conversions if its possible or maybe, do
I have to take another path?
If your IdOrder is not a number-only value, you have to wrap it with quotes, to become a string:
"<input type='submit' name='ID' value='VER' onclick='showOrder(\"{$row['IdOrder']}\")'>"
It should print something like:
<input type='submit' name='ID' value='VER' onclick='showOrder("myId")'>
So the compiler won't try to guess that ADAC is an object instead of a string.
Replace
{$row['IdOrder']}
with
\"{$row['IdOrder']}\"
to make it a string.
I need to exicute one JS function after another sequencually. I can exicute these functions individually and they work but when I put them in a sequence I only get the openPatient() and the openMessage() does not exicute. My JS functions
function openPatient() {
myRestoreSession();
opener.top.RTop.document.location.href = '../patient_file/summary/demographics.php?set_pid=<?php echo attr($ptid); ?>';
}
function openMessage(messageid) {
myRestoreSession();
document.location.href = 'upload_form.php?messageid=' + messageid;
}
My function call:
echo " onclick=\"openPatient().then(openRequest(" .
"'" . addslashes($postid) . "'," .
"'" . addslashes($v1[1]['type']) . "'" .
"))\">" . text($v1[1]['datetime']) . "</td>\n";
This function call exists in this process:
<?php
// Generate a table row for each pending portal request or message.
// This logic merges requests with messages by date.
$v1 = each($result['list']);
$v2 = each($result['messages']);
while ($v1 || $v2) {
echo " <tr class='detail' bgcolor='#ddddff'>\n";
if (!$v2 || $v1 && $v1[1]['datetime'] < $v2[1]['datetime']) {
$postid = $v1[1]['postid'];
$ptname = patientNameFromLogin($v1[1]['user']);
// Get the portal request data.
if (!$postid) die(xlt('Request ID is missing!'));
$result2 = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
if ($result2['errmsg']) {
die(text($result2['errmsg']));
}
// Look up the patient in OpenEMR.
$ptid = lookup_openemr_patient($result2['post']['user']);
echo " <td>" . text($v1[1]['user']) . "</td>\n";
echo " <td style='cursor:pointer;color:blue;' onclick=\"openPatient()\">" .text($ptname ) . "</td>\n";
echo " <td style='cursor:pointer;color:blue;'";
echo " onclick=\"openPatient().then(openRequest(" .
"'" . addslashes($postid) . "'," .
"'" . addslashes($v1[1]['type']) . "'" .
"))\">" . text($v1[1]['datetime']) . "</td>\n";
echo " <td>" . text($v1[1]['type' ]) . "</td>\n";
echo " <td align='center'><input type='checkbox' name='form_req_cb[" .
attr($postid) . "]' value='" . attr($postid) . "' /></td>\n";
$v1 = each($result['list']);
}
else {
$messageid = $v2[1]['messageid'];
$ptname = patientNameFromLogin($v2[1]['user']);
echo " <td>" . text($v2[1]['user']) . "</td>\n";
echo " <td>" . text($ptname ) . "</td>\n";
echo " <td style='cursor:pointer;color:blue;'";
echo " onclick=\"openMessage(" .
"'" . addslashes($messageid) . "'" .
")\">" . text($v2[1]['datetime']) . "</td>\n";
echo " <td>" . text($v2[1]['user'] == $v2[1]['fromuser'] ?
xl('Message from patient') : xl('Message to patient')) . "</td>\n";
echo " <td align='center'><input type='checkbox' name='form_msg_cb[" .
attr($messageid) . "]' value='" . attr($messageid) . "' /></td>\n";
$v2 = each($result['messages']);
}
echo " </tr>\n";
}
?>
I am thinking part of the problem may be that openPatient() opens in another window. Perhaps it is loosing focus. Any tips to fix this would be appreciated.
EDIT:
What I have tried and helps is adding return this; to openPatient():
function openPatient() {
myRestoreSession();
opener.top.RTop.document.location.href = '../patient_file/summary/demographics.php?set_pid=<?php echo attr($ptid); ?>';
return this;
}
This then executes the next function but the next function executes too soon. it needs to wait for openPatient() to fully load before executing openMessage(). I have tried adding setTimeout( wait, 1000 ); but then openMessage() does not execute at all.
The solution:
The call:
echo " <td style='cursor:pointer;color:blue;'";
echo " onclick=\"openPatient();setTimeout(function(){openRequest(" .
"'" . addslashes($postid) . "'," .
"'" . addslashes($v1[1]['type']) . "'" .
")}, 2500);\">" . text($v1[1]['datetime']) . "</td>\n";
The functions:
function openPatient() {
myRestoreSession();
opener.top.RTop.document.location.href = '../patient_file/summary/demographics.php?set_pid=<?php echo attr($ptid); ?>';
return this;
}
function openMessage(messageid) {
myRestoreSession();
document.location.href = 'upload_form.php?messageid=' + messageid;
}
Keys to success: return this; and the use of the anonymous function with setTimeout in the call.
Posts that helped:
What does "return this" do within a javascript function?
setTimeout delay not working
With research, I was able to come up with a neat way to display information in my database into a php page.
Now my next aim is to link each row to another php page that will recognize what account ID the user has clicked
echo "<table border='1'>
<tr>
<th>Account ID</th>
<th>Account Username</th>
<th>Account Password</th>
<th>Account First Name</th>
<th>Account Middle Name</th>
<th>Account Last Name</th>
<th>Account Phase</th>
<th>Account Block - Lot</th>
<th>Account Subdivision</th>
<th>Account Contact Number</th>
<th>Account Email Address</th>
<th>Account Status</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['acc_no'] . "</td>";
echo "<td>" . $row['acc_user'] . "</td>";
echo "<td>" . $row['acc_pass'] . "</td>";
echo "<td>" . $row['acc_fname'] . "</td>";
echo "<td>" . $row['acc_mname'] . "</td>";
echo "<td>" . $row['acc_lname'] . "</td>";
echo "<td>" . $row['acc_phase'] . "</td>";
echo "<td>" . $row['acc_blk-lot'] . "</td>";
echo "<td>" . $row['acc_subd'] . "</td>";
echo "<td>" . $row['acc_contact_num'] . "</td>";
echo "<td>" . $row['acc_email_address'] . "</td>";
echo "<td>" . $row['acc_status'] . "</td>";
echo "</tr>";
}
echo "</table>";
I tried this echo "<td><a href='target php page here'>" . $row['acc_no'] . "</td>" but all the links generated will have the same value. I think JQuery might be needed for this or something but unfortunately, this stuff is not yet taught in our school or there might be a better work around for my problem. please help.
I am not sure how to integrate the logic inside a While loop, I mean
as long as the loop is not finished, does this mean the $_GET or
$_POST will loop with it?
while($row = mysql_fetch_array($result))
{
echo "<tr>";
// Step 1.
// Create a custom URL that points to this same script,
// passing the account number as a $_GET parameter.
echo '<td>' . $row['acc_no'] . "</td>";
echo "<td>" . $row['acc_user'] . "</td>";
echo "<td>" . $row['acc_pass'] . "</td>";
echo "<td>" . $row['acc_fname'] . "</td>";
echo "<td>" . $row['acc_mname'] . "</td>";
echo "<td>" . $row['acc_lname'] . "</td>";
echo "<td>" . $row['acc_phase'] . "</td>";
echo "<td>" . $row['acc_blk-lot'] . "</td>";
echo "<td>" . $row['acc_subd'] . "</td>";
echo "<td>" . $row['acc_contact_num'] . "</td>";
echo "<td>" . $row['acc_email_address'] . "</td>";
echo "<td>" . $row['acc_status'] . "</td>";
echo "</tr>";
// Step 2.
// Check if the user has already clicked a one of the URLs we custom made in step 1.
if (isset($_GET['id'] && $_GET['id'] == $row['acc_no']){
// the user has, so let's allow them to change the fields.
// This form appears directly under the record that was clicked.
echo '<form action="commitChangesScript.php" method="post">';
echo '<input type="text" name="fname">';
//repeat for any fields you want to be able the change.
// ...
echo '</form>';
}
}
First create the custom URLs, this can be done without a form by simply creating a link to the location with a query string at the end of it.
On the first page load, isset($_GET['id'] will never be true, because the user presumably hasn't selected an account yet. The first page load create the table as well as all the links for specific users. The URLs are unique because they are created using the account number. For account #1, the URL is pointed at thisScript.php?id=1, for account #987 the URL is thisSciprt.php?id=987.
When the user selects an account number, a new form appears allowing them to change fields. This works because $_GET['id'] will be set to the account number that was selected. We can compare that input with the field in the DB allowing all other rows not to have the form.
This is just an example of what would work. The form included would interrupt the <table> which might look kind of gross.
does this mean the $_GET or $_POST will loop with it?
$_GET and $_POST are defined outside of the while, meaning they will not be repeatedly defined. They are however, within scope inside the while loop as demonstrated in the example I've shown.
Hello fellow programmers!
I'm working on a personal project (mainly to learn php/javascript) and have ran into an issue with redirection when clicking on a link. I have a bit of a strange situation on a tabbed page I've created and I think that may be what is causing my problem.
I'm trying to allow the user to click the (which due to css has made it look different than normal ) to redirect them to a new page with more details. I THINK that the second tag on my page is what is throwing me off because I have a form in it.
I have tried tons of different things like window.location.href="", location.href="", document.location="", etc... But the same thing always occurs. I am able to get both alert messages, so I know I am getting into my JavaScript (even when I put it into it's own .js file).
Anyway advice/help would be very helpful. Also, if anyone has a suggestion on cleaning this code up a bit, that would also be truly helpful.
Below is basically what I have.
Thanks in advance for your help!
<html>
<head>
<title>test site</title>
<link rel="stylesheet" href="test.css" type="text/css" media="screen" />
<script src="test.js" type="text/javascript"></script>
<script type="text/javascript">
function viewDetails(modelId){
alert(modelId);
window.location.href="new url?ModelID=" + modelId;
alert('redirecting would be way awesome...');
}
</script>
</head>
<body onload="load()">
<div id="tabbed_box_1" class="tabbed_box">
<h4>Navigation Tabs<small>Select a tab</small></h4>
<div class="tabbed_area">
<?php
mysql_connect('host','user','password');
mysql_select_db("database");
echo "<ul class='tabs'>";
echo "<li><a href='javascript:tabSwitch(1, 2);' id='tab_1' class='active'>Inventory</a></li>";
echo "<li><a href='javascript:tabSwitch(2, 2);' id='tab_2' >Add Project</a></li>";
echo "</ul>";
echo "<div id='content_1' class='content'>";
echo "<ul>";
$modelsSQL = "SELECT * FROM Model ORDER BY Name";
$modelsResult = mysql_query($modelsSQL);
while ($modelRow = mysql_fetch_array($modelsResult)){
$modelID = $modelRow[0];
$sqlAvailCount = "SELECT * FROM Project WHERE ModelID = " . $modelID . " AND Sold = 0";
$sqlSoldCount = "SELECT * FROM Project WHERE ModelID = " . $modelID . " AND Sold = 1";
$resultAvailCount = mysql_query($sqlAvailCount);
$resultSoldCount = mysql_query($sqlSoldCount);
$rowAvailCount = mysql_num_rows($resultAvailCount);
$rowSoldCount = mysql_num_rows($resultSoldCount);
echo "<li><a href='' onclick='javascript:viewDetails($modelID);'>" . $modelRow[1] . "<small>in stock: <value>"
. $rowAvailCount . "</value> sold: <value>" . $rowSoldCount . "</value></small></a></li>";
}
echo "</ul>";
echo "</div>";
echo "<div id='content_2' class='content'>";
echo "<form action='project_insert.php' method='post' name='projectAddForm'>";
echo "<table cellpadding='5'>";
// Project Model Selection
echo "<tr><td>";
echo "<label for='model'>Model</label>";
echo "</td><td>";
echo "<select name='model' style='width: 250px;'>";
echo "<option value='-1' selected>SELECT</option>";
$modelListSQL = "SELECT * FROM Model ORDER BY Name";
$modelListResult = mysql_query($modelListSQL);
while ($modelListRow = mysql_fetch_array($modelListResult)){
echo "<option value='" . $modelListRow['ID'] . "'>" . $modelListRow['Name'] . "</option>";
}
echo "</select>";
echo "</td></tr>";
// Project Material Selection
echo "<tr><td>";
echo "<label for='material'>material</label>";
echo "</td><td>";
echo "<select name='material' style='width: 250px;'>";
echo "<option value='-1' selected>SELECT</option>";
$materialListSQL = "SELECT * FROM Material ORDER BY Name";
$materialListResult = mysql_query($materialListSQL);
while ($materialListRow = mysql_fetch_array($materialListResult)){
echo "<option value='" . $materialListRow['ID'] . "'>" . $materialListRow['Name'] . "</option>";
}
echo "</select>";
echo "</td></tr>";
// Project Finish Selection
echo "<tr><td>";
echo "<label for='finish'>finish</label>";
echo "</td><td>";
echo "<select name='finish' style='width: 250px;'>";
echo "<option value='-1' selected>SELECT</option>";
$finishListSQL = "SELECT * FROM Finish ORDER BY Name";
$finishListResult = mysql_query($finishListSQL);
while ($finishListRow = mysql_fetch_array($finishListResult))
{
echo "<option value='" . $finishListRow['ID'] . "'>" . $finishListRow['Name'] . "</option>";
}
echo "</select>";
echo "</td></tr>";
// Project Craftsman Selection
echo "<tr><td>";
echo "<label for='craftsman'>craftsman</label>";
echo "</td><td>";
echo "<select name='craftsman' style='width: 250px;'>";
echo "<option value='-1' selected>SELECT</option>";
$craftsmanListSQL = "SELECT * FROM Craftsman ORDER BY FirstName";
$craftsmanListResult = mysql_query($craftsmanListSQL);
while ($craftsmanListRow = mysql_fetch_array($craftsmanListResult)){
echo "<option value='" . $craftsmanListRow['ID'] . "'>" . $craftsmanListRow['FirstName'] . " " . $craftsmanListRow['LastName'] . "</option>";
}
echo "</select>";
echo "</td></tr>";
//Project Description
echo "<tr><td>";
echo "<label for='description'>Description</label>";
echo "</td><td>";
echo "<input type='text' name='description' id='textArea' style='width:250px'>";
echo "</td></tr>";
// Project Selling Price
echo "<tr><td>";
echo "<label for='price'>Price</label>";
echo "</td><td>";
echo "<input id='price' name='price' type='number' style='width:150px'>";
echo "</td></tr>";
// Project Completion Date
echo "<tr><td>";
echo "<label for='date'>Finish Date</label>";
echo "</td><td>";
$dateArray = getdate();
$month = $dateArray[mon];
$day = $dateArray[mday];
if ($month < 10){
$month = '0' . $dateArray[mon];
}
if ($day < 10){
$day = '0' . $dateArray[mday];
}
$todaysDate = $dateArray[year] . '-' . $month . '-' . $day;
echo "<input type='date' name='date' value='" . $todaysDate . "' style='width:150px'>";
echo "</td></tr>";
// Buttons
echo "<tr><td align='center'>";
echo "<input type='button' name='Save' value='Save' onclick='javascript:validateAndSubmit(this.form);' style='width:100px'>";
echo "</td><td align='center'>";
echo "<input type='button' name='Cancel' value='Cancel' onclick='javascript:cancelEntry();' style='width:100px'>";
echo "</td></tr>";
echo "</table>";
echo "</form>";
echo "</div>";
?>
</div>
</div>
</body>
window.location.href may not trigger reload in some browsers and cases..
You should add a reload after
like this:
window.location.href = '/foo/bar/';
window.locaton.reload(true)
But, some browsers delay milliseconds to perform location.href set. In this cases the window.location.reload(true) may complete before this.
Therefore, add a timeout in reload:
window.location.href = '/foo/bar/';
setTimeout('window.locaton.reload(true)', 500);
works in all browsers for me
Good morning! I found the cause of my problem this morning and have been able to resolve the issue. The problem I was causing is because I am using the tag (stylized by css) to display the information, with an onclick event to call my JS code to redirect. Within the tag I had the href='', thinking that the JS would override that functionality, it doesn't!
Removing the href='' from the tag resolved the issue and allowed me to redirect to the new page. A second solution is to use my php code to dynamically create the href link within the tag.
echo "<li><a onclick='viewDetails($modelID);'>" . $modelRow[1] . "<small>in stock: <value>" . $rowAvailCount . "</value> sold: <value>" . $rowSoldCount . "</value></small></a></li>";
OR
echo "<li><a href='inventorydetails.php?ModelID=" . $modelID . "'>" . $modelRow[1] . "<small>in stock: <value>" . $rowAvailCount . "</value> sold: <value>" . $rowSoldCount . "</value></small></a></li>";
I think I will go with the second example for two reasons. First, it provides the link icon when hovering (which I know I can add through css, but this is easier. Second, less JS code.
I thank you for all your help in resolving this!