PHP - Cannot update the cart total amount in Session - php

As the title says, I cannot update the cart total amount. Here's the scenario of my situation.
I have a checkout page in which there is an option of shipping amount in which the user has to select an option from the drop down menu. Once chosen, the cart total amount should get updated adding the shipping charges in the header where my navigation links are and also in the page where I want the user to click the button for checking out.
Here's the shipping charge HTML code:
<select name="selectZone" id="custDelAddZone">
<option value="-1">----- Select -----</option>
<?php
$queryForZone = "SELECT * FROM shipping_zones ORDER BY ZoneName";
$validate->Query($queryForZone);
if ($validate->NumRows() >= 1) {
while ($row = $validate->FetchAllDatas()) {
echo '<option value="'.$row['ZoneId'].'">'.$row['ZoneName'].'</option>';
}
}
?>
</select>
<button name="CustDelAddUpdateZone" id="btnCustDelAddUpdateZone" type="submit">Continue</button>
Here's the AJAX part of the button click:
$("#btnCustDelAddUpdateZone").click(function() {
zoneId = $("#custDelAddZone").val();
if (zoneId == '-1') {
toastr.error("Please Select The Region", "Error");
toastr.options.showMethod = "slideDown";
toastr.options.hideMethod = "slideUp";
}
var dataStr = $("#chooseShippingZoneForm").serialize();
$.ajax({
url: 'http://localhost/ECommerceOnFlatastic/ActionFiles/Customers/UpdateDeliveryZone.php',
type: 'POST',
data: dataStr,
success: function(msg) {
toastr.success(msg);
toastr.options.showMethod = "slideDown";
toastr.options.hideMethod = "slideUp";
$("#selectZoneForm").slideUp();
$("#delMethod h3").removeClass("color_light active");
$("#paytMethod").show();
$("#paytMethod h3").removeClass("bg_light_color_1 color_dark");
$("#paytMethod h3").addClass("color_light active");
$("#payment").slideDown();
}
});
return false;
});
And here's the PHP script (UpdateDeliveryZone.php):
<?php
session_start();
$zoneId = $custCode = "";
require_once '../../Classes/class.Validation.php';
$validate = new Validation('developi_ecommerce');
$q = "SELECT CustCode FROM customers WHERE CustEmailAdd = '".$_SESSION['Customer']['email']."'";
$validate->Query($q);
if ($validate->NumRows() >= 1) {
while ($row = $validate->FetchAllDatas()) {
$custCode = $row['CustCode'];
}
} else {
echo "No Customer Found";
}
if ( isset( $_POST['selectZone'] ) && $_POST['selectZone'] != "" ) {
$zoneId = $validate->EscapeString( $_POST['selectZone'] );
$query = "UPDATE customers_delivery_address SET ZoneId = '".$zoneId."' WHERE CustCode = '".$custCode."' AND CustDelAddLastInserted >= NOW() - INTERVAL 10 MINUTE";
if ( $validate->Query( $query ) == TRUE ) {
echo "Updated Successfully";
} else {
echo "Invalid Query";
}
} else {
echo "Value Not Set";
}
?>
And here's how I am trying to get the cart total amount in PHP:
if ($validate->Query($sql) == TRUE) {
if ($validate->NumRows() >= 1) {
while ( $row = $validate->FetchAllDatas() ) {
echo '<tr>';
echo '<td style="width: 50%;" data-title="Product Image & name" class="t_md_align_c"><img src="images/Products/'.$row['ProdCode'].'.jpg" alt="'.$row['ProdCode'].'" class="m_md_bottom_5 d_xs_block d_xs_centered" height="75" width="75">'.$row['ProdName'].'</td>';
echo '<td style="width: 5%;" data-title="SKU">'.$row['ProdCode'].'</td>';
echo '<td style="width: 5%;" data-title="Price"><p class="f_size_large color_dark">Rs. '.$row['ProdRate'].'</p></td>';
echo '<td style="width: 5%;" data-title="Quantity"><div class="clearfix d_inline_middle f_size_medium color_dark m_bottom_10">'.$_SESSION['cart'][$row['ProdCode']]['quantity'].'</div></td>';
$sbTotal = $row['ProdRate'] * $_SESSION['cart'][$row['ProdCode']]['quantity'];
$subTotal = $sbTotal;
echo '<td style="width: 5%;" data-title="Subtotal"><p class="f_size_large fw_medium scheme_color t_align_r">'.number_format($sbTotal, 2).'</p></td>';
$total += $subTotal;
$_SESSION['cartTotalAmount'] = $total;
$tax = $row['CatTaxPercent'];
$taxAmt = (($sbTotal * $tax ) / 100);
$taxAmount += $taxAmt;
$amt = 0;
$cartWeightPerProduct = ($row['weight'] * $_SESSION['cart'][$row['ProdCode']]['quantity']);
echo '</tr>';
$totalCartWeight += $cartWeightPerProduct;
}
$totalTaxAmount += $taxAmount;
$_SESSION['cartWeight'] = $totalCartWeight;
$sessAmnt = ($total + $totalTaxAmount);
$totalPayableAmnt = $sessAmnt + $_SESSION['TotalWeight']; // This is my cart total amount
$_SESSION['sessionTotalPayable'] = number_format($totalPayableAmnt, 2);
if ( isset( $_SESSION['sessionTotalPayable'] ) ) {
$amt = $totalPayableAmnt;
} else {
$amt = "Rs. 0";
}
echo '<tr><td colspan="4"><p class="fw_medium f_size_large t_align_r t_xs_align_c">Cart Total:</p></td><td colspan="1"><p class="fw_medium f_size_large color_dark t_align_r">'.number_format($total, 2).'</p></td></tr>';
echo '<tr><td colspan="4"><p class="f_size_large t_align_r t_xs_align_c">Taxes:</p></td><td colspan="1"><p class="f_size_large color_dark t_align_r">'. number_format($totalTaxAmount, 2) .'</p></td></tr>';
echo '<tr><td colspan="4"><p class="f_size_large t_align_r t_xs_align_c">Shipping:</p></td><td colspan="1"><p id="shippingAmount" class="f_size_large color_dark t_align_r">'.number_format($_SESSION['TotalWeight'], 2).'</p></td></tr>';
echo '<tr><td colspan="4"><p class="fw_medium f_size_large t_align_r t_xs_align_c">Total Payable Amount:</p></td><td colspan="1"><p class="fw_medium f_size_large color_dark t_align_r">'.number_format($amt, 2).'</p></td></tr>';
}
}
For those who wants to know from where the $_SESSION['TotalWeight'] came from:
<?php
session_start();
require_once 'Classes/class.Validation.php';
function SelectZoneAmount($amt, $id) {
$validate = new Validation('developi_ecommerce');
$zoneCol = 0;
if ($amt >= 1 && $amt <= 499 ) {
$zoneCol = 'SWC_0_500';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
} elseif($amt >= 500 && $amt <= 999) {
$zoneCol = 'SWC_500_1000';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
} elseif($amt >= 1000 && $amt <= 1499) {
$zoneCol = 'SWC_1000_1500';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
} elseif($amt >= 1500 && $amt <= 1999) {
$zoneCol = 'SWC_1500_2000';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
} elseif($amt >= 2000 && $amt <= 2499) {
$zoneCol = 'SWC_2000_2500';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
} elseif($amt >= 2500 && $amt <= 2999) {
$zoneCol = 'SWC_2500_3000';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
} elseif($amt >= 3000 && $amt <= 3499) {
$zoneCol = 'SWC_3000_3500';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
} elseif($amt >= 3500 && $amt <= 3999) {
$zoneCol = 'SWC_3500_4000';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
} elseif($amt >= 4000 && $amt <= 4499) {
$zoneCol = 'SWC_4000_4500';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
} elseif($amt >= 4500 && $amt <= 4999) {
$zoneCol = 'SWC_4500_5000';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
} elseif($amt >= 5000 && $amt <= 10000) {
$zoneCol = 'SWC_5000_10000';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
}
}
$region = 0;
if (isset($_POST['selectZone'])) {
$region = SelectZoneAmount($_SESSION['cartWeight'], $_POST['selectZone']);
$_SESSION['TotalWeight'] = $region;
echo number_format($_SESSION['TotalWeight'], 2);
}
?>
When I go to checkout page and select the shipping zone, I am not able to refresh the cart total amount. I know there must be a logical error somewhere. Kindly help me in rectifying the error.
Thank You in advance.

