Pagination doesn't work - php

I am going to make a pagination for my members page, I have a created 8 pagination numbers from 1 to 8 so that when i click on each page , it should display only 1 row of particular database table,database table consists of 8 rows, But in my code when i click , correct page numbers are passing but it doesn't update and display particular selected pagination row , please can u help me in getting solution to this please.
members.php
<?php
include('assets/page_header.php');
include('db/db.php');
$page="";
if(isset($_GET['page']))
{
$page=$_GET['page'];
}
?>
<html>
<head><title></title>
<style>
h1 {
text-align:center;
}
</style>
</head>
<?php
/*$memno=mysql_real_escape_string($_POST['memno']);
$memname=mysql_real_escape_string($_POST['name']);
$address=mysql_real_escape_string($_POST['address']);
$phonenumber=mysql_real_escape_string($_POST['phno']);
$renewaldate=mysql_real_escape_string($_POST['renewaldate']);
$maxborrowlimit=mysql_real_escape_string($_POST['maxborrowlimit']);
$status=mysql_real_escape_string($_POST['status']);*/
?>
<h1>MEMBERS PAGE</h1>
<?php
$str="select * from member LIMIT 1,1 ";
$query1=mysql_query($str);
echo "<table align='center'>";
echo "<tr><th><MemberNumber</th><th>MemberName</th><th>Address</th><th>Phonenumber</th><th>RenewalDate</th><th>MaxBorrowLimit</th><th>Status</th><th colspan=2>Action</th></tr>";
while($query2=mysql_fetch_array($query1))
{
echo "<tr>";
echo "<td>".$query2['memno']."</td>";
echo "<td>".$query2['name']."</td>";
echo "<td>".$query2['address']."</td>";
echo "<td>".$query2['phno']."</td>";
echo "<td>".$query2['renewaldate']."</td>";
echo "<td>".$query2['maxborrowlimit']."</td>";
echo "<td>".$query2['status']."</td>";
echo "<td><button class='button1' data-toggle='tooltip' title='Delete' id=".$query2['memno']." value='delete' name='delete'><img id='image' src='./images/trash.png'/></button></td>";
echo "<td><a id='colour' class='tooltip' href='membereditform.php?mem_no=".$query2['memno']."'><img id='image' src='./images/small.gif'/><span class='tooltiptext' >Edit</span></a></td>";
echo "</tr>";
}
echo "</table>";
?>
<?php
if($page=="" || $page=='1')
{
$page1=0;
}
else
{
$page1=($page*4)-4;
}
$query1=mysql_query("select * from member");
$count=mysql_num_rows($query1);
$s=$count/1;
echo $s;
echo "<br>";
for($i=1;$i<=$s;$i++)
{
?><a href="members.php?page=<?php echo $i ?>" style="text-decoration":none,"Text-align":center;><?php echo $i?></a><?php
}
?>

Try your code like this:
<?php
include('assets/page_header.php');
include('db/db.php');
?>
<html>
<head><title></title>
<style>
h1 {
text-align:center;
}
</style>
</head>
<?php
/*$memno=mysql_real_escape_string($_POST['memno']);
$memname=mysql_real_escape_string($_POST['name']);
$address=mysql_real_escape_string($_POST['address']);
$phonenumber=mysql_real_escape_string($_POST['phno']);
$renewaldate=mysql_real_escape_string($_POST['renewaldate']);
$maxborrowlimit=mysql_real_escape_string($_POST['maxborrowlimit']);
$status=mysql_real_escape_string($_POST['status']);*/
?>
<h1>MEMBERS PAGE</h1>
<?php
$num_rec_per_page = 10;
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * $num_rec_per_page;
$str = "select * from member LIMIT $start_from, $num_rec_per_page";
$query1=mysql_query($str);
echo "<table align='center'>";
echo "<tr><th><MemberNumber</th><th>MemberName</th><th>Address</th><th>Phonenumber</th><th>RenewalDate</th><th>MaxBorrowLimit</th><th>Status</th><th colspan=2>Action</th></tr>";
while($query2=mysql_fetch_array($query1))
{
echo "<tr>";
echo "<td>".$query2['memno']."</td>";
echo "<td>".$query2['name']."</td>";
echo "<td>".$query2['address']."</td>";
echo "<td>".$query2['phno']."</td>";
echo "<td>".$query2['renewaldate']."</td>";
echo "<td>".$query2['maxborrowlimit']."</td>";
echo "<td>".$query2['status']."</td>";
echo "<td><button class='button1' data-toggle='tooltip' title='Delete' id=".$query2['memno']." value='delete' name='delete'><img id='image' src='./images/trash.png'/></button></td>";
echo "<td><a id='colour' class='tooltip' href='membereditform.php?mem_no=".$query2['memno']."'><img id='image' src='./images/small.gif'/><span class='tooltiptext' >Edit</span></a></td>";
echo "</tr>";
}
echo "</table>";
?>
<?php
$sql = "select * from member";
$rs_result = mysql_query($sql); //run the query
$total_records = mysql_num_rows($rs_result); //count number of records
$total_pages = ceil($total_records / $num_rec_per_page);
if($total_records > 0) {
echo "<a href='members.php?page=1'> ".'<'." </a> "; // Goto 1st page
}
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='members.php?page=".$i."'> ".$i." </a> ";
};
if($total_records > 0) {
echo "<a href='members.php?page=$total_pages'> ".'>'." </a> "; // Goto last page
}
?>
</html>

