Custom Pagination Not Working Well in Wordpress - php

Im just New in Wordpress and in PHP .. Now Ive just uploaded a theme in Wordpress. The Problem is The Custom Pagination is not working in Wordpress but works well in USBWebserver. It Only Just show the Same Content
<table id="maincon2-Article">
<?php
$page2 = $_GET["page2"];
if($page2 == "" || $page2 == "1"){
$pages = 0;
}
else{
$pages = ($page2*3)-3;
}
$Mobartsql = "Select * from tbl_article ORDER BY `Article_ID` DESC limit 1,3";
$result4 = $con->query($Mobartsql);
while($row4 = $result4->fetch_assoc()){
echo '<tr>
<td style="width:50%">
<img src = "https://www.stlouisreviewcenter.com/wp-content/uploads/slrc/'.$row4["Art_pic"].'" id="artpiclink2"/>
</td>
<td style="padding-left:2%" >
<h1 id="art-head2" style="color:purple">'.$row4["Art_title"].' </h5>
</td>
</tr>';
$results1 = $con->query("Select * from tbl_article ORDER BY `Article_ID` DESC");
$rows2 = $result1->num_rows/3;
$rows2 = ceil($rows2);
}
echo '<tr>
<td><br></td>
</tr>
<tr>
<td colspan="2">';
for($i=1; $i<=$rows;$i++){
?> <button> <a href="/article/?page=<?php echo $i;?>" style="text-decoration:none;"/><?php echo $i; ?></a> </button>
<?php
}
?>
</td>
</tr>
<tr>
<td><br/></td>
</tr>
</table>
Here is the Sample .. Plz Need Help ..

Related

PHP Mysql query optimization for report

I have this report which filters data from 5 tables but it is very slow takes around 10 seconds. I tried using index on some columns but it did not help.
Basically the first query is the master and the others are for filtering it if the other queries condition met then it will skip it.
this is the script:
<div class="col-md-12">
<h3>List of Outstandings</h3>
<table class="table table-condensed table-bordered table-hover small">
<thead>
<tr>
<th >#</th>
<th>PR #</th>
<th>PR Type</th>
<th>Description</th>
<th>Dep.</th>
<th>Date</th>
<th>Requester</th>
<th>Assigned to</th>
</tr>
</thead>
<tbody>
<?php
$chkk = 0;
$sql = "SELECT * FROM msr WHERE Status ='Approved' ";
$result6 = $connn->query($sql);
if ($result6->num_rows > 0) {
$vo = 1;
while ($row0 = $result6->fetch_assoc()) {
$chkk = 0;
$MSRID = $row0["MSRID"];
$MSRType = $row0["MSRType"];
$result4 = "SELECT owner FROM tracking WHERE MSRID='$MSRID' ";
$MyRow4 = $connn->query($result4);
$row4 = $MyRow4->fetch_assoc();
$actionBy = $row4["owner"];
$resultusr = "SELECT RFQID FROM rfq WHERE MSRID='$MSRID' AND NOPO='No' ";
$MyRowusr = $connn->query($resultusr);
$rowusr = $MyRowusr->fetch_assoc();
$rfqcount = mysqli_num_rows($MyRowusr);
if ($rfqcount > 0) {
$chkk = 1;
}
$resultusr4 = "SELECT POID FROM po WHERE MSRID='$MSRID' ";
$MyRowusr4 = $connn->query($resultusr4);
$rowusr4 = $MyRowusr4->fetch_assoc();
$rfqcount4 = mysqli_num_rows($MyRowusr4);
if ($rfqcount4 > 0) {
$chkk = 1;
}
$resultusr1 = "SELECT MSRID FROM contract WHERE MSRID='$MSRID' ";
$MyRowusr1 = $connn->query($resultusr1);
$rowusr1 = $MyRowusr1->fetch_assoc();
$rfqcount1 = mysqli_num_rows($MyRowusr1);
if ($rfqcount1 > 0) {
$chkk = 1;
}
if ($chkk == 1) {
continue;
}
?>
<tr>
<td>
<?php echo $vo; ?>
</td>
<td>
<?php echo $row0["MSRID"]; ?>
</td>
<td>
<?php echo $row0["MSRType"]; ?>
</td>
<td>
<?php echo $row0["purposeofbuying"]; ?>
</td>
<td>
<?php echo depName($row0["DepRequester"]); ?>
</td>
<td>
<?php echo $row0["RequestDate"]; ?>
</td>
<td>
<?php echo reqName($row0["RequestPer"]); ?>
</td>
<td>
<?php echo reqName($actionBy); ?>
</td>
</tr>
<?php
$vo++;
}
}
?>
</tbody>
</table>
</div>
</div>
You can use subquery method instead of looping.
Example:
$sql = "SELECT *,
( SELECT owner
FROM tracking
WHERE tracking.MSRID= msr.MSRID
) AS _owner,
( SELECT RFQID
FROM rfq
WHERE rfq.MSRID= msr.MSRID
AND rfq.NOPO='No'
) AS _RFQID
FROM msr
WHERE rfq.Status ='Approved'";