I think, error is found:
$_SESSION['sessionTotalPayable'] = number_format($totalPayableAmnt, 2);
you set value in session var by using number_format() function. this is wrong way.
you can use number_format() function only view section...
because, number_format() return a string . so, it can't calculate.
Please check your code based on above condition.
then that may solve.

Related

How to fetch the data from multiple tables order by SUM query?

I have different tables like profiles, tournaments, tournamentdate, tournamentresult and pigeons.
Profiles columns > ProfileId, Name, Address, etc.
Tournaments columns > tID, name, detail, startdate, enddate, etc.
Tournamentdate columns > tdID, tID, date.
Tournamentresult Columns > ResultID, ProfileID, tID, tdID, starttime and Total (Total Time).
Pigeons Columns > PID, ResultID, ProfileID, TID, TDID, Pigeon Number, FlyingTime, TotalTime.
I have create a tournament for 3 days like 13,15,17 May (added dates into tournamentdate Table). I have added 5 peoples from Profiles Table, 7 Pigeons a day into Pigeons Table.
I will show you how to I display data using PHP.
this is one day record one Person have 7 Pigeons I am using SQL Sum Query for each person for total. Now I want to display same thing but Total as DESC.
Here is my code (function.php)
function GetTournamentDate($conn, $TID)
{
$TID = (int)$TID;
$tournaments = array();
$sql = "SELECT * FROM tournamentdate WHERE `TID`='$TID' ORDER BY `TDate` ASC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while ($row = $result->fetch_assoc()) {
$tournaments[] = array(
'TDID' => $row['TDID'],
'TID' => $row['TID'],
'TDate' => $row['TDate'],
);
}
}
return $tournaments;
}
//=========
function GetResults($conn, $TID)
{
$TID = (int)$TID;
$Results = array();
$sql = "SELECT * FROM tournamentresult WHERE `TID`='$TID' ORDER BY `Total` DESC";
$Result = $conn->query($sql);
if ($Result->num_rows > 0) {
// output data of each row
while ($row = $Result->fetch_assoc()) {
$Results[] = array(
'ResultID' => $row['ResultID'],
'ProfileID' => $row['ProfileID'],
'TID' => $row['TID'],
'TDID' => $row['TDID'],
'StartTime' => $row['StartTime'],
'Total' => $row['Total'],
'Price' => $row['Price'],
);
}
}
return $Results;
}
// ====================
function GetPigeonByResult($conn, $ResultID, $ProfileID, $TDID)
{
$ResultID = (int)$ResultID;
$ProfileID = (int)$ProfileID;
$TDID = (int)$TDID;
$Results = array();
$sql = "SELECT * FROM pigeons WHERE `ResultID` = '$ResultID' and `ProfileID` = '$ProfileID' and `TDID` = '$TDID' ORDER BY `Pigeon` ASC";
$Result = $conn->query($sql);
if ($Result->num_rows > 0) {
// output data of each row
while ($row = $Result->fetch_assoc()) {
$Results[] = array(
'PigeonID' => $row['PigeonID'],
'ResultID' => $row['ResultID'],
'Pigeon' => $row['Pigeon'],
'PigeonTime' => $row['PigeonTime'],
'PigeonTotalTime' => $row['PigeonTotalTime'],
'Status' => $row['Status'],
);
}
}
return $Results;
}
//=================
// profile_data
function ProfileData($conn, $ProfileID)
{
$ProfileID = (int)$ProfileID;
$func_num_args = func_num_args();
$func_get_args = func_get_args();
if ($func_num_args > 1) {
unset($func_get_args[0]);
unset($func_get_args[1]);
// check arry fields
$valid = array('ProfileID', 'ProfileName', 'ProfileAddress', 'ProfileNumber', 'ProfileDetail');
$fields = array();
foreach ($func_get_args as $arg) {
if (in_array($arg, $valid)) $fields[] = $arg;
}
// convert fields
$fields = '`' . implode('`, `', $fields) . '`';
$sql = "SELECT $fields FROM profiles WHERE ProfileID = '$ProfileID'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while ($row = $result->fetch_assoc()) {
foreach ($func_get_args as $field) {
$func_get_args[$field] = $row[$field];
}
return $func_get_args;
}
} // else
}
}
// =================
and here in index.php
<?php
$TID = 5; // example
$Results = GetResults($conn, $TID);
$TournamentDate = GetTournamentDate($conn, $TID);
if (!empty($TournamentDate)) {
foreach ($TournamentDate as $TD) {
$TDID = $TD['TDID'];
$TDate = $TD['TDate'];
}
$TDID = 8; // example
if (!empty($Results)) {
foreach ($Results as $TR) {
$ResultID = $TR['ResultID'];
$ProfileID = $TR['ProfileID'];
$TotalPigeons = GetPigeonByResult($conn, $ResultID, $ProfileID, $TDID);
}
}
?>
<tbody>
<?php
$RCount = 0;
foreach ($Results as $Result) {
$RCount++;
$ResultID = $Result['ResultID'];
$ProfileID = $Result['ProfileID'];
$StartTime = $Result['StartTime'];
if ($StartTime == 0) {
$StartTime = '';
} else {
$StartTime = secondsToWords($StartTime);
// $StartTime = substr($StartTime, 0, -3);
}
$Total = $Result['Total'];
if ($Total == 0) {
$Total = '<p style="color: #ccc">0</p>';
} else {
$Total = secondsToWords($Total);
// $Total = substr($Total, 0, -3);
}
$ProfileData = ProfileData($conn, $ProfileID, 'ProfileName', 'ProfileAddress');
$ProfileName = $ProfileData['ProfileName'];
$ProfileAddress = $ProfileData['ProfileAddress'];
echo "<tr>";
echo "<td>$RCount</td>";
?>
<td style="text-align: left;">
<h3 style="margin: 0px; padding: 0px; font-weight: bold;">
<?php echo $ProfileName; ?>
</h3>
<p style="margin: 0px; padding: 0px;"><?php echo $ProfileAddress; ?></p>
</td>
<td>
<a href="#!" class="edit" data-type="text" data-pk="<?php echo $ResultID . '-sTime'; ?>">
<?php echo $StartTime; ?>
</a>
</td>
<?php
// Get Pigeons
$TotalPigeons = GetPigeonByResult($conn, $ResultID, $ProfileID, $TDID);
if (!empty($TotalPigeons)) {
$TotalSum = 0;
foreach ($TotalPigeons as $TP) {
$tPigeonID = $TP['PigeonID'];
$PigeonTime = $TP['PigeonTime'];
$PigeonTotalTime = $TP['PigeonTotalTime'];
$PigeonStatus = $TP['Status'];
$TotalSum = $TotalSum + $PigeonTotalTime;
$tPigeonTime = secondsToWords($PigeonTime);
$PigeonTotalTime = secondsToWords($PigeonTotalTime);
if ($PigeonTime == 0) {
if ($PigeonStatus == 1) {
?>
<td>
<a href="#!" class="edit" data-type="text" data-value="" data-pk="<?php echo $tPigeonID . '-pTime-' . $Result['StartTime'] . '-' . $Result['Total']; ?>">
empty
</a>
Active
</td>
<?php
} else {
?>
<td>
Waste
</td>
<?php
}
} else {
if ($PigeonStatus == 1) {
?>
<td>
<a href="#!" class="edit" data-type="text" data-pk="<?php echo $tPigeonID . '-pTime-' . $Result['StartTime'] . '-' . $Result['Total']; ?>">
<?php echo $tPigeonTime; ?>
</a>
<p><small><?php echo $PigeonTotalTime; ?></small></p>
Active
</td>
<?php
} else {
?>
<td style="background-color: red; color: white;">
Waste
</td>
<?php
}
}
}
}
echo "<td>" . secondsToWords($TotalSum) . "</td>";
echo "</tr>";
}
?>
</tbody>
Please tell me how to I Display as total DESC.
If you give me code I will be grateful to you۔
You can do this by creating a SELECT statement to get all the users and inside the SELECT statement you can nest another SELECT to get the total score.
Then you can simply sort your result using ORDER.
SELECT
*,
(SELECT SUM(score) FROM games WHERE user = users.ID) AS total
FROM users ORDER BY total DESC
In your example, if I understand correctly, this would translate to:
SELECT
*, (SELECT SUM(TotalTime) FROM Pigeons WHERE ProfileID = Profiles.ProfileId) AS total
FROM Profiles ORDER BY total DESC
Use group_concat along with group by you can get all data in a single query.
then you can use those data using explode.

How to total up the bonus on Recursive Loop in php mysql?

How to show the total bonus in red color at the screenshot below ?
Demo link : http://client.bfm.expert/test_unilevel1.php
Code :
<?php
//Use the following function to get the data of downlines
function getChildren($parent) {
//list out members by rank
$query = "SELECT user_id, first_name, sponsor_id, rank FROM tbl_user_master WHERE sponsor_id = $parent";
$result = $conn->query($query);
$children = array();
$i = 0;
$result = $conn->query($query) or die($conn->error);
while($row = $result->fetch_assoc())
{
$children[$i] = array();
$children[$i]['userid'] = $row['user_id'];
$children[$i]['name'] = $row['first_name'];
$children[$i]['rank'] = $row['rank'];
$children[$i]['children'] = getChildren($row['user_id']);
$i++;
}
return $children;
}
//modify rank = 4 to 2 to calculate unilevel bonus for rank IAM
$query2 = "SELECT user_id, first_name FROM tbl_user_master WHERE rank = 3";
$result2 = $conn2->query($query2);
$result2 = $conn2->query($query2) or die($conn2->error);
while($row2 = $result2->fetch_assoc())
{
$member_id = $row2['user_id'];
$member_name = $row2['first_name'];
$finalResult = getChildren($member_id); //enter sponsor_id here
echo "Unilevel Bonus for user id : " . $member_id . " " . $member_name . " - Total Unilevel Bonus for lvl1 : Usd??? , lvl2 : Usd???, lvl3 : Usd??? <br /> ";
printList($finalResult);
}
//display all downlines of the sponsor
function printList($array = null, $level = 1) {
$m_profit = 168000;
$Total_investment = 1500000;
$unibonus_percent = 0.00;
if (count($array)) {
echo "<ul>";
foreach ($array as $item) {
echo "<li>";
echo $item['name'];
echo " - Rank : " . $item['rank'];
echo " - level : " . $level;
//show unilevel bonus
$unibonus_percent = 0.06;
//show how many package_lot
$userid = $item['userid'];
$query3 = "SELECT user_id, package_id, package_amount FROM tbl_product_order WHERE user_id = $userid && status=3";
$result3 = $conn3->query($query3);
$result3 = $conn3->query($query3) or die($conn3->error);
while($row3 = $result3->fetch_assoc()) {
$package_siz = $row3['package_amount'] / 1500;
echo " - LOT : " . $package_siz;
$unibonus = (($m_profit / ($Total_investment / 1500)) * $unibonus_percent) * $package_siz;
echo " - unibonus : USD" . $unibonus;
}
if (count($item['children'])) {
printList($item['children'], $level+1);
}
echo "</li>";
}
echo "</ul>";
}
}
?>
Use call by refrence for total bonus calculation
here is an example
$Bonus = 0;
printList($array = null, 1, $Bonus);
echo $Bonus;
function printList($array = null, $level = 1, &$Bonus = 0) {<---call by referance for bonus
if ($level == 10) {
return; //only for break recursive
}
$Bonus = $Bonus + $level;
printList($array = null, $level + 1, $Bonus);
}

php problems with union select distinct

I submitted these two files:
sample_annotation.txt
sample_synteny.txt
I got on the next page the following error:
304501820180500000018.304501820180500000018<br><br>select distinct org1,org2 from '.304501820180500000018.'_synteny union select distinct org1,org2 from '.304501820180500000018.'_synteny<br><br>
Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''.304501820180500000018.'_synteny union select distinct org1,org2 from '.3045018' at line 1
Whole query: select distinct org1,org2 from '.304501820180500000018.'_synteny union select distinct org1,org2 from '.304501820180500000018.'_synteny[]
The mGSV/lib/data.php looks like below and caused the above error:
<?php
include('database.php');
## Get parameters
$org = $_GET['org'];
$data = $_GET['data'];
$session_id = $_GET['session_id'];
$array = array();
if($data == 'annotation') {
$query = "SELECT track_name FROM ".$session_id."_annotation WHERE org_id like '$org' GROUP BY track_name ";
$result = mysql_query($query);
if($result != ''){
while($row = mysql_fetch_assoc($result)){
array_push($array, $row['track_name']);
}
}
//array_push($syn_array, "10_50_20_70");
}
else if ($data == 'synteny') {
$query = "DESC ".$session_id."_synteny";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)){
if($row['Field'] == 'id'){ continue; }
if($row['Field'] == 'blocks'){ continue; }
if($row['Field'] == 'SYNcolor'){ continue; }
if(! preg_match("/^org[12]+[_]?[start|end]?/", $row['Field'])){
array_push($array, $row['Field']);
}
}
}
else if ($data == 'size'){
echo "$session_id.", $session_id, "<br>";
echo "$org", $org, "<br>";
$query = "select distinct org1,org2 from '.$session_id.'_synteny union select distinct org1,org2 from '.$session_id.'_synteny";
echo $query,"<br>";
$result = mysql_query($query);
echo $results,"<br>";
if ($results) {
while($row = mysql_fetch_assoc($result)){
echo $row['org1'], "<br>";
$q = "select max(output) as max from (select max(greatest(org1_start, org1_end)) as output from ".$session_id."_synteny where org1 like '" . $row['org1'] . "' union select max(greatest(org2_start, org2_end)) as output from ".$session_id."_synteny where org2 like '" . $row['org1'] . "') as t1";
echo $q, "<br>";
$res = mysql_query($q);
if (!$res) {
die('Could not query:' . mysql_error());
}
echo $row['org1'],"<br>";
echo $row['org2'],"<br>";
if (! isset($array[$row['org1']])){
//echo "add<br>";
$array[$row['org1']] = mysql_result($res,0);
}
$q = "select max(output) as max from (select max(greatest(org1_start, org1_end)) as output from ".$session_id."_synteny where org1 like '" . $row['org2'] . "' union select max(greatest(org2_start, org2_end)) as output from ".$session_id."_synteny where org2 like '" . $row['org2'] . "') as t1";
#echo $q, "<br>";
$res = mysql_query($q);
if (!$res) {
die('Could not query:' . mysql_error());
}
if (! isset($array[$row['org2']])){
//echo "add<br>";
$array[$row['org2']] = mysql_result($res,0);
}
}
}
else {
echo 'Invalid query: ' . mysql_error() . "\n";
echo 'Whole query: ' . $query;
}
}
else if ($data == 'order'){
$query = "select distinct org1 from ".$session_id."_synteny union select distinct org2 from ".$session_id."_synteny ";
//echo $query,"<br>";
$result = mysql_query($query);
$default = array();
while($row = mysql_fetch_assoc($result)){
array_push($default, $row['org1']);
}
$array = join('__ORDER__', $default);
}
else if ($data == 'sorder'){
$query = "select distinct org1,org2 from ".$session_id."_synteny union select distinct org1,org2 from ".$session_id."_synteny ";
//echo $query,"<br>";
$result = mysql_query($query);
$default = array();
$assarr = array();
while($row = mysql_fetch_assoc($result)){
if( ! in_array($row['org1'], $default)){
array_push($default, $row['org1']);
$assarr[sizeof($assarr)] = array();
}
if( ! in_array($row['org2'], $default)){
array_push($default, $row['org2']);
$assarr[sizeof($assarr)] = array();
}
$len_query = "select sum(org1_end) - sum(org1_start) + sum(org2_end) - sum(org1_start) as sum from ".$session_id."_synteny where (org1 like '".$row['org1']."' and org2 like '".$row['org2']."') OR (org1 like '".$row['org2']."' and org2 like '".$row['org1']."')";
$q_result = mysql_query($len_query);
$q_row = mysql_fetch_assoc($q_result);
#echo $len_query,"<br>";
#echo $q_row['sum'],"<br>";
$assarr[array_search($row['org1'], $default)][array_search($row['org2'], $default)] = $q_row['sum'];
#$assarr[array_search($row['org1'], $default)][array_search($row['org2'], $default)] = 1;
$assarr[array_search($row['org2'], $default)][array_search($row['org1'], $default)] = $q_row['sum'];
#$assarr[array_search($row['org2'], $default)][array_search($row['org1'], $default)] = 1;
#echo array_search($row['org1'], $default) . "][ ". array_search($row['org2'], $default) . '<br>';
$assarr[array_search($row['org1'], $default)][array_search($row['org1'], $default)] = 0;
#echo array_search($row['org1'], $default) . "][ ". array_search($row['org1'], $default) . '<br>';
$assarr[array_search($row['org2'], $default)][array_search($row['org2'], $default)] = 0;
#echo array_search($row['org2'], $default) . "][ ". array_search($row['org2'], $default) . '<br>';
}
$a = FindOrder($assarr);
$sugg = array();
//echo sizeof($a),'<br>';
foreach($a as $b){
//echo $default[$b],"<br>";
array_push($sugg, $default[$b]);
}
$array = join('__ORDER__', $sugg);
}
function FindOrder($graph){
$r = array();
$last = -1;
while(!isEmpty($graph)){
$start = leastEdges($graph);
$path = longestPath($graph, $start, 0);
$path = completeCycle($graph, $path);
if($path[0] != $last){
array_push($r, $path[0]);
}
for($x = 1; $x < sizeof($path); $x++){
array_push($r, $path[$x]);
}
$last = $path[sizeof($path)-1];
$graph = removePath($graph, $path);
}
return $r;
}
function longestPath($graph, $cur, $len){
$path = array();
array_push($path, $cur);
$longestSubpath = array();
for($x = 0; $x < sizeof($graph); $x++){
if($graph[$cur][$x] != 0){
$subpath = longestPath(removeVertex($graph, $cur), $x, $len + $graph[$cur][$x]);
if(sizeof($subpath) > sizeof($longestSubpath)){
$longestSubpath = $subpath;
}
}
}
foreach($longestSubpath as $x){
array_push($path, $x);
}
return $path;
}
function completeCycle($graph, $path){
$graph = removePath($graph, $path);
$last = $path[sizeof($path)-1];
for($x = 0; $x < sizeof($graph); $x++){
if($graph[$last][$x] != 0){
array_push($path, $x);
return $path;
}
}
return $path;
}
function removePath($graph, $path){
for($x = 0; $x < sizeof($path) - 1; $x++){
$arr = $path[$x]; //***forgot the $ in front of path***
$b = $path[$x+1]; //***forgot the $ in front of path***
$graph[$arr][$b] = 0;
$graph[$b][$arr] = 0;
}
return $graph;
}
function removeVertex($graph, $vtx){
if($vtx < 0 || $vtx >= sizeof($graph)){
return copy($graph);
}
for($x = 0; $x < sizeof($graph); $x++){
$graph[$x][$vtx] = 0;
$graph[$vtx][$x] = 0;
}
return $graph;
}
function numEdges($vtx){
$r = 0;
foreach($vtx as $x){
if($x != 0){
$r++;
}
}
return $r;
}
function leastEdges($graph){
$r = -1;
$min = 2147483647;
for($x = 0; $x < sizeof($graph); $x++){
$e = numEdges($graph[$x]);
if($e != 0 && $e < $min){
$r = $x;
$min = $e;
}
}
return $r;
}
function isEmpty($arr){
$r = true;
foreach($arr as $x){
$r = $r && numEdges($x) == 0;
}
return $r;
}
## Return the JSON object
echo json_encode($array);
?>
I created a docker-compose.yml and the can be run in the following way:
git clone https://github.com/mictadlo/mGSV-docker.git
docker-compose up --build
The service can be accessed via localhost and PhpMyAdmin can be accessed via localhost:8183
What did I miss?
Thank you in advance
Try to run independently both query in your Mysql phpmyadmin
select distinct org1,org2 from '.304342020180200000016.'_synteny
select distinct org1,org2 from '.304342020180200000016.'_synteny
As i see your query seems to be correct since union requires the same numbers of columns and same data type.
And why is your table name in the union query is both the same.

