Filter system not working - php

Hello so i made my filter system its a simple one only location and price range are set for now everything looks like this :
so the problem i have is that min and max price range filter doesn't work location filter are working as it should be the only problem i face is min and max price got no error or warning nothing but eater nothing happens to.
php code above :
$cat1 = '';
if(isset($_GET["catid"])){
$p1 = '';
$p2 = '';
$catid = $_GET["catid"];
$l1 = substr($catid,0,1);
$l2 = substr($catid,1,1);
$p1 = "CAT".$l1;
if(!empty($l2)){
$p2 = "CAT".$l1."-".$l2;
$p3 = $p2;
}
$cat1 = #$lang[$p1];
$cat2 = #$lang[$p2];
}
$postid = '';
$userid = '';
$pricemin = '';
$pricemax = '';
$location = '';
if(isset($_POST["filter"])){
$pricemin = $_POST["min"];
$pricemax = $_POST["max"];
$location = $_POST["location"];
}
main page code :
<div class="fp">
<div class="filter">
<b style="padding-left: 10px;">Filters:</b>
<form class="filterform" action="" method="post"><br>
Location: <br>
<input name="location" ><br>
Price Range:<br>
Min:<input type="text" name="min" size="5"> Max:<input type="text" name="max" size="5"><br><br>
<input class="submit-button" type="submit" name="filter" value="Filter">
</form>
</div>
<div class="posts">
<div id="adcat"><?php
if(!empty($cat2)){
?>
<a href="cat.php?catid=<?php echo $l1; ?>" ><?php echo $cat1." » "; ?></a><span><?php echo $cat2; ?></span>
<?php
} else {
echo "<font color='grey'>".$cat1."</font>";
}
?>
</div><br><br>
<div id="detailformscat">
<?php
if(empty($p1) && empty($p2)){
$sql = "SELECT * FROM posts p JOIN images i ON p.id = i.postid ";
if(!empty($location)){
$sql .= "AND location='$location'";
}
if(!empty($min)){
$sql.= "AND price>='$min' ";
}
if(!empty($max)){
$sql.= "AND price<='$max' ";
}
} else if(!empty($p2)){
$sql = "SELECT * FROM posts p JOIN images i ON p.id = i.postid WHERE catid='$p2' ";
if(!empty($location)){
$sql .= "AND location='$location'";
}
if(!empty($min)){
$sql.= "AND price>='$min' ";
}
if(!empty($max)){
$sql.= "AND price<='$max' ";
}
} else {
$sql = "SELECT * FROM posts p JOIN images i ON p.id = i.postid WHERE p.catid LIKE '$p1%' ";
if(!empty($location)){
$sql .= "AND location='$location'";
}
if(!empty($min)){
$sql.= "AND price>='$min' ";
}
if(!empty($max)){
$sql.= "AND price<='$max' ";
}
}
$res = mysqli_query($connect,$sql);
while ($row = mysqli_fetch_assoc($res)) {
$postid = $row["postid"];
?>
<div id="ads">
<div id="adfavcat">
<?php if(!isset($_SESSION["userid"])) { ?>
<?php } else {
$userid = $_SESSION["userid"];
$sql2 = "SELECT * FROM fav WHERE userid='$userid' AND postid='$postid' ";
$res2 = mysqli_query($connect,$sql2);
$rowcount = mysqli_num_rows($res2);
if ($rowcount > 0){ ?>
<?php
} else { ?>
<?php }
} ?>
</div>
<div id="titlepic">
<?php echo $row["title"]; ?><br>
<img src="<?php if(!empty($row["path1"])) { echo $row["path1"]; } else echo "image/noimage.png"; ?>" height="100px" width="150px">
</div>
<div id="datescat">
<b>Date Added:</b> <?php echo date('m/d/Y H:i', $row["dateadded"]); ?><br>
<b>Renew Date:</b> <?php if($row["renewdate"] > 0){ echo date('m/d/Y H:i', $row["renewdate"]); } ?><br>
<b>Location:</b> <?php echo $row["location"]; ?><br>
<b>Price:</b> <?php echo $row["price"]."&pound"; ?><br>
</div>
</div>
<hr width="100%">
<?php
}
?>
</div>
</div>
</div>