Related

How to check table cell in database and output results?

I am bit new to php and sql.
I am simply reading from a database table and echoing images to a page. The images are then styled with a text aligned in the middle saying 'Play Video'.
In the table 'adcTable' some entries do not have a video stored.
I would like to have the rows/entries with video say 'Play Video' and the ones without just show the image.
Not to sure how bess to explain. Hope to get some assistance.
<php
$sql = "SELECT client_id, images, video FROM adcTable";
$result = $conn->query($sql);
$count = 1;
echo "<table border = '0' width='720'><tr>";
while($row = $result->fetch_assoc()) {
echo "<td><div class='ccontainer'>"; ?><img class="cimage" src= "<?php echo $row ["images"];?> " ><?php echo "
<div class='middle'>
<div class='text'>Play Video</div>
</div>
</div>
</td>";
if ($count++ % 2 == 0) {
echo "</tr><tr>";
}
echo "</tr></table>";
?>
Thanks guys, I was able to use the example provided by BusinessPlanQuickBuilder to solve.
$sql = "SELECT client_id, files, file FROM adcTable";
$result = $conn->query($sql);
$count = 1;
echo "<table border = '0' width='720'><tr>";
while($row = $result->fetch_assoc()) {
if ($row['file'] == "VidUploads/"){
echo "<td>"; ?><img class="cimage" src= "<?php echo $row ["files"];?> " ><?php echo "
</td>";
echo '<script type="text/javascript">',
'$( ".text" ).css( "border", "3px solid red" );',
'</script>';
} else{
echo "<td><div class='ccontainer'>"; ?><img class="cimage" src= "<?php echo $row ["files"];?> " ><?php echo "
<div class='middle'>
<div class='text'>Video</div>
</div>
</div>
</td>";
}
if ($count++ % 2 == 0) {
echo "</tr><tr>";
}
}
echo "</tr></table>";
?>
Use if empty condition on video column. This is the fundamental code, add your formatting as required.
<?php
while($row = $result->fetch_assoc()) {
if (empty ($row['video']) ) {
echo $row ["images"];
} else {
echo "Play Video";
}
}
?>
SO reference to related post

delete button is not working

I am going to delete the particular row of my database, but when i delete the button it tells me that undefined display in deletebookajax.php on line no 54..
So can u please tell me where i have gone wrong...
here is my code
book.php is for displaying the entire book details....
<?php
include('assets/page_header.php');
include('db/db.php');
?>
<html>
<head><title></title>
<style>
h1 {
text-align:center;
}
</style>
</head>
<h1>BOOKS PAGE</h1>
<?php
error_reporting(0);
$str="select * from books";
$query1=mysql_query($str);
$q=mysql_num_rows($query1);
//$query2=mysql_query("select status from bookrentalinfo where bookid=$bookid");
//echo $query2;
//$res=mysql_fetch_array($query2);
echo "<table align='center'>";
echo "<tr><th>BookID</th><th>Title</th><th>Author</th><th>Publisher</th><th>Numcopies</th><th>Shelfno</th><th>Status</th><th colspan=2 >Action</th></tr>";
while($rows=mysql_fetch_array($query1))
{
echo "<tr>";
echo "<td>".$rows['bookid']."</td>";
echo "<td>".$rows['title']."</td>";
echo "<td>".$rows['author']."</td>";
echo "<td>".$rows['publisher']."</td>";
echo "<td>".$rows['numcopies']."</td>";
echo "<td>".$rows['shelfno']."</td>";
echo "<td>".$rows['status']."</td>";
echo "<td><button class='button1' data-toggle='tooltip' title='Delete' id=".$rows['bookid']." value='delete' name='delete'><img id='image' src='./images/trash.png'/></button></td>";
echo "<td><a id='colour' class='tooltip' href='edit1form.php?book_id=".$rows['bookid']."'><img id='image' src='./images/small.gif'/><span class='tooltiptext' >Edit</span></a></td>";
echo "</tr>";
}
echo "</table>";
?>
<div id="display">
</div>
<!--echo "<td><button type='button'>delete</button></td>";
/*if($res['status']=="BORROWED")
{
echo "Sorry You Can't Delete The Book";
}
else
{
echo "The Row Is Deleted";
}*/-->
<script type="text/javascript">
$('document').ready(function() {
$(".button1").click(function(e) {
$('[data-toggle="tooltip"]').tooltip();
var strconfirm = confirm("Are you sure you want to delete?");
if(strconfirm)
{
var bookid=$(this).attr("id");
alert(bookid);
dataString='book_id='+bookid;
alert(dataString);
// AJAX Code To Submit Form.
$.ajax({
type: "GET",
url: "db/deletebookajax.php",
data: dataString,
cache: false,
success: function(result){
alert("submitted"+result);
$('#display').html(result);
window.location.href="books.php";
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
}
else {
return false;
}
});
});
</script>
</body>
</html>
deletebookajax.php
<?php
if(isset($_GET['book_id']))
{
$bookid = $_GET['book_id'];
echo $bookid;
}
include('../assets/page_header.php');
?>
<input type="hidden" name="bookid" value=<?php if(isset($bookid)) echo $bookid; ?>>
<?php
include('db.php');
//if(isset($_POST['bookid']))
//
//$bookid=mysql_real_escape_string($_POST['bookid']);
$delete = "delete from books WHERE bookid=$bookid";
$query1=mysql_query($delete);
echo $query1;
if($query1)
{
$q=mysql_query("select * from books");
echo $q;
$display="<table>";
$display.="<tr><th>BookID</th><th>Title</th><th>Author</th><th>Publisher</th><th>numcopies</th><th>shelfno</th><th>status</th><th>Action</th></tr>";
while($row=mysql_fetch_array($q))
{
$display.="<tr>";
$display.= "<td>".$row['bookid']."</td>";
$display.= "<td>".$row['title']."</td>";
$display.= "<td>".$row['author']."</td>";
$display.= "<td>".$row['publisher']."</td>";
$display.="<td>".$row['numcopies']."</td>";
$display.="<td>".$row['shelfno']."</td>";
$display.="<td>".$row['status']."</td>";
$display.= "</tr>";
}
$display.="</table>";
}
else
{
$display.= "U can't delete The book";
}
//echo "nothing";
echo $display;
?>
</body>
</html>
Change Your deletebookajax.php code
<?php
if(isset($_GET['book_id']))
{
$bookid = $_GET['book_id'];
echo $bookid;
}
include('../assets/page_header.php');
?>
<input type="hidden" name="bookid" value=<?php if(isset($bookid)) echo $bookid; ?>>
<?php
//include('db.php');
//if(isset($_POST['bookid']))
//
//$bookid=mysql_real_escape_string($_POST['bookid']);
$user="root";
$server="localhost";
$password="";
$db="library book";
$dbconn = mysqli_connect($server,$user,$password,$db);
$delete = "delete from books WHERE bookid=$bookid";
$query1=mysqli_query($dbconn, $delete);
echo $query1;
if($query1)
{
$q=mysqli_query($dbconn, "select * from books");
echo $q;
$display="<table>";
$display.="<tr><th>BookID</th><th>Title</th><th>Author</th><th>Publisher</th><th>numcopies</th><th>shelfno</th><th>status</th><th>Action</th></tr>";
while($row=mysqli_fetch_array($dbconn, $q))
{
$display.="<tr>";
$display.= "<td>".$row['bookid']."</td>";
$display.= "<td>".$row['title']."</td>";
$display.= "<td>".$row['author']."</td>";
$display.= "<td>".$row['publisher']."</td>";
$display.="<td>".$row['numcopies']."</td>";
$display.="<td>".$row['shelfno']."</td>";
$display.="<td>".$row['status']."</td>";
$display.= "</tr>";
}
$display.="</table>";
}
else
{
$display = "U can't delete The book";
}
//echo "nothing";
echo $display;
?>
</body>
</html>

Pagination links disappear when clicked on the next or any other page

I'm having a problem with PHP pagination.
When I click on the next page to see next results, pagination links and data just disappear.
I tried various Pagination classes, but decided to stop on this solution.
Will be extremely grateful if someone helps to find a fix.
<html>
<head>
<title></title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<?Php
require "config_pag.php";
$field = $_POST['field'];
$state = $_POST['state'];
$page_name="search.php";
$start=$_GET['start'];
if(strlen($start) > 0 and !is_numeric($start)){
echo "Data Error";
exit;
}
$eu = ($start - 0);
$limit = 2;
$this1 = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
$nume = $dbo->query("select count(id) from posts WHERE state = '$state' AND field = '$field'")->fetchColumn();
echo "<TABLE class='t1'>";
echo "<tr><th>ID</th><th>State</th><th>Fields</th><th>Description</th></tr>";
$query=" SELECT * FROM posts WHERE state = '$state' AND field = '$field' limit $eu, $limit ";
foreach ($dbo->query($query) as $row) {
$m=$i%2;
$i=$i+1;
echo "<tr class='r$m'><td>".$row['id']."</td><td>".$row['state']."</td><td>".$row['field']."</td><td>".$row['description']."</td></tr>";
}
echo "</table>";
if($nume > $limit ){
echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>";
if($back >=0) {
print "<a href='$page_name?start=$back'><font face='Verdana' size='2'>PREV</font></a>";
}
echo "</td><td align=center width='30%'>";
$i=0;
$l=1;
for($i=0;$i < $nume;$i=$i+$limit){
if($i <> $eu){
echo " <a href='$page_name?start=$i'><font face='Verdana' size='2'>$l</font></a> ";
}
else { echo "<font face='Verdana' size='4' color=red>$l</font>";}
$l=$l+1;
}
echo "</td><td align='right' width='30%'>";
if($this1 < $nume) {
print "<a href='$page_name?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";}
echo "</td></tr></table>";
}
?>
</html>

call or create session variable in SUM

I am not very familiar with PHP or MySQL, but after researching here I have been able to learn and get very close to what I need and build my first sum query. I am trying to read the database and sum values based on several variables.
I need the reservation_pax from the reservations table where reservation_time is 8:00 where reservation_hidden = 0 and reservation_date is something. I can manually enter the date and it works. I am now trying to use a session code already in the script or find a way to to dynamically add based on selected date.
Here is the code I have working without the dynamic aspect or session.
$result = mysql_query("SELECT SUM(reservation_pax)
FROM reservations
WHERE reservation_time = '8:00:00'
AND reservation_date = '2014-10-27'
AND reservation_hidden ='0'") ;
if ($result === false) {
die(mysql_error()); // TODO: better error handling
}
while($row = mysql_fetch_array($result)) {
echo $row['SUM(reservation_pax)'];
}
Here is the full code of the page where I entered the above addition. Can anyone help me figure out how to call the selected date rather than having to manually enter.
<!-- Begin reservation table data -->
<br/>
<table class="global resv-table-small" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<?php
echo "<td class='noprint'> </td>";
echo "<td>Time</td>";
echo "<td>Guests/Type</td>";
echo "<td>Name</td>";
echo "<td>Special Instructions/Notes</td>";
echo "<td class='noprint'>Table</td>";
echo "<td class='noprint'>Status</td>";
echo "<td class='noprint'>Created</td>";
echo "<td class='noprint'>Details/Delete</td>";
echo "</tr>";
// Clear reservation variable
$reservations ='';
if ($_SESSION['page'] == 1) {
$reservations = querySQL('all_reservations');
}else{
$reservations = querySQL('reservations');
}
// reset total counters
$tablesum = 0;
$guestsum = 0;
if ($reservations) {
//start printing out reservation grid
foreach($reservations as $row) {
// reservation ID
$id = $row->reservation_id;
$_SESSION['reservation_guest_name'] = $row->reservation_guest_name;
// check if reservation is tautologous
$tautologous = querySQL('tautologous');
echo "<tr id='res-".$id."'>";
echo "<td";
// daylight coloring
if ($row->reservation_time > $daylight_evening){
echo " class='evening noprint'";
}else if ($row->reservation_time > $daylight_noon){
echo " class='afternoon noprint'";
}else if ($row->reservation_time < $daylight_noon){
echo " class='morning noprint'";
}
echo " style='width:10px !important; padding:0px;'> </td>";
echo "<td id='tb_time'";
// reservation after maitre message
if ($row->reservation_timestamp > $maitre['maitre_timestamp'] && $maitre['maitre_comment_day']!='') {
echo " class='tautologous' title='"._sentence_13."' ";
}
echo ">";
echo "<strong>".formatTime($row->reservation_time,$general['timeformat'])."</strong></td>";
echo "<td id='tb_pax'><strong class='big'>".$row->reservation_pax."</strong> <span class='noprint'>";
printType($row->reservation_hotelguest_yn);
//echo "<img src='images/icons/user-silhouette.png' class='middle'/>";
echo "</span></td><td style='width:10%' id='tb_name'><span class='noprint'>".printTitle($row->reservation_title)."</span><strong> <a id='detlbuttontrigger' href='ajax/guest_detail.php?id=".$id."'";
// color guest name if tautologous
if($tautologous>1){echo" class='tautologous tipsy' title='"._tautologous_booking."'";}
echo ">".$row->reservation_guest_name."</a></strong>";
// old reservations symbol
if( (strtotime($row->reservation_timestamp) + $general['old_days']*86400) <= time() ){
echo "<img src='images/icons/clock-bolt.png' class='help tipsyold middle smicon' title='"._sentence_11."' />";
}
// recurring symbol
if ($row->repeat_id !=0) {
echo " <img src='images/icons/loop-alt.png' alt='"._recurring.
"' title='"._recurring."' class='tipsy' border='0' >";
}
echo"</td><td style='width:10%' id='tb_note'>";
if ($_SESSION['page'] == 1) {
echo $row->outlet_name;
}else{
echo $row->reservation_notes;
}
echo "</td>";
if($_SESSION['wait'] == 0){
echo "<td class='big tb_nr' style='width:85px;' id='tb_table'><img src='images/icons/table_II.png' class='tipsy leftside noprint' title='"._table."' /><div id='reservation_table-".$id."' class='inlineedit'>".$row->reservation_table."</div></td>";
}
echo "<td class='noprint'><div>";
getStatusList($id, $row->reservation_status);
echo "</div></td>";
echo "<td class='noprint'>";
echo "<small>".$row->reservation_booker_name." | ".humanize($row->reservation_timestamp)."</small>";
echo "</td>";
echo "<td class='noprint'>";
// MOVE BUTTON
// echo "<a href=''><img src='images/icons/arrow.png' alt='move' class='help' title='"._move_reservation_to."'/></a>";
// WAITLIST ALLOW BUTTON
if($_SESSION['wait'] == 1){
$leftspace = leftSpace(substr($row->reservation_time,0,5), $availability);
if($leftspace >= $row->reservation_pax && $_SESSION['outlet_max_tables']-$tbl_availability[substr($row->reservation_time,0,5)] >= 1){
echo" <a href='#' name='".$id."' class='alwbtn'><img src='images/icons/check-alt.png' name='".$id."' alt='"._allow."' class='help' title='"._allow."'/></a> ";
}
}
// EDIT/DETAIL BUTTON
echo "<a href='?p=102&resID=".$id."'><img src='images/icons/pen-fill.png' alt='"._detail."' class='help' title='"._detail."'/></a> ";
// DELETE BUTTON
if ( current_user_can( 'Reservation-Delete' ) && $q!=3 ){
echo"<a href='#modalsecurity' name='".$row->repeat_id."' id='".$id."' class='delbtn'>
<img src='images/icons/delete.png' alt='"._cancelled."' class='help' title='"._delete."'/></a>";
}
echo"</td></tr>";
$tablesum ++;
$guestsum += $row->reservation_pax;
}
}
?>
</tbody>
<tfoot>
<tr style="border:1px #000;">
<td class=" noprint"></td><td></td>
<td colspan="2" class="bold"><?php echo $guestsum;?> <?php echo _guest_summary;?></td>
<td></td>
<td colspan="2" class="bold"><?php echo $tablesum;?> <?php echo _tables_summary;?></td>
<td colspan="2" class="bold"><?php
$result = mysql_query("SELECT SUM(`reservation_pax`) FROM `reservations` WHERE `reservation_time` = '8:00:00' AND `reservation_date` = '{$_SESSION['selectedDate']}' AND `reservation_hidden` ='0'") ;
if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
while($row = mysql_fetch_array($result))
{
echo $row['SUM(reservation_pax)'];
}
?>
<?php echo '/ 40 ', _guest_summary, ' -8:00 AM';?></td>
<td></td>
<?php
if($_SESSION['wait'] == 0){
//echo "<td></td>";
}
?>
</tr>
</tfoot>
</table>
<!-- End reservation table data -->
you can use alias field, as:
$result = mysql_query("SELECT SUM(reservation_pax) AS reserve_sum
FROM reservations WHERE reservation_time = '8:00:00'
AND reservation_date = '2014-10-27'
AND reservation_hidden ='0'"
) ;
....
and get access it as:
while($row = mysql_fetch_array($result))
{
echo $row['reserve_sum'];
}
$result = mysql_query("SELECT SUM(reservation_pax) FROM reservations WHERE reservation_time = '8:00:00' AND reservation_date = '{$_SESSION['selectedDate']}' AND reservation_hidden ='0'") ;
if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
while($row = mysql_fetch_array($result))
{
echo $row['SUM(reservation_pax)'];
}
?>

How do I not display certain parts of the table from my database?

http://i.stack.imgur.com/5OTgG.png
The image above describes my problem, and provides a visual.
As you can see, I just want to reserve or delete the two spaces on the top-right. How can I achieve this?
This is my current code:
<html>
<head>
</head>
<body>
<?php
$objConnect = mysql_connect("localhost","root","") or die(mysql_error());
$objDB = mysql_select_db("dbname");
$strSQL = "SELECT * FROM album";
if (!isset($_GET['Page'])) $_GET['Page']='0';
$objQuery = mysql_query($strSQL);
$Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 12; // Per Page
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_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;
}
$strSQL .=" order by albumID ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
echo"<table border=\"0\" cellspacing=\"1\" cellpadding=\"1\"><tr>";
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
echo "<td>";
$intRows++;
?>
<center>
<img src="https://s3.amazonaws.com/thumbnails/<?=$objResult["Picture"];?>" height="190" width="190" /></a><br>
<?=$objResult["albumName"];?>
<br>
</center>
<?php
echo"</td>";
if(($intRows)%4==0)
{
echo"</tr>";
}
}
echo"</tr></table>";
?>
<br>
<?php
//DELETED PAGINATION CODE for the sake of simplicity in StackOverflow
?>
</body>
</html>
<?php
mysql_close($objConnect);
?>
In your loop, you'd need to put in some conditional statement to break from the default behavior.
while($objResult = mysql_fetch_array($objQuery))
{
if(($intRows)%4==0)
{
echo"<tr>"; // You forgot this.
}
echo "<td>";
$intRows++;
if ($intRows == 3 || $intRows == 4) :
?>
<!-- special cells -->
<?
else:
?>
<center>
<img src="https://s3.amazonaws.com/thumbnails/<?=$objResult["Picture"];?>" height="190" width="190" /></a><br>
<?=$objResult["albumName"];?>
<br>
</center>
<?php
endif;
echo"</td>";
if(($intRows)%4==0)
{
echo"</tr>";
}
}
// You also need this part:
echo ($intRows %4 > 0 ? "</tr>" : "") . "</table>";
Your $intRows variable seems to be counting cells, not rows. So you can simply identify the top right cells by their numbers, which should be 2 and 3. Add this to your loop:
$cell = 0;
echo '<table border="1" cellpadding="2" cellspacing="1"><tr>';
while($objResult = mysql_fetch_array($objQuery))
{
if($cell % 4 == 0) {
echo '</tr><tr>';
}
if($cell == 2 || $cell == 3) {
echo '<td>RESERVED</td>';
} else {
echo '<td>'.$objResult["albumName"].'</td>';
}
$cell++;
}
echo '</tr></table>';

Categories