How do i update each array item into mysqli database in one query

With my code below i have array item with multiple record i which to update each record into database with one query but only the last item of each array record was updated here is my code
:
<?php
require("init.php");
$sql = "SELECT item_name, quantity
FROM books WHERE book = 1644445";
$query = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($query))
{
$da = $row["item_name"];
$qty = $row["quantity"];
$sql = mysqli_query($conn, "SELECT * FROM promo WHERE code = '$da' LIMIT 1");
$productCount = mysqli_num_rows($sql);
if($productCount > 0)
{
while ($row = mysqli_fetch_array($sql))
{
$id = $row["id"];
$type = $row["name"];
$code = $row["recharge"];
}
}
$set="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$coe=substr(str_shuffle($set), 0, 12);
if(preg_match('/(65265)/i', $type))
$type = "20";
if(preg_match('/(562546)/i', $type))
$type = "13";
if(preg_match('/(MTN)/i', $type))
$type = "12";
if(preg_match('/(56556)/i', $type))
$type = "16";
$disp = str_split($code, $type);
for($b = 0; $b<$qty; $b++){
$pin = "$disp[$b]";
$gam = array(0 => array("post" => $pin));
foreach($gam as $gg)
{
$pp = $gg["post"];
$go = mysqli_query($conn, "UPDATE promo SET recharge='$coe$pp' WHERE id=$id");
if($go)
{
echo "<br/> $pp";
echo "<br/> $coe";
}
}
}
}
?>
i appliciate your impact
Try this:
<?php
require("init.php");
$sql = "SELECT item_name, quantity
FROM books WHERE book = 1644445";
$query = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($query))
{
$da = $row["item_name"];
$qty = $row["quantity"];
$sql = mysqli_query($conn, "SELECT * FROM promo WHERE code = '$da' LIMIT 1");
$productCount = mysqli_num_rows($sql);
if($productCount > 0)
{
while ($row = mysqli_fetch_array($sql))
{
$id = $row["id"];
$type = $row["name"];
$code = $row["recharge"];
}
$set="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$coe=substr(str_shuffle($set), 0, 12);
if(preg_match('/(65265)/i', $type))
$type = "20";
if(preg_match('/(562546)/i', $type))
$type = "13";
if(preg_match('/(MTN)/i', $type))
$type = "12";
if(preg_match('/(56556)/i', $type))
$type = "16";
$disp = str_split($code, $type);
for($b = 0; $b<$qty; $b++){
$pin = "$disp[$b]";
$gam = array(0 => array("post" => $pin));
foreach($gam as $gg)
{
$pp = $gg["post"];
$go = mysqli_query($conn, "UPDATE promo SET recharge='$coe$pp' WHERE id=$id");
if($go)
{
echo "<br/> $pp";
echo "<br/> $coe";
}
}
}
}
}
?>
The update is only executed if $productCount > 0.