I think it's because you are treating the price as a string, in the sql query you wrote
$sql.= "AND price>='$min' ";
Try with cast/sanitize/filter input variables $min & $max to integers and removing the quotes.
--- by the way, I personally would also change some things:
use atom instead of brackets
use an ORM and remove the query from the html page (the view)
if 2 is not possible, try to move all php logic to the php file instead of the html part
remove all that IFs and try to write a code without lots of repetitions
You are also joining the tables instead of filtering, try changing
$sql = "SELECT * FROM posts p JOIN images i ON p.id = i.postid ";
with
$sql = "SELECT * FROM posts p JOIN images i ON p.id = i.postid WHERE p.id > 0 ";
change
$pricemin = '';
$pricemax = '';
with
$min = '';
$max = '';

Related

How to retain the value of a variable in a page even after refreshing

I have a search page and the pagination is set but each time i refresh the search variable sets back to default... It also restores to default if i try to navigate to within pagination... So i want to know how to keep the value of the search variable...
The search form is in another page.
I have tried using this session_start() method but it doesn't seem to retain the search variable...
<?php require_once("../includes/initialize.php"); ?>
<?php
session_start();
if(isset($_POST['submit'])){
// 1. the current page number ($current_page)
$page = !empty($_GET['page']) ? (int)$_GET['page'] : 1;
// 2. records per page ($per_page)
$per_page = 2;
// 3. total record count ($total_count)
$_SESSION['search'] = $_POST['search'];
echo $_SESSION['search'];
$search = $database->escape_value($_SESSION['search']);
$sql = "SELECT COUNT(*) FROM products WHERE image LIKE '%$search%'";
$sql .= " OR title LIKE '%$search%'";
$sql .= " OR slug LIKE '%$search%'";
$sql .= " OR description LIKE '%$search%'";
$sql .= " OR price LIKE '%$search%'";
$sql = $database->query($sql);
$sql = $database->fetch_array($sql);
$total_count = array_shift($sql);
// Find all photos
// use pagination instead
$pagination = new Pagination($page, $per_page, $total_count);
// Instead of finding all records, just find the records
$sql = "SELECT * FROM products WHERE image LIKE '%$search%'";
$sql .= " OR title LIKE '%$search%'";
$sql .= " OR slug LIKE '%$search%'";
$sql .= " OR description LIKE '%$search%'";
$sql .= " OR price LIKE '%$search%'";
$sql .= " ORDER by id DESC";
$sql .= " LIMIT {$per_page}";
$sql .= " OFFSET {$pagination->offset()}";
$photos = Product::find_by_sql($sql);
$tcount = count($photos);
}
?>
<?php include_layout_template('header2.php'); ?>
<div class="container">
<P class="lead error-msg">There are <?php echo $tcount; ?> results out of <?php echo " " . $total_count; ?></P>
<div class="row">
<div id="pagination" style="clear: both;">
<nav aria-label="Page navigation example">
<ul class="pagination">
<?php
for($i=1; $i <= $pagination->total_pages(); $i++){
if($i == $page) {
echo "<li class='page-item'><a class='page-link'> <span class=\"selected\">{$i}</span></a></li> ";
} else{
echo " <li class='page-item'><a class='page-link' href=\"search.php?page={$i}\">{$i}</a></li> ";
}
}
if($pagination->total_pages() > 1) {
if($pagination->has_previous_page()) {
echo "<li class='page-item'><a class='page-link' href=\"search.php?page=";
echo $pagination->previous_page();
echo "\">« Previous</a></li> ";
}
if($pagination->has_next_page()){
echo "<li class='page-item'><a class='page-link' href=\"search.php?page=";
echo $pagination->next_page();
echo "\">Next »</a></li>";
}
}
?>
</ul>
</nav>
</div>
</div>
</div>
<div class="container">
<div class="row">
<?php foreach ($photos as $photo): ?>
<div class="col-md-4 col-sm-6">
<div class="thumbnail">
<form method="post" action="cart.php?action=add&id=<?php echo $photo->id; ?>" role="form" class="form-vertical">
<a href="order_review.php?id=<?php echo $photo->id; ?>"><img src="<?php echo $photo->image_path();
?>" class="img-thumbnail" alt="responsive image"></a>
<div class="caption">
<h3 class="text-info text-center"><?php echo $photo->title; ?></h3>
<p class="text-muted text-center price card-header"><span class="currency">N</span><?php echo $photo->price; ?></p>
<p class="text-center"><em><?php echo $photo->description; ?></em></p>
<input type="hidden" name="id" class="form-control" value="<?php echo $photo->id; ?>" />
<input type="hidden" name="title" class="form-control" value="<?php echo $photo->title; ?>" />
<input type="hidden" name="slug" class="form-control" value="<?php echo $photo->slug; ?>" />
<input type="hidden" name="description" class="form-control" value="<?php echo $photo->description; ?>" />
<input type="hidden" name="price" class="form-control" value="<?php echo $photo->price; ?>"/>
<div class="col-sm-4 mx-auto d-block">
<select name="quantity" class="form-control" name="quantity">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
</div>
<div class="col-sm-4 col-sm-push-3 mx-auto d-block">
<input type="submit" name="add_to_cart" class="btn bg-success" value="Add to cart" />
</div><br/>
</form>
</div>
</div>
<?php endforeach;
?>
</div>
</div>
<?php include_layout_template('footer2.php'); ?>
Try to call session_start(); at the beginn of any php code. If this doesnt work create new page to test, if any sessions are working. Maybe the configuration is not correct.
<?php
session_start();
$_SESSION['foo'] = "test";
var_dump($_SESSION);
<?php
//var_dump($_POST);
//var_dump($_SESSION);
if(isset($_POST['submit']) || isset($_SESSION['search'])){
// 1. the current page number ($current_page)
$page = !empty($_GET['page']) ? (int)$_GET['page'] : 1;
// 2. records per page ($per_page)
$per_page = 2;
// 3. total record count ($total_count)
if(isset($_POST['submit'])) {
$_SESSION['search'] = $_POST['search'];
$searchvalue = $_POST['search'];
} else {
isset($_SESSION['search']);
$searchvalue = $_SESSION['search'];
}
$search = $database->escape_value($searchvalue);
$sql = "SELECT COUNT(*) FROM products WHERE image LIKE '%$search%'";
$sql .= " OR title LIKE '%$search%'";
$sql .= " OR slug LIKE '%$search%'";
$sql .= " OR description LIKE '%$search%'";
$sql .= " OR price LIKE '%$search%'";
$sql = $database->query($sql);
$sql = $database->fetch_array($sql);
$total_count = array_shift($sql);
// Find all photos
// use pagination instead
$pagination = new Pagination($page, $per_page, $total_count);
// Instead of finding all records, just find the records
$sql = "SELECT * FROM products WHERE image LIKE '%$search%'";
$sql .= " OR title LIKE '%$search%'";
$sql .= " OR slug LIKE '%$search%'";
$sql .= " OR description LIKE '%$search%'";
$sql .= " OR price LIKE '%$search%'";
$sql .= " ORDER by id DESC";
$sql .= " LIMIT {$per_page}";
$sql .= " OFFSET {$pagination->offset()}";
$photos = Product::find_by_sql($sql);
$tcount = count($photos);
}
// var_dump($_SESSION);
?>