Dynamic Accordion Repetitive Code

I have built a navigation page in an accordion format using mysqli and php. You can see an example at
[1]: http://www.outerhebridesalgae.uk/marine/marine-taxononic-list.php/ "Marine Algae".
This works perfectly well, but the coding is very repetitive as I am repeating the same code for each heading in the accordion. This is fine for a limited number of headings, but some of my tables have 30 or more headings! Is there a more efficient approach? Thank you for your assistance.
A sample of the code follows:
<?phprequire '../assets/includes/conn.inc.php';
$query1 = mysqli_query($connect, "SELECT * FROM marine WHERE famid='1' ORDER BY marine.species");
$row1 = mysqli_fetch_assoc($query1);
$totalRows_query1 = mysqli_num_rows($query1);
$query2 = mysqli_query($connect, "SELECT * FROM marine WHERE famid='2' ORDER BY marine.species");
$row2= mysqli_fetch_assoc($query2);
$totalRows_query2 = mysqli_num_rows($query2);
$query4 = mysqli_query($connect, "SELECT * FROM marine WHERE famid='4' ORDER BY marine.species");
$row4= mysqli_fetch_assoc($query4);
$totalRows_query4 = mysqli_num_rows($query4);
?>
<!DOCTYPE html>
<head>.......</head>
<body>
<div class="uk-panel uk-panel-box uk-margin">
<h2 class="uk-panel-title">Chlorophyta - Green Seaweeds</h2>
<div id="firstpane" class="msg_list">
<p class="msg_head"> <?php echo $row1['family']; ?><img src="../images/arrow.jpg" alt="arrow open" align="right"></p>
<div class="msg_body">
<table width="100%" >
<?php do { ?>
<tr>
<td id="marine.species"><?php echo $row1['species']; ?></td>
<?php } while ($row1 = mysqli_fetch_assoc($query1)); ?>
</tr>
</table>
</div>
<p class="msg_head"><?php echo $row2['family']; ?><img src="../images/arrow.jpg" alt="arrow open" align="right"></p>
<div class="msg_body">
<table width="100%" >
<?php do { ?>
<tr>
<td id="marine.species"><?php echo $row2['species']; ?></td>
<?php } while ($row2 = mysqli_fetch_assoc($query2)); ?>
</tr>
</table>
</div>
<p class="msg_head"><?php echo $row4['family']; ?><img src="../images/arrow.jpg" alt="arrow open" align="right"></p>
<div class="msg_body">
<table width="100%" >
<?php do { ?>
<tr>
<td id="marine.species"><?php echo $row4['species']; ?></td>
<?php } while ($row4 = mysqli_fetch_assoc($query4)); ?>
</tr>
</table>
</div></body></html>

