I want to access this function and change the variable from the URL how can i Do that . i try this to echo something and its work
http://test.local/UUser.php
<?php echo '<p>'. 'Hello Husam' . '</p>'; ?>
but how i can access this function inside UUser.php .
For example i need to change $order = "ASC" to $order = "DESC".
public function getBooks($start = 0, $limit = 2, $order = "ASC")
{
$sql_start = $start * $limit;
$sql_limit = $limit;
$sql_order_by = $order;
$query = "SELECT Library.nameOfBook, userBook.book_id, userBook.user_id FROM loginUser JOIN userBook JOIN Library ON userBook.user_id = loginUser.id AND userBook.book_id = Library.id WHERE loginUser.username=:username ORDER BY Library.nameOfBook $sql_order_by LIMIT $sql_start, $sql_limit";
$statment = $this->db->prepare($query);
$statment->execute([
':username' => $this->username
]);
$result = $statment->fetchAll();
echo "<table id='myTable' border='1'>
<tr>
<th><a id='sorter' href='#'>Books</a></th>
<th>Action</th>
</tr>";
foreach($result as $row){
echo "<tr>";
echo "<td>" . $row['nameOfBook'] . "</td>";
echo "<td>" ."<input type='submit' id='delete".$row['book_id']."-".$row['user_id']."' onclick='deleteBook(this)' name='delete' value='Delete'>" . "</td>";
echo "</tr>";
}
echo "</table>";
echo "";
return count($result);
echo '<p>'. 'Hello Husam' . '</p>';
}
Related
How to echo the left column table to "Daily" "Monthly" and "Yearly"? It currently displays repeatedly because the results of SQL queries on the right side are 3 items.
$ID = get_current_user_id();
global $wpdb;
if(isset($_GET["view_data"])){
$SubmissionID = $_GET["view_data"];
$results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}myTable WHERE user_id = {$ID} AND `key` IN ('name1', 'name2', 'name3')", OBJECT );
if(isset($_GET["form_name"])) echo "<h4>YOUR REVIEW ON {$_GET["form_name"]}</h4>";
echo "<table>";
foreach ($results as $result) {
echo "<tr>";
echo "<td>";
echo "<p>test1</p>";
echo "</td>";
echo "<td>";
echo $result->value;
echo "</td>";
echo "</tr>";
}
echo "</table>";
echo "<h4><a href='?view_all'>Back to List</a></h4>";
}
The current output of my code:
test1
dynamic_data_1
test1
dynamic_data_2
test1
dynamic_data_3
The output I need:
Daily
dynamic_data_1
Monthly
dynamic_data_2
Yearly
dynamic_data_3
add a counter:
$ID = get_current_user_id();
global $wpdb;
if(isset($_GET["view_data"])){
$SubmissionID = $_GET["view_data"];
$results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}myTable WHERE user_id = {$ID} AND `key` IN ('name1', 'name2', 'name3')", OBJECT );
if(isset($_GET["form_name"])) echo "<h4>YOUR REVIEW ON {$_GET["form_name"]}</h4>";
$count = 0;
echo "<table>";
foreach ($results as $result) {
$count++;
$title = 'DEFAULT Title';
if( $count == 1 ){
$title = 'Daily';
}
elseif( $count == 2 ){
$title = 'Monthly';
}
elseif( $count == 3 ){
$title = 'Yearly';
}
echo "<tr>";
echo "<td>";
echo "<p>" . $title ."</p>";
echo "</td>";
echo "<td>";
echo $result->value;
echo "</td>";
echo "</tr>";
}
echo "</table>";
echo "<h4><a href='?view_all'>Back to List</a></h4>";
}
I want to try multiple while in one while with multiple tables but it's doesn't work.
I have three table and I want a different-different value from table.
Here is my code.
$table1 = GROUPMASTER;
$table2 = LEDGERMASTER;
$table3 = TRANSECTIONMASTER;
$groupmasterdata = mysql_query("select * from $table1 WHERE groupname = 'Capital' OR groupname = 'Fund and Reserves' OR groupname = 'Long Term liabilities' OR groupname = 'Current Liabilities' ");
echo "<table align='center' border=1>";
echo "<tr>";
echo "<td colspan=2 style='text-align:center'><b> CAPITAL and LIABILITIES</b></td>";
echo "<td style='text-align:center'><b> Amount </b></td>";
echo "</tr>";
while($recored = mysql_fetch_array($groupmasterdata))
{
$onegroupname = $recored ['groupname'];
echo "<tr>";
echo "<td colspan=3><b>" . strtoupper($onegroupname) . "</b></td></tr>";
$groupnamelist = mysql_query("select groupname from $table1 WHERE under = '". $onegroupname ."'");
while($data = mysql_fetch_array($groupnamelist))
{
$gname = $data ['groupname'];
$getledgername = mysql_query("select ledgername from WHERE groupname = '". $gname ."'");
while($lname = mysql_fetch_array($getledgername))
{
$gettocashbal = mysql_query("select *, SUM(amount) AS totalto from $table3 WHERE voucherto = '". $ledgername ."'");
while($datato = mysql_fetch_array($gettocashbal))
{
$tototal = $datato['totalto'];
}
$getbycashbal = mysql_query("select *, SUM(amount) AS totalby from $table3 WHERE voucherby = '". $ledgername ."' ");
while($databy = mysql_fetch_array($getbycashbal))
{
$bytotal = $databy['totalby'];
}
$ledgertotal = $opbal - $tototal + $bytotal;
echo "<tr>";
echo "<td class='test'>" . $gname . "</td>";
echo "<td>Rs. $ledgertotal</td>";
echo "<td></td>";
echo "</tr>";
}
}
echo "<tr>";
echo "<td style='text-align:right'>Total</td>";
echo "<td></td>";
echo "<td>Rs.</td>";
echo "</tr>";
}
echo "</table>";
I want to try multiple while but doesn't work.
How can I solve these issues?
I tried different way to solve this...
//TABLE 1 = GROUPMASTER
$table1 = $_SESSION['table1'];
//TABLE 2 = LEDGERMASTER
$table2 = $_SESSION['table2'];
//TABLE 3 = TRANSECTIONMASTER
$table3 = $_SESSION['table3'];
echo "<table align='center' border=1>";
echo "<tr>";
echo "<td colspan=2 style='text-align:center'><b> CAPITAL and LIABILITIES</b></td>";
echo "<td style='text-align:center'><b> Amount </b></td>";
echo "</tr>";
echo "<tr>";
$liabilitytotal = 0;
echo "<td colspan=3><b>CAPITAL</b></td></tr>";
$categorytotal = 0;
$groupnamelist = mysql_query("select groupname from $table1 WHERE under = 'Capital'");
while($data = mysql_fetch_array($groupnamelist))
{
$grouptotal = 0;
$gname = $data ['groupname'];
echo "<tr>";
echo "<td class='test'>" . $gname . "</td>";
$ledgername = mysql_query("SELECT ledgername from $table2 WHERE groupname = '". $gname ."' ");
while($datato = mysql_fetch_array($ledgername))
{
$lname = $datato['ledgername'];
$getbytotalquery = mysql_query("SELECT SUM(amount) FROM $table3 WHERE voucherby = '". $lname ."' ");
$gettototalquery = mysql_query("SELECT SUM(amount) FROM $table3 WHERE voucherto = '". $lname ."' ");
$getopbal = mysql_result($getopbalquery,0,0);
$getbytotal = mysql_result($getbytotalquery,0,0);
$gettototal = mysql_result($gettototalquery,0,0);
$result = $getopbal - $gettototal + $getbytotal;
if ($result == null)
{
$result = 0;
}
$grouptotal = $grouptotal + $result;
}
$categorytotal = $categorytotal + $grouptotal;
echo "<td style='text-align:right'>$grouptotal</td><td></td></tr>";
}
$liabilitytotal = $liabilitytotal + $categorytotal;
echo "<tr>";
echo "<td></td>";
echo "<td></td>";
echo "<td style='text-align:right'>$categorytotal</td>";
echo "</tr>";
echo "</table>";```
I tried my best..
And I will try to also solve this query to another way...
Thank you.. I think and I hope It's helpful..
I want to read out data from an sql-database an show them in a table. This works well. Now, I would like to show only those columns with at least one value in it and not the empty ones (containing NULL, 0, empty string). This works with the following example:
enter code here
<TABLE width="500" border="1" cellpadding="1" cellspacing="1">
<?php
$query = mysql_query("SELECT * FROM guestbook", $db);
$results = array();
while($line = mysql_fetch_assoc($query)){
$results[] = $line;
$Name = array_column($results, 'Name');
$Home = array_column($results, 'Home');
$Date = array_column($results, 'Date');
$Emptycolumn = array_column($results, 'Emptycolumn');
$Comment = array_column($results, 'Comment');
$City = array_column($results, 'City');
}
echo "<TR>";
if(array_filter($Name)) {echo "<TH>Name</TH>";}
if(array_filter($Home)){echo "<TH>Home</TH>";}
if(array_filter($Date)){echo "<TH>Date</TH>";}
if(array_filter($Emptycolumn)){echo "<TH>Emptycolumn</TH>";}
if(array_filter($Comment)){echo "<TH>Comment</TH>";}
if(array_filter($City)){echo "<TH>City</TH>";}
echo "</TR>";
$query = mysql_query("SELECT * FROM guestbook", $db);
while($line = mysql_fetch_assoc($query)){
echo "<TR>";
if(array_filter($Name)) {echo "<TD>".$line['Name']."</TD>";}
if(array_filter($Home)) {echo "<TD>".$line['Home']."</TD>";}
if(array_filter($Date)) {echo "<TD>".$line['Date']."</TD>";}
if(array_filter($Emptycolumn)) {echo "<TD>".$line['Emptycolumn']."</TD>";}
if(array_filter($Comment)) {echo "<TD>".$line['Comment']."</TD>";}
if(array_filter($City)) {echo "<TD>".$line['City']."</TD>";}
echo "</TR>";
}
?>
</TABLE>
Since the column-names of my table are highly variable (depending on the query), the table is generated by looping through the result-array, first the column-names, then the values in the rows:
enter code here
$sql = "SELECT DISTINCT $selection FROM $tabelle WHERE
$whereclause"; //will be changed to PDO
$result = mysqli_query($db, $sql) or die("<b>No result</b>"); //Running
the query and storing it in result
$numrows = mysqli_num_rows($result); // gets number of rows in result
table
$numcols = mysqli_num_fields($result); // gets number of columns in
result table
$field = mysqli_fetch_fields($result); // gets the column names from the
result table
if ($numrows > 0) {
echo "<table id='myTable' >";
echo "<thead>";
echo "<tr>";
echo "<th>" . 'Nr' . "</th>";
for($x=0;$x<$numcols;$x++){
$key = array_search($field[$x]->name, $custom_column_arr);
if($key !== false){
echo "<th>" . $key . "</th>";
}else{
echo "<th>" . $field[$x]->name . "</th>";
}
}
echo "</tr></thead>";
echo "<tbody>";
$nr = 1;
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $nr . "</td>";
for ($k=0; $k<$numcols; $k++) { // goes around until there are no
columns left
echo "<td>" . $row[$field[$k]->name] . "</td>"; //Prints the data
}
echo "</tr>";
$nr = $nr + 1;
} // End of while-loop
echo "</tbody></table>";
}
}
mysqli_close($db);
Now, I tried to integrate the array_column() and array_filter()-blocks of the example above into the loops, but unfortunately, it didn´t work. I´m sure, this is easy for a professional and I would be very grateful, if someone could help me with this problem!
Thank you very much in advance!!
How can I add LIMIT query in it? I have adding it in
$SQL = "SELECT * FROM eins_policy LIMIT 500 ";
but it did not display the list.
For example:
If I choose 500 records per page;
Total records is 3560 records;
If now I on page 1, meaning (Page number – 1) * 500 = 0, and my Offset is 0;
If now I on page 2, meaning (Page number – 1) * 500 = (2 – 1) * 500 = 500, and Offset is 500, meaning 501 to 1000 is the records fetched;
If now I on page 3, meaning (Page number – 1) * 500 = (3 – 1) * 500 = 1000, and Offset is 1000, meaning 1001 to 1500 is the records fetched;
policylist.php
function eins_listPolicy($page, $record ,$search)
{
//connect to database
base_connectDatabase();
$searchs = explode(" ", $search);
$SQL = "SELECT * FROM eins_policy ";
$countSearch = 0;
foreach ($searchs as &$value) {
if ($countSearch == 0) {
$SQL .= "WHERE ";
} else {
$SQL .= "AND ";
}
$SQL .= "(eins_plcy_code LIKE '%".$value."%' OR
eins_plcy_client IN (SELECT eins_clnt_id FROM eins_client WHERE eins_clnt_full_name LIKE '%".$value."%') OR
eins_plcy_insurance_company IN (SELECT eins_icomp_id FROM eins_insurance_company WHERE eins_icomp_name LIKE '%".$value."%') OR
eins_plcy_agent IN (SELECT eins_agent_id FROM eins_agent WHERE eins_agent_user_id IN (SELECT base_u_id FROM base_users WHERE base_u_name LIKE '%".$value."%')) OR
eins_plcy_policy_type IN (SELECT base_u_id FROM base_users WHERE base_u_name LIKE '%".$value."%') OR
eins_plcy_start_date LIKE '%".$value."%' OR
eins_plcy_end_date LIKE '%".$value."%' OR
eins_plcy_payment_status = '".$value."' OR
eins_plcy_status LIKE '%".$value."%')
";
$countSearch ++;
}
$result = base_executeSQL($SQL);
$total = base_num_rows($result);
if(is_int($total/$record)) {
$tpages = $total/$record;
} else {
$tpages = floor($total/$record)+1;
}
$start = $record * ($page-1);
$adjacents = 3;
$reload = 'policy_list.php';
$count = 0;
$zeroRecord = false;
$RSQL = "LIMIT ".$start.", ".$record."";
$getPolicySQL = base_executeSQL($SQL.$RSQL);
while($Policy_row = base_fetch_array($getPolicySQL))
if (base_num_rows($getPolicySQL)!= 0) {
$inscompName = eins_getInscompDetail($Policy_row["eins_plcy_insurance_company"]);
$agentName = eins_getAgentDetail($Policy_row["eins_plcy_agent"]);
$clientName = eins_getClientDetail($Policy_row["eins_plcy_client"]);
$polocytypeName = eins_getPolicytypeDetail($Policy_row["eins_plcy_policy_type"]);
$count = $count + 1;
echo "<tr>";
echo "<td>". $count ."</td>";
echo "<td>". $Policy_row["eins_plcy_code"] ."</td>";
echo "<td>". $polocytypeName['eins_ptype_name'] ."</td>";
echo "<td>". $inscompName['eins_icomp_name'] ."</td>";
echo "<td>". $agentName['eins_agent_full_name'] ."</td>";
echo "<td>". $clientName['eins_clnt_full_name'] ."</td>";
echo "<td>". $Policy_row["eins_plcy_payment_status"] ."</td>";
echo "<td>". $Policy_row["eins_plcy_status"] ."</td>";
echo "<td><img src=\"". BASE_IMG_ICON_EDIT ."\" /></td>";
echo "<td><img src=\"". BASE_IMG_ICON_DELETE ."\" /></td>";
echo "</tr>";
}
if (base_num_rows($getPolicySQL)== 0) {
echo "<tr><td colspan = \"9\" align = \"center\">There is no record!</td></tr>";
$zeroRecord = true;
}
if($zeroRecord == false) {
echo "<tfoot bgcolor=\"white\">";
echo "<tr>";
echo "<td colspan=\"10\">";
$record .= "&search=".$search;
eins_paginate($reload, $page, $tpages, $adjacents, $record, $total) ;
echo "</td>";
echo "</tr>";
}
//close the database
base_closeDatabase();
}
The correct usage of LIMIT is LIMIT offset, max rows
First 500 rows : ... LIMIT 0,500
The next 500: ... LIMIT 500,500 and so on.
Reference: http://dev.mysql.com/doc/refman/5.7/en/select.html
I need to output a table based on two other tables as shown below:
case: there are two table "tbl_schedule" and "tbl_report"
this is my script:
$sql = mysql_query("SELECT*, count(*) as schedule_date FROM mst_schedule WHERE schedule_date LIKE '%$date' GROUP BY schedule_account") or die (mysql_error());
while ($data = mysql_fetch_array($sql)) {
$account = schAccount($data['schedule_account']);
$sql2 = mysql_query("SELECT * FROM trn_reportsch WHERE schedule_id='$data[schedule_id]' GROUP BY schedule_id");
echo "<tr>";
echo "<td>".ucfirst($account['admin_fullname'])."</td>";
while ($data2 = mysql_fetch_array($sql2)) {
echo "<td>".$data2['rating']."</td>";
}
echo "<td>".$data['schedule_date']."</td>";
echo "</tr>";
}
So far I don't get the desired output. How should I change the script?
Your code is almost correct.
Add following lines:
$sql = mysql_query("SELECT*, count(*) as schedule_date FROM mst_schedule WHERE schedule_date LIKE '%$date' GROUP BY schedule_account") or die(mysql_error());
while ($data = mysql_fetch_array($sql)) {
$account = schAccount($data['schedule_account']);
$sql2 = mysql_query("SELECT * FROM trn_reportsch WHERE schedule_id='$data[schedule_id]' GROUP BY schedule_id");
echo "<tr>";
echo "<td>" . ucfirst($account['admin_fullname']) . "</td>";
$bad = $good = $vGood = 0; // <-- ADD THIS LINE
while ($data2 = mysql_fetch_array($sql2)) {
if($data2['rating'] <=2){ // BAD
$bad++;
} else if($data2['rating'] <= 3){ // GOOD
$good++;
} else if($data2['rating'] > 3){ // VERY GOOD
$vGood++;
}
}
echo "<td>" . $bad . "</td>"; // Display the final value for bad
echo "<td>" . $good . "</td>"; // Display the final value for good
echo "<td>" . $vGood . "</td>"; // Display the final value for very good
echo "<td>" . $data['schedule_date'] . "</td>";
echo "</tr>";
}