Maximum execution time of 30 seconds with dead lock

it seem like i get stocked in loop ,i didn't know why this is my code-
$db = new mysqli("localhost", "root", "", "gdwal");
$sub = mysqli_query($db, "SELECT *,priority FROM subjects,teacher WHERE teach =techID ");
$stack = array();
$num = mysqli_query($db, "SELECT count(capacity)'h' FROM rooms ");
$table[][] = array();
$x = mysqli_fetch_array($num);
$table[0][0] = 0;
if ($db) {
echo 'connected';
}
/* function seet()
{
global $db;
$a=mysqli_query($db,"SELECT * from options ");
while ($row = mysqli_fetch_array($a)) {$z=$row['choices'];
echo($z);
$e=mysqli_query($db,"SELECT * from timeslot where sname=$z ");
$y=mysqli_fetch_array($e);
$x=$y['sindex'];
echo"//////$x/////+";
$b=mysqli_query($db,"UPDATE options SET `choices`=$x WHERE choices=$z ");
if($db->query($b)===true)
{
echo "lk";
}
}
}
seet(); */
for ($u = 0; $u <= 70; $u++) {
for ($g = 0; $g < 10; $g++) {
$table[$u][$g] = 0;
}
}
choose();
function choose() {
$sum = 0;
$sums = 0;
$best = array();
$prev = 0;
$best[0] = 0;
$best[1] = 0;
$best[2] = 100;
$best[3] = 0;
$best[4] = 0;
global $sub;
global $table;
global $stack;
global $db;
$ee = mysqli_query($db, "SELECT a.cid,c.NOstd,t.priority,c.hours,a.choices ,class,c.teacher_id FROM options a LEFT JOIN subjects c ON c.subject_id = a.cid LEFT JOIN teachers t ON t.id = c.teacher_id ");
while ($row = mysqli_fetch_array($ee)) {
if (!in_array($row['cid'], $stack)) {
$r = $row['cid'];
echo "$r-----";
$new = $r;
if ($prev===$new) {
} else {
$sum = 0;
$prev =$new;
}
$z = mysqli_query($db, "SELECT ind FROM rooms where capacity>='$r'");
while ($j = mysqli_fetch_array($z)) {
$hh = $row['choices'];
$uu = $j['ind'];
if ($table[$hh][$uu] == 0) {
$sum++;
}
}
if ($sum == 0) {
break;
}
$sums = $sum;
if ($best[2] == $sum && $best[3] < $row['priority']) {
echo $row['cid'];
echo '09090909090909';
$best[0] = $row['cid'];
$best[1] = $row['NOstd'];
$best[2] = $sums;
$best[3] = $row['priority'];
$best[4] = $row['teacher_id'];
$best[5] = $row['hours'];
$best[6] = $row['class'];
} else {
if ($best[2] > $sum) {
$best[0] = $row['cid'];
$best[1] = $row['NOstd'];
$best[2] = $sums;
$best[3] = $row['priority'];
$best[4] = $row['teacher_id'];
$best[5] = $row['hours'];
$best[6] = $row['class'];
}
}
}
}
back($best);
}
function back($courses) {
global $stack;
global $db;
global $table;
$y =$courses[0];
$i = 0;
global$x;
$numsub = mysqli_query($db, "SELECT COUNT(DISTINCT cid)'jj' FROM options ");
$nn = mysqli_fetch_array($numsub);
$t = 0;
echo "XXX";
echo "//$y//";
echo "SELECT * FROM options WHERE cid='$y'";
echo "XXX";
$slot = mysqli_query($db, "SELECT * FROM options WHERE cid='$y'");
while ($rows = mysqli_fetch_array($slot)) {
$rom = mysqli_query($db, "SELECT * FROM rooms where capacity>='$courses[1]'");
$j = mysqli_query($db, "SELECT * FROM rooms where capacity>='$courses[1]'");
while ($D = mysqli_fetch_array($rom)) {
if ($courses[5] == 3) {
echo "22";
if ($table[$rows['choices']][$D['ind']] != 0 && $table[($rows['choices'] + 1)][$D['ind']] != 0) {
$z = $table[$rows['choices']][$D['ind']];
$ff = mysqli_query($db, "SELECT teacher FROM subjects where course_id=$z ");
$selec = mysqli_fetch_array($ff);
$b = mysqli_query($db, "SELECT COUNT(`class`)'kk'FROM `subjects` WHERE `class` IN(SELECT `class` FROM subjects WHERE `course_id`=$z ) AND( course_id =$y OR`ssubject`=$y");
$count = mysqli_fetch_array($b);
if ($count['kk'] != 0 || $selec['teacher'] == $courses[4]) {
$t++;
}
}
} else
if ($table[$rows['choices']][$D['ind']] != 0) {
$z = $table[$rows['choices']][$D['ind']];
$ff = mysqli_query($db, "SELECT teacher FROM subjects where course_id=$z ");
$selec = mysqli_fetch_array($ff);
$b = mysqli_query($db, "SELECT COUNT(`class`)'kk'FROM `subjects` WHERE `class` IN(SELECT `class` FROM subjects WHERE `course_id`=$z ) AND( course_id =$y OR`ssubject`=$y");
$count = mysqli_fetch_array($b);
if ($count['kk'] != 0 || $selec['teacher'] == $courses[4]) {
$t++;
if ($t != 0) {
break;
}
}
echo "1";
}
if ($t != 0) {
break;
}
}
while ($colmn = mysqli_fetch_array($j)) {
if ($courses[5] == 3) {
echo "uuuuuu";
$w = $table[$rows['choices']][$colmn['ind']];
$y = mysqli_query($db, "SELECT hours FROM subjects where course_id='$w' ");
$op = mysqli_fetch_array($y);
if ($op['hours'] == 3) {
$i = $table[($rows['choices'] - 1)][$colmn['ind']];
$q = mysqli_query($db, "SELECT hours ,course_id , FROM subjects WHERE course_id=$i");
$opi = mysqli_fetch_array($q);
if ($opi['hours'] == 3 && $opi['course_id'] == $w) {
array_push($stack, $courses[0]);
$table[($rows['choices'] + 1)][$colmn['ind']] = $courses[0];
if (count($stack) == $nn['jj']) {
database($table);
break;
}
choose();
$table[($rows['choices']) + 1][$colmn['ind']] = 0;
array_pop($stack);
}
} elseif ($table[$rows['choices']][$colmn['ind']] == 0) {
array_push($stack, $courses[0]);
$table[$rows['choices']][$colmn['ind']] = $courses[0];
$table[($rows['choices'] + 1)][$colmn['ind']] = $courses[0];
if (count($stack) == $nn['jj']) {
database($table);
break;
}
choose();
$table[$rows['choices']][$colmn['ind']] = 0;
$table[($rows['choices'] + 1)][$colmn['ind']] = 0;
array_pop($stack);
}
//end of t
}//end of courses 3
else {
if ($t == 0 && $table[$rows['choices']][$colmn['ind']] == 0) {
array_push($stack, $courses[0]);
$table[$rows['choices']][$colmn['ind']] = $courses[0];
if (count($stack) == $nn['jj']) {
database($table);
break;
}
choose();
$table[$rows['choices']][$colmn['ind']] = 0;
array_pop($stack);
}
}
}
}
}
global $sub;
function database($tab) { // print_r($tab);
global $db;
$g = mysqli_query($db, "SELECT * FROM timeslot");
$r = mysqli_query($db, "SELECT * FROM rooms");
while ($ro = mysqli_fetch_array($g)) {
while ($co = mysqli_fetch_array($r)) {
if ($tab[$ro['sindex']][$co['ind']] === 0) {
} else {
echo 'iam in 2';
$x = $tab[$ro['sindex']][$co['ind']];
$u = mysqli_query($db, "select subject_id,hours,teacher_id,class from subjects WHERE subject_id='$x'");
$cor = mysqli_fetch_array($u);
$na = $cor['subject_id'];
$ho = $cor['hours'];
$tea = $cor['teacher_id'];
$clas = $cor['class'];
$tim = $ro['sindex'];
$km = $co['ind'];
$rmm = mysqli_query($db, "SELECT name FROM rooms where ind=$km");
$rom = mysqli_fetch_array($rmm);
$romm = $rom['name'];
$n = mysqli_query($db, "INSERT INTO ttable(name, teacher,class, timeslot, room, hours) VALUES ($na,$tea,$clas,$tim,$romm,$ho)");
$t = "INSERT INTO ttable(name, teacher, timeslot, room, hours) VALUES ('$na','$tea','$tim','$romm','$ho')";
echo "uuututyttuy";
if ($db->query($t) === true) {
echo "lklklklklklklklkl";
}
}
}
}
}
It seems your "back" function calls "choose" function.
And your "choose" function calls your "back" function.
The loop is complete.
I have marked it with //////// to make it easy to find.
Edit I see now that there is several places in back you call choose. I have only marked one.
It's not to hard to find it with search function of any developer app.
$db = new mysqli("localhost", "root", "", "gdwal");
$sub = mysqli_query($db, "SELECT *,priority FROM subjects,teacher WHERE teach =techID ");
$stack = array();
$num = mysqli_query($db, "SELECT count(capacity)'h' FROM rooms ");
$table[][] = array();
$x = mysqli_fetch_array($num);
$table[0][0] = 0;
if ($db) {
echo 'connected';
}
/* function seet()
{
global $db;
$a=mysqli_query($db,"SELECT * from options ");
while ($row = mysqli_fetch_array($a)) {$z=$row['choices'];
echo($z);
$e=mysqli_query($db,"SELECT * from timeslot where sname=$z ");
$y=mysqli_fetch_array($e);
$x=$y['sindex'];
echo"//////$x/////+";
$b=mysqli_query($db,"UPDATE options SET `choices`=$x WHERE choices=$z ");
if($db->query($b)===true)
{
echo "lk";
}
}
}
seet(); */
for ($u = 0; $u <= 70; $u++) {
for ($g = 0; $g < 10; $g++) {
$table[$u][$g] = 0;
}
}
choose();
function choose() {
$sum = 0;
$sums = 0;
$best = array();
$prev = 0;
$best[0] = 0;
$best[1] = 0;
$best[2] = 100;
$best[3] = 0;
$best[4] = 0;
global $sub;
global $table;
global $stack;
global $db;
$ee = mysqli_query($db, "SELECT a.cid,c.NOstd,t.priority,c.hours,a.choices ,class,c.teacher_id FROM options a LEFT JOIN subjects c ON c.subject_id = a.cid LEFT JOIN teachers t ON t.id = c.teacher_id ");
while ($row = mysqli_fetch_array($ee)) {
if (!in_array($row['cid'], $stack)) {
$r = $row['cid'];
echo "$r-----";
$new = $r;
if ($prev===$new) {
} else {
$sum = 0;
$prev =$new;
}
$z = mysqli_query($db, "SELECT ind FROM rooms where capacity>='$r'");
while ($j = mysqli_fetch_array($z)) {
$hh = $row['choices'];
$uu = $j['ind'];
if ($table[$hh][$uu] == 0) {
$sum++;
}
}
if ($sum == 0) {
break;
}
$sums = $sum;
if ($best[2] == $sum && $best[3] < $row['priority']) {
echo $row['cid'];
echo '09090909090909';
$best[0] = $row['cid'];
$best[1] = $row['NOstd'];
$best[2] = $sums;
$best[3] = $row['priority'];
$best[4] = $row['teacher_id'];
$best[5] = $row['hours'];
$best[6] = $row['class'];
} else {
if ($best[2] > $sum) {
$best[0] = $row['cid'];
$best[1] = $row['NOstd'];
$best[2] = $sums;
$best[3] = $row['priority'];
$best[4] = $row['teacher_id'];
$best[5] = $row['hours'];
$best[6] = $row['class'];
}
}
}
}
/////////////////
/////////////////
/////////////////
back($best);
}
function back($courses) {
global $stack;
global $db;
global $table;
$y =$courses[0];
$i = 0;
global$x;
$numsub = mysqli_query($db, "SELECT COUNT(DISTINCT cid)'jj' FROM options ");
$nn = mysqli_fetch_array($numsub);
$t = 0;
echo "XXX";
echo "//$y//";
echo "SELECT * FROM options WHERE cid='$y'";
echo "XXX";
$slot = mysqli_query($db, "SELECT * FROM options WHERE cid='$y'");
while ($rows = mysqli_fetch_array($slot)) {
$rom = mysqli_query($db, "SELECT * FROM rooms where capacity>='$courses[1]'");
$j = mysqli_query($db, "SELECT * FROM rooms where capacity>='$courses[1]'");
while ($D = mysqli_fetch_array($rom)) {
if ($courses[5] == 3) {
echo "22";
if ($table[$rows['choices']][$D['ind']] != 0 && $table[($rows['choices'] + 1)][$D['ind']] != 0) {
$z = $table[$rows['choices']][$D['ind']];
$ff = mysqli_query($db, "SELECT teacher FROM subjects where course_id=$z ");
$selec = mysqli_fetch_array($ff);
$b = mysqli_query($db, "SELECT COUNT(`class`)'kk'FROM `subjects` WHERE `class` IN(SELECT `class` FROM subjects WHERE `course_id`=$z ) AND( course_id =$y OR`ssubject`=$y");
$count = mysqli_fetch_array($b);
if ($count['kk'] != 0 || $selec['teacher'] == $courses[4]) {
$t++;
}
}
} else
if ($table[$rows['choices']][$D['ind']] != 0) {
$z = $table[$rows['choices']][$D['ind']];
$ff = mysqli_query($db, "SELECT teacher FROM subjects where course_id=$z ");
$selec = mysqli_fetch_array($ff);
$b = mysqli_query($db, "SELECT COUNT(`class`)'kk'FROM `subjects` WHERE `class` IN(SELECT `class` FROM subjects WHERE `course_id`=$z ) AND( course_id =$y OR`ssubject`=$y");
$count = mysqli_fetch_array($b);
if ($count['kk'] != 0 || $selec['teacher'] == $courses[4]) {
$t++;
if ($t != 0) {
break;
}
}
echo "1";
}
if ($t != 0) {
break;
}
}
while ($colmn = mysqli_fetch_array($j)) {
if ($courses[5] == 3) {
echo "uuuuuu";
$w = $table[$rows['choices']][$colmn['ind']];
$y = mysqli_query($db, "SELECT hours FROM subjects where course_id='$w' ");
$op = mysqli_fetch_array($y);
if ($op['hours'] == 3) {
$i = $table[($rows['choices'] - 1)][$colmn['ind']];
$q = mysqli_query($db, "SELECT hours ,course_id , FROM subjects WHERE course_id=$i");
$opi = mysqli_fetch_array($q);
if ($opi['hours'] == 3 && $opi['course_id'] == $w) {
array_push($stack, $courses[0]);
$table[($rows['choices'] + 1)][$colmn['ind']] = $courses[0];
if (count($stack) == $nn['jj']) {
database($table);
break;
}
choose();
$table[($rows['choices']) + 1][$colmn['ind']] = 0;
array_pop($stack);
}
} elseif ($table[$rows['choices']][$colmn['ind']] == 0) {
array_push($stack, $courses[0]);
$table[$rows['choices']][$colmn['ind']] = $courses[0];
$table[($rows['choices'] + 1)][$colmn['ind']] = $courses[0];
if (count($stack) == $nn['jj']) {
database($table);
break;
}
choose();
$table[$rows['choices']][$colmn['ind']] = 0;
$table[($rows['choices'] + 1)][$colmn['ind']] = 0;
array_pop($stack);
}
//end of t
}//end of courses 3
else {
if ($t == 0 && $table[$rows['choices']][$colmn['ind']] == 0) {
array_push($stack, $courses[0]);
$table[$rows['choices']][$colmn['ind']] = $courses[0];
if (count($stack) == $nn['jj']) {
database($table);
break;
}
///////////////////////
///////////////////////
///////////////////////
choose();
$table[$rows['choices']][$colmn['ind']] = 0;
array_pop($stack);
}
}
}
}
}
global $sub;
function database($tab) { // print_r($tab);
global $db;
$g = mysqli_query($db, "SELECT * FROM timeslot");
$r = mysqli_query($db, "SELECT * FROM rooms");
while ($ro = mysqli_fetch_array($g)) {
while ($co = mysqli_fetch_array($r)) {
if ($tab[$ro['sindex']][$co['ind']] === 0) {
} else {
echo 'iam in 2';
$x = $tab[$ro['sindex']][$co['ind']];
$u = mysqli_query($db, "select subject_id,hours,teacher_id,class from subjects WHERE subject_id='$x'");
$cor = mysqli_fetch_array($u);
$na = $cor['subject_id'];
$ho = $cor['hours'];
$tea = $cor['teacher_id'];
$clas = $cor['class'];
$tim = $ro['sindex'];
$km = $co['ind'];
$rmm = mysqli_query($db, "SELECT name FROM rooms where ind=$km");
$rom = mysqli_fetch_array($rmm);
$romm = $rom['name'];
$n = mysqli_query($db, "INSERT INTO ttable(name, teacher,class, timeslot, room, hours) VALUES ($na,$tea,$clas,$tim,$romm,$ho)");
$t = "INSERT INTO ttable(name, teacher, timeslot, room, hours) VALUES ('$na','$tea','$tim','$romm','$ho')";
echo "uuututyttuy";
if ($db->query($t) === true) {
echo "lklklklklklklklkl";
}
}
}
}
}

Categories