PHP Pagination not functioning correcetly, stops on 6th page - php

I've recently got back into doing some PHP coding but have got stuck on something with PHP Pagination, it would seem that anything I tried either results in it not counting the pages and displaying on one page of results, or just stops at Page 6 and goes no further, I know with the data that is stored in the MySQL database, it should be showing 52 pages of results at 12 per page.
So I'm in need of some help, I thought it was working until I hit the won't go further than Page 6 after putting in 100's of entires into the database.
The code is as follows
<?php
//
//How to print date
//
if($print_date == 1)
{
$print_date = '%d.%m.%Y';
}
elseif($print_date == 2)
{
$print_date = '%m.%d.%Y';
}
elseif($print_date == 3)
{
$print_date = '%W, %M %D %Y';
}
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
} // if
$get_matches = mysql_query("SELECT
O.OpponentName AS hometeam, OP.OpponentName AS awayteam,
LM.LeagueMatchHomeGoals AS goals_home,
LM.LeagueMatchAwayGoals AS goals_away,
LM.LeagueMatchID AS id,
DATE_FORMAT(LM.LeagueMatchDate, '$print_date') AS date
FROM tplls_leaguematches LM, tplls_opponents O, tplls_opponents OP
WHERE O.OpponentID = LM.LeagueMatchHomeID AND
OP.OpponentID = LM.LeagueMatchAwayID AND
LeagueMatchSeasonID LIKE '$defaultseasonid'
ORDER BY LM.LeagueMatchDate");
$get_matches = #mysql_query($SQL) or die("Error Processing Fixtures");
$query_data = mysql_fetch_row($get_matches);
$numrows = $query_data[0];
$rows_per_page = 12;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno > $lastpage) {
$pageno = $lastpage;
} // if
if ($pageno < 1) {
$pageno = 1;
} // if
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$get_matches2 = mysql_query("SELECT
O.OpponentName AS hometeam, OP.OpponentName AS awayteam,
LM.LeagueMatchHomeGoals AS goals_home,
LM.LeagueMatchAwayGoals AS goals_away,
LM.LeagueMatchID AS id,
DATE_FORMAT(LM.LeagueMatchDate, '$print_date') AS date
FROM tplls_leaguematches LM, tplls_opponents O, tplls_opponents OP
WHERE O.OpponentID = LM.LeagueMatchHomeID AND
OP.OpponentID = LM.LeagueMatchAwayID AND
LeagueMatchSeasonID LIKE '$defaultseasonid'
ORDER BY LM.LeagueMatchDate, hometeam $limit",$connection)
or die(mysql_error());
while($row = mysql_fetch_array($get_matches2))
{
?>
More to add, if I take out the first SELECT statement, I get the same result?

Try this out. It's just your code with some minor modifications.
<?php
//
//How to print date
//
switch ($print_date)
{
case 1:
$print_date = '%d.%m.%Y';
break;
case 2:
$print_date = '%m.%d.%Y';
break;
case 3:
$print_date = '%W, %M %D %Y';
}
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
} // if
$clause = "
FROM tplls_leaguematches LM, tplls_opponents O, tplls_opponents OP
WHERE O.OpponentID = LM.LeagueMatchHomeID AND
OP.OpponentID = LM.LeagueMatchAwayID AND
LeagueMatchSeasonID LIKE '$defaultseasonid'
ORDER BY LM.LeagueMatchDate";
$query = "SELECT COUNT(*) as num $clause";
$result = #mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];
$rows_per_page = 12;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno > $lastpage) {
$pageno = $lastpage;
} // if
if ($pageno < 1) {
$pageno = 1;
} // if
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query = "SELECT
O.OpponentName AS hometeam, OP.OpponentName AS awayteam,
LM.LeagueMatchHomeGoals AS goals_home,
LM.LeagueMatchAwayGoals AS goals_away,
LM.LeagueMatchID AS id,
DATE_FORMAT(LM.LeagueMatchDate, '$print_date') AS date $clause $limit";
$get_matches = mysql_query($query, $connection)
or die(mysql_error());
while($row = mysql_fetch_array($get_matches))
{
?>
It's actually what #g.salakirov suggested but in the context of all the code you supplied. I haven't tested it, but it should work. (Famous last words. :D)

You need to use mysql_num_rows(resource $result) rather than mysql_fetch_row(resource $result) to get the number of rows in here: .
$get_matches = #mysql_query($SQL) or die("Error Processing Fixtures");
$query_data = mysql_fetch_row($get_matches);
$numrows = $query_data[0];
$rows_per_page = 12;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
Alternatively, you can use a "count(*)" query in the beginning to get the number of entries, which will be significantly faster.
For example:
$get_matches = mysql_query("SELECT
count(*) as resultCount
FROM tplls_leaguematches LM, tplls_opponents O, tplls_opponents OP
WHERE O.OpponentID = LM.LeagueMatchHomeID AND
OP.OpponentID = LM.LeagueMatchAwayID AND
LeagueMatchSeasonID LIKE '$defaultseasonid'
ORDER BY LM.LeagueMatchDate");

Related

How to make pagination in PHP, mysql

I wonder how to make pagination in PHP
May I ask you a favor of you?
This code have not error.
But I do not know what $current_page make
<?php
$con = mysqli_connect("localhost", "root", "", "dbdb") or die("error");
$page_size = 10;
$page_list_size = 10;
if (isset($_POST['search'])) {
$valueTosearch = $_POST['valueTosearch'];
$query = "SELECT * FROM `shipment` WHERE CONCAT(`Ship_Date`,`Model_No`,`Serial_No`)LIKE'%" . $valueTosearch . "%' ORDER BY Ship_Date DESC LIMIT $page_size";
$search_result = filterTable($query);
} else {
$query = "SELECT * FROM `shipment` ORDER BY Ship_Date DESC LIMIT $page_size";
$search_result = filterTable($query);
}
function filterTable($query) {
$con = mysqli_connect("localhost", "root", "", "dbdb");
$filter_Result = mysqli_query($con, $query);
return $filter_Result;
}
echo "<center><h1>info</h1></center> <br><br>";
$ret = mysqli_query($con, $query);
if ($ret) {
echo mysqli_num_rows($ret), " <br><br>";
$count = mysqli_num_rows($ret);
} else {
echo "error :" . mysqli_error($con);
exit();
}
$query = "SELECT count(*) FROM shipment";
$result_count = mysqli_query($con, $query);
$result_row = mysqli_fetch_array($result_count);
$total_row = $result_row[0];
if ($total_row <= 0)
$total_row = 0;
$total_page = ceil($total_row / $page_size);
$current_page = ceil();
?>
I wonder how to make pagination in PHP
May I ask you a favor of you?
This code have not error.
But I do not know what $current_page make
I think you have a mistake on the mysql query, limitting to $page_size you will get only a number of results = $page_size, but you will always get the $page-size 1st elements, if you want to page results you need to add offset.
This way first page will be $page_size elements with offset 0, second page $page_size elements with $page_size offset, and in general the nth page will be $page_size elements with (n-1) times $page_size offset.
In the last line you are missing an argument:
$current_page = ceil(); should be $current_page = ceil($lowest_element_in_result_set/$page_size);
$current_page should be the number of the page user want to view and this would be a input from user.
this is my implementation.
hope this will help you .
$pagenum = $_GET['pagenum'];//get the page number user want to view
$con = mysqli_connect("localhost", "root", "9272", "new_platform_7");
$query = 'select * from table1';
$filter_Result = mysqli_query($con, $query);//execute query without limit to get total number of rows
$rows = mysqli_num_rows($filter_Result);//total number of rows
if (!(isset($pagenum)))
{
$pagenum = 1;//if user hasn't give page number set page to page number 1
}
$page_rows = 30;//the page size (number of rows in each page)
$last = ceil($rows/$page_rows);//total number of pages //use ceil to avoid fractions
if ($pagenum < 1){ //if user give negative page number. set page number to 1
$pagenum = 1; //this will happen if user clicked the Previous page link when current page is 1
}elseif ($pagenum > $last) //if page number is greater than calculated number of pages . set page number to last page
{
$pagenum = $last; //this will happen if user clicked the next page link when current page is the last page
}
//($pagenum - 1) * $page_rows calculates where to start the lmit
$query.= ' limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;//limit result
echo $query;
$filter_Result = mysqli_query($con, $query);//execute query with limits
//pagination links
echo 'First Page';
echo 'Previous Page';
echo 'Next Page';
echo 'Last Page';
Try this in a simple way.
<?php
$link = mysqli_connect("localhost","roo","","dbname");
if(!$link):
echo "something wrong with the database connection";
endif;
//check to see if the page (value) is available
if(isset($_GET['pageNo']):
$page = $_GET['pageNo'];
else:
$page = "";
endif;
if($page == "" || $page == 1):
$start_to_count_rowNo = 0;
else:
$start_to_count_rowNo = ($page * &item_displayed_per_page) - &item_displayed_per_page;
endif;
//here choose how many items do you want to display per page
&item_displayed_per_page = 10;
//Now select the data to display them
$query = "SELECT * FROM table_name LIMIT $start_to_count_rowNo, $item_displayed_per_page";
$readData = mysqli_query($link, $query);
//obtaining total number of data(rows) in a database
$sql = mysqli_query($link,"SELECT * FROM table_name");
$total_row = mysqli_num_rows($sql);
$pageNo = ceil($total_row / &item_displayed_per_page);
//using bootstrap add class pager in unordered list to style the list
?>
<ul class="pager">
<?php
//display out the page # like 1,2,3 ....
for($i = 0; $i <= $pageNo; $i++){
echo "</li><a href='pagename.php?pageNo={$i}'>{$i}</a></li>";
}
?>
</ul>

Paginating error with joining tables

Need some help if possible?
I’m trying to add pagination to my code.. The problem I am getting is the pagination script works perfectly well without the JOIN statement and the JOIN statement works when I exclude the pagination script so they both work just not together.
It counts the results correctly with both scripts together just wont show the data.
The question is how do I get them to work together as I get an error:
Any help would be grateful
ini_set('display_errors', 1);
error_reporting(~0);
$Keyword = null;
if(isset($_POST["term"])){
$Keyword = $_POST["term"];
}
if(isset($_GET["term"])){
$Keyword = $_GET["term"];
}
$sql = "SELECT * FROM table1
INNER JOIN table2 ON (table1.member_id = members.id)
WHERE MATCH (name,location) AGAINST ('%".$Keyword."%' IN NATURAL LANGUAGE MODE)";
$query = mysqli_query($conn,$sql);
$num_rows = mysqli_num_rows($query);
$per_page = 2;
$page = 1;
if(isset($_GET["Page"])) {
$page = $_GET["Page"];
}
$prev_page = $page-1;
$next_page = $page+1;
$row_start = (($per_page*$page)-$per_page);
if($num_rows<=$per_page) {
$num_pages =1;
} else if(($num_rows % $per_page)==0) {
$num_pages =($num_rows/$per_page) ;
} else {
$num_pages =($num_rows/$per_page)+1;
$num_pages = (int)$num_pages;
}
$row_end = $per_page * $page;
if($row_end > $num_rows) {
$row_end = $num_rows;
}
$sql .= "SELECT * ORDER BY ID ASC LIMIT $row_start ,$row_end ";
$query = mysqli_query($conn,$sql);
while($result=mysqli_fetch_array($query,MYSQLI_ASSOC)) {

Problems with php pagination function

I have two php files:
1. functions.php
2. index.php
The functions.php file has a series of functions that query MySQL database to produce different result sets. For example, i have two functions; one that returns all data whose year 2016, and the other that returns all the data whose year is 2015.
For both queries i desire to have php pagination for the result sets returned. An example of the function that returns results for all data whose years are 2015 and 2016 looks like this:
function get2015(){
$con = dbConnect();
$refs_per_page = 20;
$query = "select * from mytable where year = 2015";
$sql=$con->prepare($query);
$sql->execute();
$total = $sql->rowCount();
$pages = ceil($total/$refs_per_page);
echo "$total <br>";
if (isset($_GET['page']) && is_numeric($_GET["page"])){
$page = (int) $_GET['page'];
}//endif
if($page =="" || $page ==1){
$page=0;
}
else{
$page = ($page * $refs_per_page)-$refs_per_page;
}
//
$query = "select * from mytable where year = 2015 limit $page, $refs_per_page";
$sql=$con->prepare($query);
$sql->execute();
$sql->setFetchMode(PDO::FETCH_ASSOC);
while ($row=$sql->fetch()){
$title = $row['title'];
$authors = $row['authors'];
echo "<b>$title</b>" . "<br>" . $authors . "<p>";
}
//
for($x=1; $x<=$pages; $x++){
?> <?php echo $x;?> <?php
}
}
//function get records for 2016
function get2016(){
$con = dbConnect();
$refs_per_page = 20;
$query = "select * from mytable where year = 2016";
$sql=$con->prepare($query);
$sql->execute();
$total = $sql->rowCount();
$pages = ceil($total/$refs_per_page);
echo "$total <br>";
if (isset($_GET['page']) && is_numeric($_GET["page"])){
$page = (int) $_GET['page'];
}//endif
if($page =="" || $page ==1){
$page=0;
}
else{
$page = ($page * $refs_per_page)-$refs_per_page;
}
//
$query = "select * from mytable where year = 2016 limit $page, $refs_per_page";
$sql=$con->prepare($query);
$sql->execute();
$sql->setFetchMode(PDO::FETCH_ASSOC);
while ($row=$sql->fetch()){
$title = $row['title'];
$authors = $row['authors'];
echo "<b>$title</b>" . "<br>" . $authors . "<p>";
}
//
for($x=1; $x<=$pages; $x++){
?> <?php echo $x;?> <?php
}
}
The code in index.php code looks like this
<?php
include "functions.php";
$page = $_GET["page"];
if($page){
if($page=="get2015"){
get2015();
}
if($page=="get2016"){
get2016();
}
}
?>
<html>
Archive<br>
2015<br>
2016<br>
</html>
<?php ?>
The first page renders okay but when i click on the second page the page goes blank. #Syed below has suggested the use of an offset variable, which while useful does the same thing as the $page variable in the code above. How do i get pagination to work? I highly suspect that the problem is how i am calling the pages on index.php
Your sould make $offset variable and minus 1 from it and then multiply by $per_page
For example
User in index.php your offset variable calculate like that.
// offset should be equal to 0 and query should be
// SELECT * FROM your_table WHERE year='2015' LIMIT 0, 20
(page=1 - 1) = 0 * $per_page = 20
User in index.php?page=2 your offset variable calculate like that.
// offset should be equal to 20 and query should be
// SELECT * FROM your_table WHERE year='2015' LIMIT 20, 20
(page=2 - 1) = 1 * $per_page = 20
// offset should be equal to 40 and query should be
// SELECT * FROM your_table WHERE year='2015' LIMIT 40, 20
(page=3 - 1) = 2 * $per_page = 40
$sql = sprintf("SELECT COUNT(*) FROM your_table WHERE year='%s'", $_GET['year']);
// Query to database and store in pages variable
$total_record = $con->query($sql)->result();
$page = ( isset($_GET['page']) && is_numeric($_GET['page'])) ? $_GET['page'] : 1;
$per_page = 20;
$offset = ($page - 1) * $per_page;
$pages = ceil($total/$per_page);
$sql = sprintf("SELECT * FROM your_table WHERE year='%s' LIMIT %s, %s", $_GET['year'], $offset, $per_page);
// QUERY TO DATABASE
for($i=1; $i<=$pages; $i++){
if ($page == $i) {
echo '<span class="active">'. $i .'</span>';
}else{
echo '' .$i .'';
}
}

i wrote some code for fetch data from database ,in mysql code is working and in pdo it is not working

This is mysql connection coding, it is working fine
the same code i wrote with pdo connection,it is not working i'm new to php please help me to get out of this problem.
thanks in advance
<?php
error_reporting(0);
ini_set('max_execution_time', 600);
require_once 'config.php';
if(isset($_GET["nm_mask"]))
$nm_mask = $_GET['nm_mask'];
else
$nm_mask = "";
if(isset($_GET["cd_mask"]))
$cd_mask = $_GET['cd_mask'];
else
$cd_mask = "";
if(isset($_GET["func"]))
$func = $_GET['func'];
else
$func = "";
$where = "WHERE 1=1";
if($nm_mask!='')
$where.= " AND Login LIKE '$nm_mask%'";
if($cd_mask!='')
$where.= " AND Manager_Login LIKE '$cd_mask%'";
if($func!='')
$where.= " AND Function LIKE '$func%'";
$page = $_GET['page']; // get the requested page
$limit = $_GET['rows']; // get how many rows we want to have into the grid
$sidx = $_GET['sidx']; // get index row - i.e. user click to sort
$sord = $_GET['sord']; // get the direction
if(!$sidx) $sidx =1; // connect to the database
$result = mysqli_query("SELECT COUNT(*) AS count FROM EmpMasterTB ".$where);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$count = $row['count'];
if( $count >0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
if ($limit<0) $limit = 0;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
if ($start<0) $start = 0;
$SQL = "SELECT * from EmpMasterTB ". $where ." ORDER BY $sidx $sord LIMIT $start , $limit";
$result = mysqli_query( $SQL ) or die("Couldn?t execute query.".mysqli_error());
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
$responce->rows[$i]['id']=$row[WeekNo].$row[Login];
$responce->rows[$i]['cell']=array($row['WeekNo'],$row['WeekBeginning'],$row['SITE'],$row['Name'],$row['WFH'],$row['Login'],$row['Manager_Login'],$row['Lead'],$row['Cost_center'],$row['Business_Title'],$row['Function'],$row['Workgroup'],$row['Login_time'],$row['ROLE'],$row['Secondary_Skill'],$row['Weekoff'],""); $i++;
}
echo json_encode($responce);
?>
PDO connection code
<?php
error_reporting(0);
ini_set('max_execution_time', 600);
require_once 'config.php';
if(isset($_GET["nm_mask"]))
$nm_mask = $_GET['nm_mask'];
else
$nm_mask = "";
if(isset($_GET["cd_mask"]))
$cd_mask = $_GET['cd_mask'];
else
$cd_mask = "";
if(isset($_GET["func"]))
$func = $_GET['func'];
else
$func = "";
$where = "WHERE 1=1";
if($nm_mask!='')
$where.= " AND Login LIKE '$nm_mask%'";
if($cd_mask!='')
$where.= " AND Manager_Login LIKE '$cd_mask%'";
if($func!='')
$where.= " AND Function LIKE '$func%'";
$page = $_GET['page']; // get the requested page
$limit = $_GET['rows']; // get how many rows we want to have into the grid
$sidx = $_GET['sidx']; // get index row - i.e. user click to sort
$sord = $_GET['sord']; // get the direction
if(!$sidx) $sidx =1; // connect to the database
$count = $dbh->exec("SELECT COUNT(*) AS count FROM EmpMasterTB ".$where);
if( $count >0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
if ($limit<0) $limit = 0;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
if ($start<0) $start = 0;
$SQL = "SELECT * from EmpMasterTB ". $where ." ORDER BY $sidx $sord LIMIT $start , $limit"; /*** The SQL SELECT statement ***/
$stmt = $dbh->query($SQL); /*** fetch into an PDOStatement object ***/
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
/*** echo number of columns ***/
$obj = $stmt->fetch(PDO::FETCH_OBJ);
/*** loop over the object directly ***/
{
$responce->rows[$i]['id']=$obj->WeekNo.$obj->Login;
$responce->rows[$i]['cell']=array($obj->WeekNo ,$obj->WeekBeginning ,$obj->SITE ,$obj->Name ,$obj->WFH ,$obj->Login ,$obj->Manager_Login ,$obj->Lead ,$obj->Cost_center ,$obj->Business_Title ,$obj->Function ,$obj->Workgroup ,$obj->Login_time ,$obj->ROLE ,$obj->Secondary_Skill ,$obj->Weekoff ); $i++;
}
echo json_encode($ );
?>
You have missed for loop and you didn't pass response in json_encode().
Please check my below code:
/*** echo number of columns ***/
$objs = $stmt->fetch(PDO::FETCH_OBJ);
/*** loop over the object directly ***/
foreach($objs as $obj)
{
$responce->rows[$i]['id']=$obj->WeekNo.$obj->Login;
$responce->rows[$i]['cell']=array($obj->WeekNo ,$obj->WeekBeginning ,$obj->SITE ,$obj->Name ,$obj->WFH ,$obj->Login ,$obj->Manager_Login ,$obj->Lead ,$obj->Cost_center ,$obj->Business_Title ,$obj->Function ,$obj->Workgroup ,$obj->Login_time ,$obj->ROLE ,$obj->Secondary_Skill ,$obj->Weekoff ); $i++;
}
echo json_encode($responce );

PHP Database Query instead of using 0 and 1 use true or false/ paid or unpaid

new Query
$query = "SELECT COUNT(*) FROM payments $sCriteria";
$result = mysql_query($query) or die("Error encountered on retrieving logs.");
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
$rows_per_page = 30;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno > $lastpage) {
$pageno = $lastpage;
}
if ($pageno < 1) {
$pageno = 1;
}
$limit = "LIMIT ".($pageno - 1) * $rows_per_page .",".$rows_per_page;
$rs = mysql_query("SELECT * FROM payments $sCriteria ORDER BY pay_date DESC $limit") or die("Error encountered on retrieving logs.".mysql_error());
$current_rows = mysql_num_rows($rs);
if ($current_rows) {
while ($rows = mysql_fetch_array($rs)) {
echo "<tr>
<td>".date("m/d/Y n:H:s",strtotime($rows["pay_date"]))."</td>
<td>".$rows["po_no"]."</td>
<td>".$rows["or_no"]."</td>
<td>".$rows["sold_to"]."</td>
<td>Php ".number_format($rows["amt_to_pay"],2,".",",")."</td>
<td>Php ".number_format($rows["amt_paid"],2,".",",")."</td>
<td>".$rows["pay_status"]."</td>
**<td>".$rows["verified"]."</td>**
<td><a href='pay_preview.php?id=$iPayID' class='action preview' title='Print Preview'><img src='images/preview.png' class='action_img' /></a></td>
Old Query
$query = "SELECT COUNT(*) FROM payments";
$result = mysql_query($query) or die("Error encountered on retrieving payment details.");
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
$rows_per_page = 10;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno > $lastpage) {
$pageno = $lastpage;
}
if ($pageno < 1) {
$pageno = 1;
}
$limit = "LIMIT ".($pageno - 1) * $rows_per_page .",".$rows_per_page;
$rs = mysql_query("SELECT * FROM payments ORDER BY pay_date DESC, po_id $limit") or die("Error encountered on retrieving payment details.");
$current_rows = mysql_num_rows($rs);
if ($current_rows) {
while ($rows = mysql_fetch_array($rs)) {
$iPayID = $rows["pay_id"];
$iPoID = $rows["po_id"];
$dSubTotal = get_po_subtotal($iPoID);
$sPoNo = get_value("po","po_no","WHERE po_id=$iPoID");
$iDis = get_value("po","discount","WHERE po_id=$iPoID");
$dNet = $dSubTotal - ($dSubTotal * ($iDis/100));
$sStat = $rows["pay_status"];
switch($sStat) {
case "Paid": $sColor = "class='blue'";break;
default: $sColor = "";break;
}
if ($rows["verified"]) {
$sVerified = "Yes";
}
else {
$sVerified = "No <a href='payment_verification.php?id=$iPayID' class='action verify' title='Verify' id='$iPayID'>(verify)</a>";
}
echo "<tr>
<td>".date('Y-m-d',strtotime($rows["pay_date"]))."</td>
<td>".$rows["or_no"]."</td>
<td>$sPoNo</td>
<td>".$rows["sold_to"]."</td>
<td class='right'>Php ".number_format($rows["amt_to_pay"],2,".",",")."</td>
<td class='right'>Php ".number_format($rows["amt_paid"],2,".",",")."</td>
<td $sColor>".$rows["pay_status"]."</td>
<td>$sVerified</td>
<td><a href='pay_preview.php?id=$iPayID' class='action preview' title='Print Preview'><img src='images/preview.png' class='action_img' /></a></td>
</tr>\n";
}
}
My problem is that on my new query I can't change the Verified output to Paid or Unpaid, It stays with a 0 and 1 ** I did also copy and compare it with my old and new query, it just that it didn't work, can someone help me with it? thank you so much.
I would suggest something like as an example to use a condition in mysql:
I your SQL statement specify the columns and don't use SELECT *
SELECT IF(Field > 0,'TRUE','FALSE') AS verified FROM Table
You can add a field to change it to paid or unpaid as well
SELECT IF(Field > 0,'Paid','Unpaid') AS verified FROM Table
Serves as an example. you can add any condition and result output
ALSO
In you code I cannot determine where $sVerified is ever assigned a value?
I am not sure exactly what your asking.. I don't know if your needing to print the value to the page, or if your needing to change it for another query..
Maybe a switch case would work.. Allowing you to change the format to however you need it. Basically converting your old queries result so your new query can handle it..
$value = 0; // or false.. this is your value from first query
$newval = null; // just placeholder for newval in switch
switch($value) {
case 0:
$newval = 'Unpaid';
break;
case 1:
$newval = 'Paid';
break;
default:
$newval = 'Unknown';
}
echo $newval;

Categories