Select multiple rows from multiple tables and print all withe php while loop

i have 3 table T1, T2, T3,
so, in T1 i want to select 1st row and select from T2 the rows related to the row selected in T1, and select from T3 rows related to T2 how have relation with row selected in T1 and print all this in one continer withe php while loop function
see the images for more descriptions
Base on what I understand with your question. This could be the answer
<?php
$db = new PDO("mysql:host=localhost", "username", "password");
$q1 = $db->prepare("SELECT * FROM T1");
$q1->execute();
$f1 = $q1->fetchAll(PDO::FETCH_ASSOC);
foreach ($f1 as $f1_items) {
echo "<tr><td>".$f1['id_cat']."</td></tr>";
$q2 = $db->prepare("SELECT * FROM T2 WHERE id_cat = ".$f1['id_cat'].";");
$q2->execute();
$f2 = $q2->fetchAll(PDO::FETCH_ASSOC);
foreach ($f2 as $f2_items) {
echo "<tr><td>\t".$f2['id_tr']."</td></tr>";
$q3 = $db->prepare("SELECT * FROM T3 WHERE id_tr = ".$f2['id_cus'].";");
$q3->execute();
$f3 = $q3->fetchAll(PDO::FETCH_ASSOC);
foreach ($f3 as $f3_items) {
echo "<tr><td>\t\t".$f2['id_cus']."</td></tr>";
}
}
}
?>
Solved and this is the code i am happy :)
$ReqFindRows = "SELECT * FROM commandes WHERE commande_status = 0 AND date(commande_le) = CURDATE()";
$STMTFindRows = $connect->stmt_init();
if(!$STMTFindRows->prepare($ReqFindRows)){
echo "No Results";
}
else {
$STMTFindRows->execute();
$ResultsFindRows = $STMTFindRows->get_result();
$x = 0;
while($ArrayCat = $ResultsFindRows->fetch_assoc()){
switch($ArrayCat['commande_importance']){
case 0 :
$importance = 'Normal';
$bgclas = "bg-blue";
break;
case 1 :
$importance = 'Urgent';
$bgclas = "bg-yellow";
break;
case 2 :
$importance = 'Immediat';
$bgclas = "bg-red";
break;
};
$prods = array();
$GetProductsInCommandeQuery = "SELECT * FROM commandes_produits WHERE commande_id = ?";
$GetProductsInCommandeSTMT = $connect->stmt_init();
if(!$GetProductsInCommandeSTMT->prepare($GetProductsInCommandeQuery)){
echo $connect->error;
}
else {
$id_toserch = $ArrayCat["commande_id"];
$GetProductsInCommandeSTMT->bind_param("s", $id_toserch );
$GetProductsInCommandeSTMT->execute();
$GetProductsInCommandeResults = $GetProductsInCommandeSTMT->get_result();
$Prodss = "";
while($GetProductsInCommandeArray = $GetProductsInCommandeResults->fetch_array()){
$prods = $GetProductsInCommandeArray["recette_id"];
$GetSupQuery = "SELECT * FROM commandes_supp WHERE tr_number = ? AND commande_id = ?";
$GetSupSTMT = $connect->stmt_init();
if(!$GetSupSTMT->prepare($GetSupQuery)){
echo $connect->error;
}
else {
$trNumber = $GetProductsInCommandeArray["tr_number"];
$GetSupSTMT->bind_param("ss", $trNumber, $id_toserch );
$GetSupSTMT->execute();
$GetSupResults = $GetSupSTMT->get_result();
$Supp = "";
while($GetSupArray = $GetSupResults->fetch_array()){
$Suppss = $GetSupArray["supp_id"];
$Supp .= '<p style="color:#F00">'.$Suppss.' </p>';
}
}
$Prodss .=
'<tr>
<td>
'.$prods.'
'.$Supp.'
</td>
<td>
A table
</td>
<td>
<button type="button" class="btn btn-sm">Servis</button>
</td>
</tr> ';
}
}
?>
<div class="col-xs-6 col-md-4" style="margin-bottom:10px;">
<div class="tiket">
<div class="tikeheader <?php echo $bgclas ?>">
<span class="commandenumber">
<i class="fa fa-star iconheader">
</i>
<?php echo $ArrayCat["commande_id"] ?> A Table
</span>
<span class="importance">
<?php echo $importance?>
</span>
</div>
<div class="tiketbody">
<table class="tiketbodytable">
<tbody>
<?php echo $Prodss ?>
</tbody>
</table>
</div>
</div>
</div>
<?php
}
}
?>
</div>
</div>
</div>
</div>
<?php
}
?>

