I want to use query and query2 two different select queries together.
How to use it and execute?
Here is my code
$query2 = "SELECT advance FROM transaction WHERE adv_date=now()";
$query = "SELECT SUM(s.total) AS totalamount FROM sale s JOIN product p ON ( s.pr_id = p.pr_id ) WHERE s.customer_name = '$customer'";
$result = mysqli_query($connect, $query);
$result2 = mysqli_query($connect, $query2);
$output = '';
if (mysqli_num_rows($result) > 0) {
$i = 0;
while ($row = mysqli_fetch_array($result)) {
$output .= '<h4 style="display: inline;" align="right"> ' . $row["totalamount"] . '</h4><br> ';
$output .= ' ';
$i++;
}
} else {
$output .= '<tr>
<td colspan="5">No Order Found</td>
</tr>';
}
$output .= '<h4 style="display:inline;" align="right"> ' . $row["total"] . '</h4><br> ';
echo $output; ?>
try this one it will help you
$sql = "SELECT Lastname FROM Persons ORDER BY LastName;";
$sql .= "SELECT Country FROM Customers";
// Execute multi query
if (mysqli_multi_query($con,$sql))
{
do
{
// Store first result set
if ($result=mysqli_store_result($con)) {
// Fetch one and one row
while ($row=mysqli_fetch_row($result))
{
printf("%s\n",$row[0]);
}
// Free result set
mysqli_free_result($result);
}
}
while (mysqli_next_result($con));
}
I'm not sure if i understood your question right, but i created a function to execute both of your queries, by passing them through the parameter of the function.
function commitQuery($query){
$result = mysqli_query($connect, $query);
$output = '';
if(mysqli_num_rows($result) > 0) {
$i=0;
while($row = mysqli_fetch_array($result)) {
$output .= '<h4 style="display:inline;" align="right"> '. $row["totalamount"] .'</h4><br>';
$output .= '';
$i++;
}
} else {
$output .= '
<tr>
<td colspan="5">No Order Found</td>
</tr>';
}
$output .= '<h4 style="display:inline;" align="right"> '. $row["total"] .'</h4><br>';
echo $output;
}
}
commitQuery("SELECT advance FROM transaction WHERE adv_date=now()");
commitQuery("SELECT SUM(s.total) AS totalamount FROM sale s JOIN product p ON ( s.pr_id = p.pr_id ) WHERE s.customer_name = '$customer'");
Related
In the addonmodule Controller.php:
I append this order_detail function:
/**
* #param $vars
*/
public function order_detail($vars){
$modulelink = $vars['modulelink']; // eg. addonmodules.php?module=addonmodule
$version = $vars['version']; // eg. 1.0
$LANG = $vars['_lang']; // an array of the currently loaded language variables
$orderid = 28;//isset($_REQUEST['orderid']) ? $_REQUEST['orderid'] : '';
$sql = "SELECT tblhosting.id, tblhosting.regdate, tblhosting.domain, tblhosting.billingcycle, tblhosting.nextduedate, tblhosting.nextinvoicedate, tblhosting.termination_date, tblhosting.domainstatus, tblhosting.username, tblhosting.notes, tblhosting.dedicatedip, tblhosting.assignedips FROM tblhosting ";
// $sql .= "LEFT JOIN tblorders ON ";
// $sql .= "tblhosting.orderid = tblorders.id ";
$sql .= ("WHERE tblhosting.orderid = " . $orderid);
$tblhostings = Capsule::select($sql);
$table_tbody = "";
for($i = 0; $i < count($tblhostings); $i ++) {
$item = $tblhostings[$i];
$row = "<tr>";
$row .= ("<td><input type='text' id='tblhosting-id' name='id' class='form-control' readonly=\"readonly\" style='width:80px;' value='" . $item->id . "'></td>");
$row .= ("<td><textarea id='tblhosting-domain' name='domain' class='form-control' style='width:320px;'>" . $item->domain . "</textarea></td>");
//$row .= ("<td>" . $item->billingcycle . "</td>");
$row .= ("<td ><div style='width:80px;'>" . $item->nextduedate . "</div></td>");
$row .= ("<td ><div style='width:80px;'>" . $item->nextinvoicedate . "</div></td>");
//$row .= ("<td>" . $item->termination_date . "</td>");
//$row .= ("<td>" . $item->username . "</td>");
$row .= ("<td><textarea id='tblhosting-dedicatedip' name='dedicatedip' class='form-control' style='width:200px;'>" . $item->dedicatedip . "</textarea></td>");
$row .= ("<td><textarea id='tblhosting-assignedips' name='assignedips' class='form-control' style='width:200px;'>" . $item->assignedips . "</textarea></td>");
$row .= ("<td>" . $item->domainstatus . "</td>");
$row .= ("<td><div style='width:80px;'>" . $item->regdate . "</div></td>");
$row .= ("<td><textarea id='tblhosting-notes' type='textarea' name='notes' class='form-control' style='width:200px;'>" . $item->notes . "</textarea></td>");
$row .= ("<td> <button id='modify' type='submit' class='btn btn-warning'>modify</button> <button id='send-email' type='button' class='btn btn-success'>Send email</button> </td>");
$row .= "</tr>";
$table_tbody .= $row;
}
$div = "<div class='container'><div><h2>order ID: {$orderid} :</h2></div>";
$div .= "<div >";
$div .= "<form '><table class='table'>";
$div .= "<thead><tr>";
$div .= "<th>product ID</th>";
$div .= "<th>product name</th>";
//$div .= "<th>billingtype</th>";
$div .= "<th>nextdue</th>";
$div .= "<th>nextvoice</th>";
//$div .= "<th>terminate time</th>";
//$div .= "<th>username</th>";
$div .= "<th>dedicated IP</th>";
$div .= "<th>assigned IP</th>";
$div .= "<th>status</th>";
$div .= "<th>regdate</th>";
$div .= "<th>note</th>";
$div .= "<th>ope</th>";
$div .= "</tr></thead>";
$div .= "<tbody>";
$div .= $table_tbody;
$div .= "</tbody>";
$div .= "</table>";
$div .= "</div></div>";
$js = "<script>";
$js .= "
var origin_url = window.location.href;//\"http://192.168.33.10/whmcs-nlidc.com/whmcs/admin/addonmodules.php?module=addonmodule&action=order_detail&orderid=100\";
var url_array =origin_url.split(\"/admin/\")
var url = url_array[0] + \"/admin/api/admin_apis.php\";
jQuery(document).ready(function(){
$('#modify').click(function(){
//alert('modify');
var id = $('#tblhosting-id').val();
var domain = $('#tblhosting-domain').val();
var dedicatedip = $('#tblhosting-dedicatedip').val();
var assignedips = $('#tblhosting-assignedips').val();
var notes = $('#tblhosting-notes').val();
var params = {
admin_api:'update_tblhosting_support',
id: id,
domain: domain,
dedicatedip: dedicatedip,
assignedips: assignedips,
notes: notes,
}
$.post(url, params,function(data,status){
//alert(\"Data: \" + data + \"nStatus: \" + status);
var data_obj = JSON.parse(data);
if (status == 'url' && data_obj.status == 200) {
alert('update success');
alert(window.location.href(www.baidu.com);)
}else {
//alert('update fail');
}
});
})
});
jQuery(document).ready(function(){
$('#send-email').click(function(){
alert('send email');
})
});
";
$js .= "</script>";
$html = $div . $js;
return <<<EOF
$html
EOF;
}
}
I want to use this way to update the tblhosting entries. You see my jQuery code want to use post method to update the tblhosting entry.
when I click update button, it will execute the update url, but however it will redirect to this URL
http://192.168.33.10/whmcs/admin/addonmodules.php?id=28&domain=10.93.240.193-194(15M%29+HK-Z7-A15++E5-2650%282CPU%29%2F32G%2F500G+ssd%2F++&dedicatedip=10.93.240.193-194&assignedips=10.93.240.193%0D%0A10.93.240.194¬es=02442%2F66655%0D%0A10&intellisearch=1&token=ac271aed87528e68969608329e8a1f4d2a35c858&value=
As we know the ajax will not refresh a whole page, and will not redirect by default after request, why there goes different?
Who know the way to avoid the redirect?
I also tried use
window.location.href(origin_url);
to redirect to back after the wrong redirect, but it will not execute.
I am needing to get the total of a row from a MySQL data base that is listed in an HTML table.
I have tried using separate sql select statements with the as statement for the new row (i.e. SELECT SUM(product_price) AS order_total FROM orderplace WHERE orderplace_number = '$item') as well as using it in the original select statement.
Here is my original code without the total added up. I would like the total in a different row spanning across all columns. Thanks in advance!
<table width="100%">
<tr>
<th>Product ID</th>
<th>Item Name</th>
<th>Description</th>
<th>Price</th>
<th>Actions</th>
</tr>
<?php
$cart = $_COOKIE['crochetdamour'];
if ($cart) {
$i = 1;
include('includes/dbc.php');
$items = explode(',', $cart);
foreach ($items AS $item) {
$sql = "SELECT * FROM orderplace WHERE orderplace_number = '$item'";
$result = mysqli_query($con, $sql);
if ($result == false) {
$mysql_error = mysqli_error($con);
echo "There was a query error: $mysql_error";
} else {
while ($row = mysqli_fetch_assoc($result)) {
echo '<tr><td align="left" id="prodid" name="prodid">' . $row['product_id'] . '</td>';
echo '<td align="left" id="prodname" name="prodname">' . $row['product_name'] . '</td>';
echo '<td align="left" class="desctd" id="proddesc" name="proddesc">' . $row['product_size'] . ', ' . $row['product_gender'] . ', ' . $row['product_theme'] . ', ' . $row['product_specs'] . '</td>';
echo '<td align="left" id="prodprice" name="prodprice">' . $row['product_price'] . '</td>';
echo '<td align="left">Remove From Cart</td></tr>';
} //end while
$i++;
} //end else
} //end foreach
} //end if
?>
</table>
You have to this:
foreach ($items AS $item) {
$sum = 0; //<-------------
$sql = "SELECT * FROM orderplace WHERE orderplace_number = '$item'";
$result = mysqli_query($con, $sql);
if ($result == false) {
$mysql_error = mysqli_error($con);
echo "There was a query error: $mysql_error";
} else {
while ($row = mysqli_fetch_assoc($result)) {
echo '<tr><td align="left" id="prodid" name="prodid">' . $row['product_id'] . '</td>';
echo '<td align="left" id="prodname" name="prodname">' . $row['product_name'] . '</td>';
echo '<td align="left" class="desctd" id="proddesc" name="proddesc">' . $row['product_size'] . ', ' . $row['product_gender'] . ', ' . $row['product_theme'] . ', ' . $row['product_specs'] . '</td>';
echo '<td align="left" id="prodprice" name="prodprice">' . $row['product_price'] . '</td>';
echo '<td align="left">Remove From Cart</td></tr>';
$sum += $row['product_price']; //<--------------
} //end while
$i++;
} //end else
echo $sum; //<----------------
} //end foreach
Hope it will helps
I want to pass the php variable to the next page.
I tried many things, but I did not succeed.
Here is the attached case I tried.
index code
<script>
<?php
$con = mysqli_connect($db_host,$db_user,$db_passwd,$db_name);
mysqli_set_charset($con, "utf8");
$result = mysqli_query($con, "select * from StoreTable");
$n = 1;
while($row = mysqli_fetch_array($result)){
$name = $row['name'];
?>
positions_1.push({ content:
'<div class="wrap">' +
' <div>next page</div>' +
'</div>'
});
<?
$n++;
}
?>
</script>
next code
<?php
echo $name;
?>
url has been changed to a variable, but a blank screen is displayed. (Variables were not passed to the next page.)
Try this --
<script>
<?php
$con = mysqli_connect($db_host,$db_user,$db_passwd,$db_name);
mysqli_set_charset($con, "utf8");
$result = mysqli_query($con, "select * from StoreTable");
$n = 1;
while($row = mysqli_fetch_array($result)){
$name = $row['name'];
?>
positions_1.push({ content:
'<div class="wrap">' +
' <div>next page</div>' +
'</div>'
});
<?
$n++;
}
?>
</script>
I have a program that displays authors book code and book title using php and
AJAX technology, but for some reason the data is not appearing in the table. I know my SQL code is correct as our instructor gave us the code for that, but something is preventing the data from appearing in the table. Any tips or suggestions would be appreciated!
<body>
<?php
$authorid = 0;
$authorid = (int) $_GET['authorid'];
if ($authorid > 0) {
require_once('dbtest.php');
$query = "SELECT * FROM author";
$r = mysqli_query($dbc, $query);
if (mysqli_num_rows($r) > 0) {
$row = mysqli_fetch_array($r);
} else {
echo "Title Not Returned<br>";
}
echo "<table border='1'><caption>Titles for </caption>";
echo "<tr>";
echo "<th>Book Code</th>";
echo "<th>Book Title</th>";
echo "</tr>";
$q2 ="SELECT wrote.author_number As ANo, wrote.book_code As BookCd, book.book_title As Title ";
$q2 .= " FROM wrote, book ";
$q2 .= " WHERE wrote.book_code=book.book_code ";
$q2 .= " AND wrote.author_number = ' ' ";
$q2 .= " ORDER BY book.book_title";
$r2 = mysqli_query($dbc, $q2);
$row = mysqli_fetch_array($r2);
while ($row) {
echo "<tr>";
echo "<td>" .$row['BookCd']. "</td>";
echo "<td>" .$row['Title']. "</td>";
echo "</tr>";
$row = mysqli_fetch_array($r2);
}
echo "</table>";
} else {
echo "<p>No Author ID from prior page</p>";
}
?>
</form>
</body>
The suspicious line is: AND wrote.author_number = ' '
Why is it empty?
Put a check after the second query:
$r2 = mysqli_query($dbc, $q2);
if (mysqli_num_rows($r2) > 0) {
echo "rows are Returned<br>";
} else {
echo "rows are Not Returned<br>";
}
$row = mysqli_fetch_array($r2);
Inside a php class I am defining a table which displays a list of clients which one need to contact. In column 7 I have integrated a checkbox so when the user call the client, he/she ticks into this checkbox.
The problem is that the JS function runs the first-time and then the second time it says: default.php?page=_PhoneBankingP1:1 Uncaught ReferenceError: contacted is not defined(…)
The modules in use are listed below:
public function phonebank($townCode,$streetCode){
$query = "SELECT clientId, clientFirstname1, clientLastname1, clientAddress, ";
$query .= " clientMailshot, clientPhone1, clientMobile1, clientContacted, min(clientDoB) ";
$query .= "FROM _clients ";
$query .= "WHERE _clients.streetCode = '{$streetCode}' and ";
$query .= " _clients.townCode = '{$townCode}' and ";
$query .= " _clients.GE = 'Y' ";
$query .= "GROUP BY clientAddress ";
$result = $this->db->query($query);
$output = "";
if ( $result->num_rows > 0 ){
$output .= "<div class='alert alert-info'><strong>Information!</strong> All the residents shown below have been extracted from the last Electoral Register.</div>";
$output .= "<table class='table table-striped' style='font-size:10pt;' id='myTable' >";
$output .= "<thead>";
$output .= "<tr>";
$output .= "<th>ID #</th>";
$output .= "<th>Name</th>";
$output .= "<th>Address</th>";
$output .= "<th>T</th>";
$output .= "<th>Phone</th>";
$output .= "<th>Mobile</th>";
$output .= "<th class='text-center'>Contacted</th>";
$output .= "</tr>";
$output .= "</thead>";
$output .= "<tbody>";
while ( $record = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$output .= "<tr>";
$output .= "<td><a href='default.php?page=_clientDetails&id=".$record['clientId']."&mode=edit' style='color: #000;'><span class='pb-clientId'>".$record['clientId']."</span></a></td>";
$output .= "<td><span class='pb-fullname'>".$record['clientFirstname1']." ".$record['clientLastname1']."</span></td>";
$output .= "<td>".$record['clientAddress']."</td>";
$output .= "<td>".$record['clientMailshot']."</td>";
$output .= "<td>".$record['clientPhone1']."</td>";
$output .= "<td>".$record['clientMobile1']."</td>";
// Makes a checkbox selected
if ( $record['clientContacted'] == 'Y'){
$optContacted = ' checked ';
} else {
$optContacted = '';
}
//$output .= "<td class='text-center' ><button id='btn-contacted-".$record['clientId']."' onclick='street.clientContacted("{$record['clientId']}","{$record['clientContacted']}")' class='btn btn-success'>Contacted</button></td>";
$output .= "<td align='center'>";
$output .= "<input type='checkbox' id='col7-".$record['clientId']."' onclick='contacted("".$record['clientId']."");' value='1' ".$optContacted." />";
$output .= "</td>";
$output .= "</tr>";
}
$output .= "</tbody>";
$output .= "</table>";
$output .= "<br/>";
echo $output;
} else {
echo "No Clients Found in this street";
}
}
Then the test JS function required to update the MYSQL is:
function contacted(id) {
var clientId = id;
var col7 = "col7-"+clientId;
var col7value = $("#"+col7).is(':checked');
var data = id+"\n"+col7+"\n"+col7value;
alert(data);
//Read checkbox state
if (col7value =='false'){
contacted = 'N';
} else {
contacted = 'Y';
}
$.ajax({
type: "POST",
url: "_backend/_core/_database/update_Phonebank.php",
data: {
"id": clientId,
"contacted": contacted
},
dataType: "text",
success: function(data){
}
})
}
I will appreciate if you can help me out to decide my the function is not being read the second time.
You define a function:
function contacted(id) {
//...
}
But within that function, you overwrite the function with a value:
contacted = 'N';
So the next time you try to invoke contacted() you're trying to call a string as if it was a function.
Give your variables unique names:
var wasContacted = '';
//...
wasContacted = 'N';
// etc.
That way you're not overwriting things you don't want to overwrite.
Additionally, using the var keyword to declare your variables will define them within that specific scope (such as within that function), instead of just putting them on the window object. (You can have variables of the same name in different scopes without affecting each other.)