nested if else syntax error php [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
it says syntax error t_else, what could be the problem?
it really is making me crazy for finding what did i do wrong in this code
what could be myy mistake here?
<?php
include("../mysql_connect.php");
if (isset($_POST['search_form'])) {
$page1 = $_GET['page'];
if ($page1 == "" || $page1 == 1) {
$page1 = 0;
}
else {
$page1 = ($page1 * 5) - 5;
}
$query = "select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]' ";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
?>
<table class="table table-hover" border="2">
<col width="50%"></col>
<col width="40%"></col>
<col width="20%"></col>
<tr>
<td rowspan="3">
a href="news_view.php?id=<?php echo $row['news_id']; ?>">
<img src="<?php echo $row['news_image_location'] . $row['news_image']; ?>" height="300" width="500">
</a>
</td>
<td>Title: <?php echo $row['news_title']; ?></td>
</tr>
<tr>
<td>Author: <?php echo $row['news_author']; ?></td>
</tr>
<tr>
<td>Date: <?php echo $row['news_date_filed']; ?></td>
</tr>
</thead>
</table>
<?php
}
$query1 = "select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]'";
$result1 = mysql_query($query1);
$row1 = mysql_num_rows($result1);
$pagecount = $row1 / 5;
$pagecount = ceil($pagecount);
for ($count = 1; $count <= $pagecount; $count++) {
?>
<?php echo $count ?>
<?php
}
}
else{
$page1 = $_GET['page'];
if ($page1 == "" || $page1 == 1) {
$page1 = 0;
}
else {
$page1 = ($page1 * 5) - 5;
}
$query = "select * from tbl_news where news_status='Active' limit $page1,5";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
?>
<table class="table table-hover" border="2">
<col width="50%"></col>
<col width="40%"></col>
<col width="20%"></col>
<tr>
<td rowspan="3">
<a href="news_view.php?id=<?php echo $row['news_id']; ?>">
<img src="<?php echo $row['news_image_location'] . $row['news_image']; ?>" height="300"
width="500">
</a>
</td>
<td>Title: <?php echo $row['news_title']; ?></td>
</tr>
<tr>
<td>Author: <?php echo $row['news_author']; ?></td>
</tr>
<tr>
<td>Date: <?php echo $row['news_date_filed']; ?></td>
</tr>
</thead>
</table>
<?php
}
?>
<?php
$query1 = "select * from tbl_news where news_status='Active'";
$result1 = mysql_query($query1);
$row1 = mysql_num_rows($result1);
$pagecount = $row1 / 5;
$pagecount = ceil($pagecount);
for ($count = 1; $count <= $pagecount; $count++) {
?>
<?php echo $count ?>
<?php # code...
}
}
?>
here is the full code, of what errror gives me, please help me guys it takes me a a lot of time having this kind of problem i already tried everything i could but maybe you guys could me solve my problem hahahaha it really drained my mind here , im already mindblown on what is the my currently facing problem
You are missing < at the a tag inside the first while loop (exactly on line 21 when I copy/paste your code). That might be the reason it doesn't recognize the else statement, because it can't get to it properly.
try this code. may be it resolve your problem.
I have corrected some syntax mistake in your code.
<?php
include("../mysql_connect.php");
if (isset($_POST['search_form'])) {
$page1=$_GET['page'];
if ($page1=="" || $page1==1) {
$page1=0;
}
else{
$page1=($page1*5)-5;
}
$query="select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]' ";
$result=mysql_query($query);
while ($row=mysql_fetch_array($result)) {
?>
<table class="table table-hover" border="2">
<col width="50%"></col>
<col width="40%"></col>
<col width="20%"></col>
<tr>
<td rowspan="3">
<a href="news_view.php?id=<?php echo $row['news_id'];?>">
<img src="<?php echo $row['news_image_location'].$row['news_image'];?>" height="300" width="500">
</a>
</td>
<td>Title: <?php echo $row['news_title'];?></td>
</tr>
<tr>
<td>Author: <?php echo $row['news_author'];?></td>
</tr>
<tr>
<td>Date: <?php echo $row['news_date_filed'];?></td>
</tr>
</thead>
</table>
<?php
}
$query1="select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]'";
$result1=mysql_query($query1);
$row1=mysql_num_rows($result1);
$pagecount=$row1/5;
$pagecount=ceil($pagecount);
for ($count=1; $count <= $pagecount ; $count++) {
?>
<?php echo $count?>
<?php
}
}else{
$page1=$_GET['page'];
if ($page1=="" || $page1==1) {
$page1=0;
}
else{
$page1=($page1*5)-5;
}
$query="select * from tbl_news where news_status='Active' limit $page1,5";
$result=mysql_query($query);
while ($row=mysql_fetch_array($result)) {
?>
<table class="table table-hover" border="2">
<col width="50%"></col>
<col width="40%"></col>
<col width="20%"></col>
<tr>
<td rowspan="3">
<a href="news_view.php?id=<?php echo $row['news_id'];?>">
<img src="<?php echo $row['news_image_location'].$row['news_image'];?>" height="300" width="500">
</a>
</td>
<td>Title: <?php echo $row['news_title'];?></td>
</tr>
<tr>
<td>Author: <?php echo $row['news_author'];?></td>
</tr>
<tr>
<td>Date: <?php echo $row['news_date_filed'];?></td>
</tr>
</thead>
</table>
<?php
}
$query1="select * from tbl_news where news_status='Active'";
$result1=mysql_query($query1);
$row1=mysql_num_rows($result1);
$pagecount=$row1/5;
$pagecount=ceil($pagecount);
for ($count=1; $count <= $pagecount ; $count++) {
?>
<?php echo $count?>
<?php # code...
}
}
?>

Create a simple pagination