PHP & MySQL - Update Query not updating database

I'm making a personal website and I just wanted it to be a bit easier for me to add/edit my posts without manually going into phpmyadmin.
When I go to the edit_post.php page and press update I get an "=" sign next to the pid eg.(foo.php?pid=3), and if i let it redirect to the blog page it doesn't update it.
Blog page
<?php
session_start();
include_once("../IncBlog/db.php");
?>
<?php include "../Includes/navHead.php"; ?>
<title>Adam Brickhill - Life Journal </title>
</head>
<body>
<div class="box">
<div class="header">
<nav class="nav"><p class="title"><a class="postLink" href="../IncBlog/post.php">- Lone Tree -</a></p></nav>
</div>
<!-- JOURNAL !-->
<?php
require_once("../nbbc/nbbc.php");
$bbcode = new BBCode;
$sql = "SELECT * FROM posts ORDER BY id DESC";
$res = mysqli_query($db, $sql) or die(mysqli_error());
$posts = "";
if (mysqli_num_rows($res) > 0) {
while ($row = mysqli_fetch_assoc($res)) {
$id = $row['id'];
$title = $row['title'];
$img = $row['img'];
$content = $row['content'];
$date = $row['date'];
$admin = "<div><a href='../IncBlog/del_post.php?pid$id'>Delete</a> <div><a href='../IncBlog/edit_post.php?pid$id'>Edit</a>";
$output = $bbcode->Parse($content);
ob_start();
include('../IncBlog/blogSkel.php');
$posts .= ob_get_contents();
ob_end_clean();
}
echo $posts;
}
else {
echo "There are no posts to display";
}
?>
<div class="journal">
<div class="catagories">
</div>
<!-- Date !-->
<!-- Picture !-->
<!-- Description !-->
</div>
<?php include "../Includes/navFooter.php"; ?>
<!-- SCRIPTS !-->
<?php include "../Includes/navScriptImport.php"; ?>
</div>
</body>
</html>
Edit Page
<?php
session_start();
include_once("db.php");
if (!isset($_SESSION['username'])) {
header("Location: login.php");
return;
}
$pid = $_SERVER['REQUEST_URI'];
$pid = trim($pid, "/IncBlog/edit_post.php?pid");
$pid = strip_tags($pid);
$pid = stripslashes($pid);
$pid = mysqli_real_escape_string($db, $pid);
//echo "$pid";
if ($pid == "") {
header("Location: ../Nav/life.php");
}
if (isset($_POST['update'])) {
$title = strip_tags($_POST['title']);
$content = strip_tags($_POST['content']);
$img = strip_tags($_POST['image']);
$title = mysqli_real_escape_string($db, $title);
$content = mysqli_real_escape_string($db, $content);
$img = mysqli_real_escape_string($db, $img);
$date = date("l jS \of F Y h:i:s A");
$sql = "UPDATE posts SET title='$title', content='$content', img='$img', date='$date' WHERE id=$pid";
if ($title == "" || $content == "") {
echo "The database is hungry you can't feed it nothing!";
return;
}
mysqli_query($db, $sql);
header("Location: ../Nav/life.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Blog - Post</title>
</head>
<body>
<?php
$sql_get = "SELECT * FROM posts WHERE id=$pid LIMIT 1";
$res = mysqli_query($db, $sql_get);
if (mysqli_num_rows($res) > 0) {
while ($row = mysqli_fetch_assoc($res)) {
$title = $row['title'];
$content = $row['content'];
$img = $row['image'];
echo "<form action='edit_post.php?pid=$pid' method='post' enctype='multipart/form-data'>";
echo " <input placeholder='Title' type='text' name='title' value='$title' autofocus size='48'><br /><br />";
echo " <input placeholder='Image' type='text' name='image' value='$img' autofocus size='48'><br /><br />";
echo " <textarea placeholder='Content' name='content' rows='40' cols='40'>$content</textarea><br />";
}
}
?>
<input type="submit" name="update" value="Update">
</form>
</body>
</html>
You have to set the columns and set the values for the columns.
UPDATE posts SET ( title, content, img, date ) VALUES ($title, $content, $img, $date) WHERE id = $pid;
$date = date("l jS \of F Y h:i:s A");
use instead of above line
$date = date('Y-m-d H:i:s', strtotime());
$sql = 'UPDATE posts SET title='".$title."', content='".$content."', img='".$img."', date='".$date."' WHERE id='".$pid."'";
Ok so I figured it out, very small programmers blindness but hey we all get it.
Line 66 echo "<form action='edit_post.php?pid$pid' method='post' enctype='multipart/form-data'>";
Where it says "?pid$pid" I just needed to remove the "=" that i had there.

Left-join foreach loop over array with nested array

I have two tables one for users and one for their reviews. On one page I need to show thumbnails of each user and the reviews that match that user. The problem is the LEFT JOIN creates a row for every time there is a review. So if a user has two reviews they are showing up twice in the list of thumbnails. Do I need a loop inside the loop? Everything I can think of seems really clunky. Thanks.
// Get Data
$qry = "SELECT * FROM `users` LEFT JOIN `reviews` ON users.userId = reviews.user_id WHERE installation_id = $installation_id";
$res = mysqli_query($mysqli, $qry) or die('-1'.mysqli_error($mysqli));
//$uqry = "SELECT membership FROM users WHERE userId = $uid";
//$current_user = mysqli_query($mysqli, $uqry) or die('-1'.mysqli_error($mysqli));
$getUser = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT membership FROM users WHERE userId = $uid"));
$currentUserLevel = $getUser['membership'];
?>
<div class="container">
<div class="content">
<?php if ($msgBox) { echo $msgBox; } ?>
<div class="row">
<?php $lists = array();
while($list = mysqli_fetch_assoc($res)) {
$lists[] = $list;
}
foreach($lists as $list) {
$name = stripslashes($list['usersName']);
$bio = stripslashes($list['usersBio']);
$review = stripslashes($list['comments']);
$stars = stripslashes($list['stars']); ?>
<div class="col-md-4">
<div id = "user-square">
<div class="avatar">
<img src="<?php echo $avatarDir.$list['usersAvatar']; ?>" class="publicAvatar" />
</div>
Name:<?php echo $name; ?> <br />
Bio:<?php echo $bio; ?> <br />
Review:<?php echo $review; ?> <br />
Stars: <?php echo $stars; ?> <br />
<?php
if ($currentUserLevel == 'pro') {
echo 'CONTACT SCOUT';
}
else {
echo 'Sorry you must upgrade to a Pro membership to contact this Scout';
}
?>
</div>
</div>
<?php }
?>
</div>
</div>
</div>
</div>
Change the while loop to the following:
while($list = mysqli_fetch_assoc($res)) {
$lists[$list['usersName']][$list['usersBio']][$list['stars']][] = $list['comments'];
}
That will give you a nice multidimensional array with the user name as the first key, and all that users reviews ordered by star rating. You should probably use a unique key rather than the users name as there could be duplicates, so either the email or unique row ID would be better.
You can then (VERY basic example):
$reviews = "";
foreach($lists as $username => $array) {
foreach($array as $bio => $array2) {
$name = stripslashes($username);
$bio = stripslashes($bio);
foreach($array2 as $stars => $comments_array) {
$stars = stripslashes($stars);
foreach($comments_array as $comments) {
$reviews .= $stars . " - " . stripslashes($comments) . "<br />";
}
}
// Your HTML here using $name, $bio, and $reviews(which will be star rating followed review for that user each on a new line)
echo '
<table width="400">
<tr>
<td>' . $name . '</td><td>' . $bio . '</td><td>' . $reviews . '</td>
</tr>
</table>
';
}
$reviews = "";
}

links php mysql pagination not working

i'm trying to paginate my results, the limit is working, the number of pages is properly set, but the links of the pagination don't work, i've been looking for a while and nothing, ¿can you take a look and tell me what i'm doing wrong? thanks
<?php
include("config/conexion.php");
$limit = 3;
if(isset($_GET['pag'])){
$pag= $_GET['pag'];
}else{
$pag=1;
}
$offset = ($pag-1) * $limit;
$sql = "SELECT SQL_CALC_FOUND_ROWS id, nombre, local, telefono, celular, email FROM almacenes WHERE id_cat = '".$_GET["id"]."'";
$sqlTotal = "SELECT FOUND_ROWS() as total";
$currentid = $_GET["id"];
$rs = mysql_query($sql);
$rsTotal = mysql_query($sqlTotal);
$rowTotal = mysql_fetch_assoc($rsTotal);
// Total de registros sin limit
$total = $rowTotal["total"];
?>
<?php if($_GET["id"]){ $cat = mysql_query("SELECT * FROM almacenes WHERE id_cat = '".$_GET["id"]."' ORDER BY id ASC LIMIT $offset, $limit"); if(mysql_num_rows($cat)>0){
while($row = mysql_fetch_object($cat)){ ?>
<div class="almacenbox">
<div class="shadow"></div>
<div class="white">
<div class="image"><img src=almacenes/local_111.jpg></div>
<div class="title"><?php echo $row->nombre?></div>
<div class="text">Local: <?php echo $row->local?></div>
<div class="text">Teléfono: <?php echo $row->telefono?></div>
<div class="text">Celular: <?php echo $row->celular?></div>
<div class="text"><?php echo $row->email?></div>
</div>
</div>
<?php } ?>
<?php } }else{ echo "<p>No hay resultados para mostrar</p>"; }?>
<table border="1" bordercolor="#000">
<tfoot>
<tr>
<td colspan="2">
<?php
$totalPag = ceil($total/$limit);
$links = array();
for( $i=1; $i<=$totalPag ; $i++)
{
$links[] = "<a href=almacenes.php?id=$currentid?pag=$i\>$i</a>";
}
echo implode(" - ", $links);
?>
</td>
</tr>
</tfoot> </table>
$links[] = "<a href=almacenes.php?id=$currentid?pag=$i\>$i</a>";
Should be
$links[] = '$i';
Query strings start with a ? but any name-value pairs after that first one require an ampersand.
On a side note you should never place user data directly into your query. This leaves you open to an SQL injection attack. Consider using mysql_real_escape_string or switching to the mysqli library.

Categories