Here's a screenshot of the page that I want to put a pagination Below is my code and I want to create a simple pagination. I tried some examples available in this site but unfortunately it doesn't work for me or I might have missed something in the code.
<?php
session_start();
$server = 'localhost';
$user = 'root';
$pass = 'root';
$connect = mysql_connect($server,$user,$pass)
or die(mysql_error());
$selectdb = mysql_select_db('des')
or die(mysql_error());
?>
<form method="post" name="action_form" action="admin2.php">
<div id="gallery1" class="lbGallery">
<table class="table" width="100%" cellpadding="10">
<tbody>
<?php
$allRecords = mysql_query('select * from cms ORDER BY id DESC limit 4');
if(is_resource($allRecords))
{
while($row = mysql_fetch_assoc($allRecords))
{
?>
<tr><ul>
<td width="30%"><li style="list-style:none"><a href="uploads/<?php echo $row['image'];?>"/><img src="uploads/<?php echo $row['image'];?>"/></li></td>
<td style="float:left; font-size:16px"><?php echo $row['name']; ?></td>
</ul>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
</form>
Try this. What is does is:
create a contant $amount en a variable $offset
Create a link (next) with which sends the value of $offset back to the script
Catch the value in $_GET['offset'];
Add the value of $amount to $offset to create a new offset.
Run MySQL statement again with the new values for LIMIT
I didn't actualy test this code for typo's, but you'll get the general idea. Hope this is of any help.
(Best to use the new mysqli statement by te way).
<?php
$amount = 4;
if (!empty($_GET['offset']))
{
$offset = $_GET['offset'] + $amount;
}
else
{
$offset = 1;
}
$allRecords = mysql_query('select * from cms ORDER BY id DESC limit $amount,$offset');
if(is_resource($allRecords))
{
while($row = mysql_fetch_assoc($allRecords))
{
?>
<tr><ul>
<td width="30%"><li style="list-style:none"><a href="uploads/<?php echo $row['image'];?>"/><img src="uploads/<?php echo $row['image'];?>"/></li></td>
<td style="float:left; font-size:16px"><?php echo $row['name']; ?></td>
</ul>
</tr>
<tr>
<td colspan="2">
Next
</td>
</tr>
<?php
}
}
?>

Showing data from category with php mysql

My tables are:
barangtbl: id, judul_barang, judul_seo, keywords, deskripsi, id_kat, id_sub, id_supersub, kategori_seo, view, gambar
kategori: id_kat, nama_kat
subkategori: id_sub, id_kat, nama_sub
supersubkategori: id_supersub, id_sub, id_kat, nama_supersub
I have a problem with showing data in category from database with PHP, the problem is when i click link: localhost/test/category.php?name=HPI, it doesn't show any data, but if I change HPI with number: 15, it show all.
15 is id_supersub data on supersubkategori table where I join with barangtbl table. So, all i want is if someone click: localhost/test/category.php?name=HPI it will show data with HPI category inside. How solve this problem?
<?php
if (isset($_GET['name']))
{
$kategori = $_GET['name'];
}
include "config.php";
if ((isset($kategori)) =='')
{
$query = "SELECT * FROM barangtbl INNER JOIN supersubkategori on supersubkategori.id_supersub = barangtbl.id_supersub ORDER BY id DESC LIMIT 0,12";
$hasil = mysql_query($query);
$numrows = mysql_num_rows($hasil);
}
else
{
echo "
<table width=\"100%\">
<tr>
<td align=\"center\"><b><font color=\"red\" size=\"2.5\">[ ".$_GET['name']." ]</b></font></td>
</tr>
</table>";
$query = "SELECT * FROM barangtbl WHERE id_supersub = '$kategori' ORDER BY id";
$hasil = mysql_query($query);
$numrows = mysql_num_rows($hasil);
}
?>
<table cellpadding="10" cellspacing="2" align="center">
<tr>
<?php
$kolom=3;
$x = 0;
if($numrows > 0)
{
while($data=mysql_fetch_array($hasil))
{
if ($x >= $kolom)
{
echo "</tr><tr>";
$x = 0;
}
$x++;
?>
<th>
<div id="title">
<a href="product.php?id=<?php echo $data['id']; ?>">
<?php echo $data['judul_barang']; ?>
</a>
<br><br>
</div>
<div id="image">
<a href="product.php?id=<?php echo $data['id']; ?>">
<img width='150' height='150' valign='top' border='1,5' src="product/<?php echo $data['gambar']; ?>" />
</a>
<br><br>
</div>
<div id="action">
<?php
echo '
<a href="product.php?id='.$data['id'].'">
<img src="images/detail.jpg"\ title="Detail Barang" border="0" width=\"50\" height=\"30\">
</a>';
?>
</div>
<hr />
</th>
<?php
}
}
?>
</tr>
</table>
Try removing the quotes
$query = "SELECT * FROM barangtbl WHERE id_supersub = $kategori ORDER BY id";

Categories