I'm trying to materialize pagination. I want to fetch like
$sql2 = "select * from phptest.memo order by num desc limit $start,$start+$scale";
and i used while paragraph to show memo and ripple (ripple database has parent field that what number of memo and it's order num primary field) but I think it seems like typed wrong code what should i do? It's image that I want make
Expected result:
Error:
<?php
session_start();
// echo "<a href='memo.php?page=$i'> $i </a>";
$scale=5; // page per writing
// start recored number newest writing is up
// $page 값에 다른 시작 레코드 넘버값, 가장 높은 글번호(최신글 부터 밑으로)
$start = ($page - 1) * $scale; //0,5,10 ...
if(!isset($_REQUEST["page"]))
{
$page = 1; // initialize seeing page
}else{
$page = $_REQUEST["page"];
}
require_once '../lib/dbconn.php';
$pdo = db_connect();
if(isset($_SESSION["userid"])){
$userid = $_SESSION["userid"];
}else{
$userid = "";
}
// start recored number newest writing is up
try{
//$sql = "select * from phptest.memo order by num desc";
$sql2 = "select * from phptest.memo order by num desc limit $start,$start+$scale";
$stmh = $pdo->query($sql2);
} catch (PDOException $ex) {`enter code here`
print "오류: ".$ex->getMessage();
}
$total_record = $stmh->rowCount();
$number = $total_record - $start;
// 전체 페이지 수 계산..
if ($total_record % $scale == 0)
$total_page = floor($total_record/$scale);
else
$total_page = floor($total_record/$scale) + 1;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<link href="../css/common.css" rel="stylesheet" type="text/css" media="all">
<link href="../css/memo.css" rel="stylesheet" type="text/css" media="all">
</head>
<body>
<div id="wrap">
<div id="header">
<?php include "../lib/top_login2.php"; ?>
</div> <!-- end of header -->
<div id="menu">
<?php include "../lib/top_menu2.php"; ?>
</div> <!-- end of menu -->
<div id="content">
<div id="col1">
<div id="left_menu">
<?php
include "../lib/left_menu.php";
?>
</div>
</div>
<div id="col2">
<div id="title">
<img src="../img/title_memo.gif">
</div>
<?php
// if(isset($_SESSION["userid"])){
?>
<div id="memo_row1">
<form name="memo_form" method="post" action="insert.php">
<?php if(isset($_SESSION['nick'])){ ?>
<div id="memo_writer"><span >▷ <?=$_SESSION['nick'] ?> </span></div>
<?php }?>
<div id="memo1"><textarea rows="6" cols="95" name="content"></textarea></div>
<div id="memo2"><input type="image" src="../img/memo_button.gif"></div>
</form>
</div> <!-- end of memo_row1 -->
<?php // }
while ($row = $stmh->fetch(PDO::FETCH_ASSOC))
{
// $stmh = $pdo->query($sql2);
//$row[$i] = $row;
// $row = $stmh2->fetch(PDO::FETCH_ASSOC);
$memo_id = $row['id'];
$memo_num = $row['num'];
$memo_date = $row['regist_day'];
$memo_nick = $row['nick'];
$memo_content = $row['content'];
$memo_content = str_replace("\n", "<br>", $row['content']);
$memo_content = str_replace(" ", " ", $memo_content);
?>
<div id="memo_writer_title">
<ul>
<li id="writer_title1"><?= $memo_num ?></li> <!--article number -->
<li id="writer_title2"><?= $memo_nick ?></li>
<li id="writer_title3"><?= $memo_date ?></li>
<li id="writer_title4">
<?php
if($userid=="admin" || $userid==$memo_id)
echo "<a href='delete.php?num=$memo_num'>[삭제]</a>";
?>
</li>
</ul>
</div>
<div id="memo_content"><?= $memo_content ?>
</div>
<div id="ripple">
<div id="ripple1">덧글</div>
<div id="ripple2">
<?php
$sql3 = "select * from phptest.memo_ripple where parent=$memo_num";
$stmh3 = $pdo->query($sql3);
while ($row_ripple = $stmh3->fetch(PDO::FETCH_ASSOC))
{
$ripple_num = $row_ripple["num"];
$ripple_id = $row_ripple["id"];
$ripple_nick = $row_ripple["nick"];
$ripple_content = str_replace("\n", "<br>", $row_ripple["content"]);
$ripple_content = str_replace(" ", " ", $ripple_content);
$ripple_date = $row_ripple["regist_day"];
?>
<div id="ripple_title">
<ul>
<li><?= $ripple_nick ?> <?= $ripple_date ?></li>
<li id="mdi_del">
<?php
if($userid=="admin" || $userid==$ripple_id)
echo "<a href='delete_ripple.php?num=$ripple_num'>삭제</a>";
?>
</li>
</ul>
</div>
<div id="ripple_content"> <?= $ripple_content ?></div>
<?php
}
if(isset($_SESSION["userid"])){
?>
<form name="ripple_form" method="post" action="insert_ripple.php">
<input type="hidden" name="num" value="<?= $memo_num ?>">
<div id="ripple_insert">
<div id="ripple_textarea">
<textarea rows="3" cols="80" name="ripple_content"></textarea>
</div>
<div id="ripple_button"><input type="image" src="../img/memo_ripple_button.png"></div>
</div>
</form>
<?php } ?>
</div> <!-- end of ripple2 -->
<div class="clear"></div>
<div class="linespace_10"></div>
<?php
//$number--;
}
?>
<div id="page_num"> ◀ 이전
<?php
// page link num
// 게시판 목록 하단에 페이지 링크 번호 출력
for ($i=1; $i<=$total_page; $i++)
{
if ($page == $i) // ���� ������ ��ȣ ��ũ ����
{
echo "<b> $i </b>";
}
else
{
echo "<a href='memo.php?page=$i'> $i </a>";
}
}
?>
다음 ▶</div>
</div> <!-- end of ripple -->
</div> <!-- end of col2 -->
</div> <!-- end of content -->
</div> <!-- end of wrap -->
</body>
</html>
The SQL doesn't like doing maths in the limit clause. Do it first in PHP:
$sql2 = "select * from phptest.memo order by num desc limit $start," . ($start+$scale);
Related
I have implement pagination in PHP.
It's works fine on Desktop and Laptop but but its not working on mobile devices.
member_list.php
<?php
include "../connection.php";
extract($_REQUEST);
$perPage = 50; // total records per page
// page
$conditionArr = array(); // array for condition
$condition = ""; // conditions
$pages = ""; // how many pages created
$type = "";
$company = "";
$message = "";
$rersArr = array();
$data = array();
$templeArr = array();
if ($sabhasadnumber != "") {
array_push($conditionArr, "sabhasad_number = '" . $sabhasadnumber . "'");
}
if ($Sakhe != "") {
array_push($conditionArr, "sakhe_id = '" . $Sakhe . "'");
}
if ($g != "") {
array_push($conditionArr, "gender LIKE '%" . $g . "%'");
}
$sql = "SELECT * FROM members WHERE village_id = '$id' and is_active = '1' and status = '1' ";
if (sizeOf($conditionArr) > 0) {
$condition = implode(" AND ", $conditionArr);
// echo $condition;
$sql .= " AND $condition";
}
$start = ($page - 1) * $perPage;
$sql1 = mysqli_query($conn, $sql) or die(mysqli_error($conn));
$count = mysqli_num_rows($sql1);
$pages = ceil($count / $perPage);
$sql .= " ORDER BY members_id ASC";
$sql .= " limit $start,$perPage ";
$num_of_rows = mysqli_num_rows($sql1);
?>
<input type="hidden" name="total_page" id="total_page" value="<?php echo $pages; ?>">
<input type="hidden" name="current_page" class="current_page" id="current_page"
value="<?php echo $page; ?>">
<div class="member--items">
<div class="row gutter--15 AdjustRow">
<div class="row">
<?php
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_array($result)) {
?>
<div class="col-md-3 col-xs-6 col-xxs-12" style="height:300px">
<div class="member--item ">
<?php
$imgurl = "";
if ($row["image"] != "") {
$imgurl = "../admin/uploads/" . $row["image"];
} else {
$imgurl = "../admin/uploads/default_profile.jpg";
}
?>
<div class="img img-circle">
<a href="sabhasad_family.php?id=<?php echo $row['sabhasad_number']; ?>" class="btn-link">
<img src="<?php echo $imgurl; ?>" alt=""
style="height: 150px; width: 150px;">
<!-- <img src="../admin/uploads/default_profile.jpg" alt=""-->
<!-- style="height: 150px; width: 150px;">-->
</a>
</div>
<div class="name">
<h3 class="h fs--12">
<p>
<a href="sabhasad_family.php?id=<?php echo $row['sabhasad_number']; ?>"> <?php echo $row['surname'] ." " ;
echo $row['name'] ." ";
echo $row['middle_name'] ." "; ?></a></p>
</h3>
</div>
<div class="activity">
<p>સભાસદ નંબર : <?php echo $row['sabhasad_number']; ?> </p>
</div>
</div>
</div>
<?php
}
}
else { ?>
<?php
}
?>
member_list.js
var page = 1;
var total_page = "";
function getresult(searches) {
$.ajax({
url: "process/member_list.php",
type: "post",
data: {
sabhasadnumber: $("#sabhasadnumber").val(),
id: $("#village_id").val(),
Sakhe: $("#Sakhe").val(),
g: $("#g").val(),
page: page
},
success: function (data) {
// alert(data);
if (data != "") {
if (searches === true) {
$("#mlist").html(data);
} else {
$("#mlist").append(data);
}
}
}
});
}
$(document).ready(function () {
getresult(false);
$(window).scroll(function () {
if ($(window).scrollTop() >= $(document).height() - $(window).height()) {
if (parseInt($(".current_page:last").val()) < parseInt($("#total_page").val())) {
page = parseInt($(".current_page:last").val()) + 1;
// alert("scrool"+$(".current_page:last").val());
getresult(false);
}
}
});
$("#reset").click(function () {
$("#Sakhe").val("");
$("#sabhasadnumber").val("");
$("#g").val("");
page = 1;
getresult(true);
});
$("#shopsubmit").click(function () {
page = 1;
getresult(true);
});
$("#freset").click(function () {
$("#subcategory").val("");
page = 1;
getresult(true);
});
});
My front page code look like this
village.php
<?php
include 'connection.php';
include 'header.php';
$id = $_GET['id'];
$totalvillagemember = mysqli_num_rows(mysqli_query($conn, "select members_id from members WHERE village_id = $id AND is_active = '1' and status = '1' "));
$villagename = mysqli_query($conn, "SELECT name from village WHERE village_id = $id");
$row1 = mysqli_fetch_array($villagename);
?>
<body>
<!-- Preloader Start -->
<div id="preloader">
<div class="preloader--inner"></div>
</div>
<!-- Preloader End -->
<!-- Wrapper Start -->
<div class="wrapper">
<!-- Header Section Start -->
<!-- Header Section End -->
<!-- Page Header Start -->
<div class="page--header pt--60 pb--60 text-center" data-bg-img="img/page-header-img/bg.jpg" data-overlay="0.85">
<div class="container">
<div class="title">
<h2 class="h1 text-white">સભ્યો</h2>
</div>
<ul class="breadcrumb text-gray ff--primary">
<li>હોમ</li>
<li class="active"><span class="text-primary">સભ્યો</span></li>
</ul>
</div>
</div>
<!-- Page Header End -->
<!-- Page Wrapper Start -->
<section class="page--wrapper pt--80 pb--20">
<div class="container">
<div class="row">
<!-- Main Content Start -->
<div class="main--content col-md-8 pb--60" data-trigger="stickyScroll">
<div class="main--content-inner">
<!-- Filter Nav Start -->
<div class="filter--nav clearfix">
<div class="filter--link">
<h2 class="">ગામ : <?php echo $row1['name']; ?></h2>
<h2 class="">કુલ સભ્ય :<?php echo number_format($totalvillagemember) ?></h2>
</div>
</div>
<div id="mlist" name="mlist">
</div>
<!-- Page Count End -->
</div>
</div>
<!-- Main Content End -->
<!-- Main Sidebar Start -->
<div class="main--sidebar col-md-4 pb--60" data-trigger="stickyScroll">
<!-- Widget Start -->
<div class="widget">
<h2 class="h4 fw--700 widget--title">સભ્ય શોધો</h2>
<!-- Buddy Finder Widget Start -->
<div class="buddy-finder--widget">
<form name="village" id="village">
<div class="row">
<div class="col-xs-6 col-xxs-12">
<div class="form-group">
<label>
<span class="text-darker ff--primary fw--500">શોધી રહ્યો છુ</span>
<select class="form-control form-sm" name="g" id="g">
<option value=""> પસંદ કરો
</option>
<option value = "M">પુરુષ</option>
<option value = "F">સ્ત્રી</option>
</select>
</label>
</div>
</div>
<div class="col-xs-6 col-xxs-12">
<div class="form-group">
<label>
<span class="text-darker ff--primary fw--500">સભાસદ નંબર</span>
<input type="text" name="sabhasadnumber" id="sabhasadnumber"
class="form-control form-sm"
placeholder="સભાસદ નંબર">
</label>
</div>
</div>
<div class="col-xs-6 col-xxs-12">
<div class="form-group">
<label>
<input type="hidden" id="village_id" name="village_id"
value="<?php echo $id; ?>">
<span class="text-darker ff--primary fw--500">સાખે</span>
<select class="form-control form-sm" name="Sakhe" id="Sakhe">
<option value=""> સાખે પસંદ કરો
</option>
<?php
$query = mysqli_query($conn, "select * from sakhe where status = 1 order by sakhe_id asc");
while ($row = mysqli_fetch_array($query)) {
echo "<option value = " . $row['sakhe_id'] . ">" . $row['name'] . "</option>";
}
?>
</select>
</label>
</div>
</div>
<div class="col-xs-12">
<button type="button" onclick="getresult()" class="btn btn-primary" id="shopsubmit" name="shopsubmit">
સબમિટ કરો
</button>
<button type="button" onclick="getresult()" class="btn btn-primary"
id="reset" name="reset">
ફરીથી સેટ કરો
</button>
</div>
</div>
</form>
</div>
</div>
<!-- Widget End -->
</div>
<!-- Main Sidebar End -->
</div>
</div>
</section>
<!-- Page Wrapper End -->
<!-- Footer Section Start -->
<!-- Footer Widgets End -->
<!-- Footer Extra Start -->
<?php include 'footer.php'; ?>
<!-- Footer Section End -->
</div>
<!-- Wrapper End -->
<!-- Back To Top Button Start -->
<div id="backToTop">
<i class="fa fa-caret-up"></i>
</div>
<!-- Back To Top Button End -->
<!-- ==== Plugins Bundle ==== -->
<script src="js/plugins.min.js"></script>
<!-- ==== Color Switcher Plugin ==== -->
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<!-- ==== Main Script ==== -->
<script src="js/main.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<!--<script src="http://malsup.github.com/jquery.form.js"></script>-->
<script src="myjs/member_list.js"></script>
</body>
<!-- Mirrored from themelooks.us/demo/socifly/html/members.html by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 30 Sep 2019 09:33:46 GMT -->
</html>
This pagination is not working only on Mobile devices.
Please help.
Hosting company updated servers or added new patchs can't get a straight answer.
I updated code looked online and stuck. Tried to have hosting check with server and company keeps coming back and saying its the code.
Don't know what else to do and help would be appreciated.
<?
include_once("mysql_nitrousgarage.inc");
$clean_url = substr($PHP_SELF,1);
$clean_url = substr($clean_url,0,-5);
$q = "SELECT * from NG_product where active='Y' and
clean_url='$clean_url'";
$results = mysql_query($q);
$row = mysql_fetch_array($results);
$product_id = $row["product_id"];
$product_name = $row["product_name"];
$sku = $row["sku"];
$description = $row["description"];
$meta_title = $row["meta_title"];
$meta_description = $row["meta_description"];
$magiczoomplus = "Y";
include_once("topnav.inc")
?>
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<meta name="viewport" content="width=400, user-scalable=no">
<script type="text/javascript"
src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-
52f96c9761c7b0cb" async="async"></script>
<div class="box-border">
Home ›
<?
if ($saved_category_id || !$saved_brand_id)
{
if ($saved_category_id)
$q = "SELECT * from NG_category where
category_id='$saved_category_id'";
else
$q = "SELECT * from NG_product_category as pc, NG_category
as c where pc.product_id='$product_id' and
pc.category_id=c.category_id order by c.order_placement limit 1";
$results = mysql_nitrousgarage.inc($q);
$row = mysql_fetch_array($results);
$category_id = $row["category_id"];
$category = $row["category"];
$category_clean_url = $row["clean_url"];
echo "<a href='$category_clean_url'>$category Wheels</a>";
}
else
{
$q = "SELECT * from NG_brand where brand_id='$saved_brand_id'";
$results = mysql_query($q);
$row = mysql_fetch_array($results);
$brand_id = $row["brand_id"];
$brand = $row["brand"];
$brand_clean_url = $row["clean_url"];
echo "<a href='$brand_clean_url'>$brand Wheels</a>";
}
?>
› <?echo $product_name?>
<div class="page-numbers">
<a href="<?echo $category_clean_url?>">‹ Back to <?echo
$category?> Wheels</a>
</div>
</div>
<div class="space20"></div>
<?
$image_id_arr = array();
$q1 = "SELECT * from NG_finish as f, NG_product_finish as pf, NG_finish_image as fi where f.active='Y' and f.finish_id=pf.finish_id and pf.active='Y' and pf.product_id='$product_id' and pf.product_finish_id=fi.product_finish_id and fi.active='Y' order by f.order_placement,fi.order_placement";
$r1 = mysql_query($q1);
while ($row1 = mysql_fetch_array($r1))
{
$image_id = $row1["image_id"];
$product_finish_name = $row1["product_finish_name"];
if (!$main_image)
{
$main_image = "finish-$image_id.jpg";
$selected_finish = $product_finish_name;
}
$image_id_arr[] = $image_id;
$product_finish_name_arr[] = $product_finish_name;
}
?>
<div class="simpletable">
<div class="row">
<div class="simplecell details-cll1">
<div id="m-container">
<img class="maxwidth" id="m-img" src="productphotos/<?echo $main_image?>" width=488>
</div>
</div>
<div class="simplecell" style="width: 3%"></div>
<div class="simplecell details-cll2">
<!--<div class="details-share">
<img src="images/facebook.jpg">
<br class="nomobile">
<img src="images/twitter.jpg">
<br class="nomobile">
<img src="images/mail.jpg">
<br class="nomobile">
<img src="images/plus.jpg">
</div>-->
<span class="details-title"><?echo $product_name?></span>
<div class="style-number">Style: <?echo $sku?></div>
<div class="selected-finish">Selected Finish: <span id=finish_layer>
<?echo $selected_finish?></span>
</div>
<div class="space30"></div>
<br>
<div class="simpleinline">
<div class="like-wheel">Like this Wheel?</div>
<div class="more-info-via">GET MORE INFO VIA</div>
</div>
<div class="simpleinline">
<a class="like-buttons" href="wheel-inquiry.php?product_id=<?echo $product_id?>&contact=C">CALL/TEXT</a> <a class="like-buttons" href="wheel-inquiry.php?product_id=<?echo $product_id?>&contact=E">EMAIL</a>
</div>
<div class="space50 nomobile"></div>
<div class="space30"></div>
<?
while(list($k,$v) = each($image_id_arr))
{
$product_finish_name = $product_finish_name_arr[$k];
echo "<img class='maxwidth' src='productphotos/finish-$v.jpg' width=145>";
}
?>
</div>
</div>
</div>
<div class="space20"></div>
<div class="box-border">
<div class="simpletable">
<div class="row">
<div class="simplecell product-desc">
<?echo $description?>
</div>
<!--<div class="simplecell price-notshow">
<b>Why are prices not shown?</b>
<br><br>
Many of our customers frequently ask us why are the prices not show.
</div>-->
</div>
</div>
</div>
<div class="space20"></div>
<?
$q = "SELECT * FROM NG_gallery WHERE active='y' and product_id='$product_id' ORDER BY featured desc, orderplacement limit 3";
$results = mysql_query($q);
if (mysql_num_rows($results) > 0) { ?>
<b><?echo $product_name?></b> Vehicle Gallery
<div class="page-numbers">
CLICK IMAGE TO <b>ENLARGE | VIEW MORE</b>
</div>
<?
while ($row = mysql_fetch_array($results))
{
$gallery_id = $row["gallery_id"];
$gallery_title = $row["gallery_title"];
$gallery_pics .= "<a href='productphotos/gallery_$gallery_id-l.jpg' class='MagicZoomPlus' id='Zoomer$gallery_id' rel='zoom-position: inner; zoom-width:400px;zoom-height:500px;' title='$gallery_title'><img class='maxwidth' src='productphotos/gallery_$gallery_id-l.jpg' width=380 border=0></a>";
}
?>
<div class="details-img-container">
<nobr>
<?echo $gallery_pics?>
</nobr>
</div>
<div class="details-img-container2">
<?echo $gallery_pics?>
</div>
<?}?>
<? include_once("footer.inc") ?>
Before updates of server page was working fine.
After searching for a specific course the results are displayed correctly but once I change page it reverts back to displaying all of the available results. How do I keep the search term results?
Here's the code
<?php
$con = mysqli_connect("localhost", "root", "root", "courses");
// $total = mysqli_query($con, "SELECT count(title) as total")->fetch()['total']);
if(isset($_GET['searchword'])){
$searchword = $_GET['searchword'];
}
else {
$searchword = "";
}
$result = mysqli_query($con, "SELECT count(title) FROM course WHERE title LIKE '$searchword%'");
$row = mysqli_fetch_row($result);
// Total rows.
$rowstotal = $row[0];
//pages
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$perPage = isset($_GET['per-page']) && $_GET['per-page'] <= 100 ? (int)$_GET['per-page'] : 10;
$start = ($page > 1) ? ($page * $perPage) - $perPage : 0;
$pages = $rowstotal / $perPage;
$sql = "SELECT * FROM course WHERE title LIKE '%$searchword%' ORDER BY title ASC LIMIT {$start},{$perPage}";
$query = mysqli_query($con, $sql);
$resultsText = "$rowstotal results";
$resultsList = '';
while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
$courseId = $row["id"];
$courseAward = $row["award"];
$courseName = $row["title"];
$courseDetails = $row["summary"];
$resultsList .= ''.$courseAward.' '.$courseName.' <br>'.$courseDetails.'<br/>';
}
mysqli_close($con);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Courses</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<nav class="navbar navbar-default navbar-static-top navbar-inverse">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">
<img alt="Napier" src="">
</a>
</div>
</div>
</nav>
<div class="container">
<!-- Search -->
<form method="GET">
<input type="text" class="form-control" name="searchword" placeholder="Search" value="<?php echo $searchword ?>" style="width:30%;"><br>
</form>
<!-- Results -->
<div class="results">
<p></p>
<p>Showing <?php echo $perPage; ?> of <?php echo $resultsText; ?></p>
<p id="content"><?php echo $resultsList; ?></p>
</div>
<div class="pagination">
<?php for($x = 1; $x <= $pages; $x++): ?>
<a href="?page=<?php echo $x; ?>&per-page=<?php echo $perPage; ?>"<?php if($page === $x) { echo ' class="selected"'; } ?>><?php echo $x; ?></a>
<?php endfor; ?>
</div>
</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
</body>
</html>
Your page links don't preserve the searchword parameter. Change this:
<a href="?page=<?php echo $x; ?>&per-page=<?php echo $perPage; ?>"<?php if($page === $x) { echo ' class="selected"'; } ?>><?php echo $x; ?></a>
to this:
<a href="?page=<?php echo $x; ?>&per-page=<?php echo $perPage; ?>&searchword=<?php echo $searchword; ?>"<?php if($page === $x) { echo ' class="selected"'; } ?>><?php echo $x; ?></a>
I have a problem with my code in php.
Error: Undefined Variable 'id'.
<?php
include_once '../includes/connection.php';
include_once '../includes/functions.php';
session_start();
$posts = $pdo->query("SELECT * FROM posty ORDER BY post_id DESC");
$j=0;
?>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="../sources/css/style.css">
<script type="text/javascript" src="../sources/scripts/time.js"></script>
<script type="text/javascript" src="../sources/scripts/scroll.js"></script>
</head>
<body onload="timeLine(); setInterval('timeLine()', 1000 )" >
<header>
<div class = "menu">
<ul>
<li> Blog </li>
<li> Archives </li>
<li> Contact </li>
<li id="addPost"> Add Post </li>
<li id="editPost"> Edit Post </li>
<li id="deletePost"> Delete Post </li>
<li id="showBlogContent"> Hide Blog </li>
<li id="menuRightLogin"> Logout </li>
<li id="menuRightDate"><?php echo date('jS F Y').' '; ?><span id="clock"> </span> </li>
</ul>
</div>
</header>
<div id="showBlog" style="display: block;">
<div class="container">
<div class="postsContainer">
<?php foreach($posts as $post) {
if ($j <= 5) { ?>
<div class="postBox">
<div class="postTitle">
<br />
<?php echo $post['post_title']; ?>
</div>
<div class="postContent">
<br />
<?php if(($wordCount = str_word_count($post['post_content']) <=50)) {
echo $post['post_content'];?>
Edit Post
<br />
<?php } else {
echo excerpts($post['post_content'], 50).'... <br/> <br/>
Edit Post
<br /> <br />';
} ?>
</div>
<div class="postDate">
<?php echo '<b id="author">Author:</b> '.$post['post_author'].' <b id="posted">posted:</b> '.date('jS F Y', $post['add_date']); ?>
</div>
</div>
<?php $j++; } }?>
</div>
</div>
<footer>
<small> © Copyright 2015, n3stis </small>
</footer>
</div>
</body>
</html>
So from here I'm sending a 'id' to edit form:
<?php
include_once '../includes/connection.php';
include_once '../includes/functions.php';
session_start();
$id = $_GET['id'];
if (isset ($id)) {
if (isset($_SESSION['logged_in'])) {
$query = $pdo->prepare("SELECT * FROM posty WHERE post_id='" . $id . "' LIMIT 1");
$query->execute();
$post = $query->fetch();
if (isset($_POST['post_title'], $_POST['post_content'], $_POST['post_author'])) {
$postTitle = $_POST['post_title'];
$postAuthor = $_POST['post_author'];
$postContent = nl2br($_POST['post_content']);
$postTime = time();
if (empty($post_title) or empty($post_content) or empty($post_author)) {
$error = 'All fields required.';
} else {
$sql = ("UPDATE `posty` SET `post_title` = :title, `post_author` = :author, `post_content` = :content, `edit_date` = :editDate WHERE `post_id` = :postID ");
$query = $pdo->prepare($sql);
$query->bindValue(':title', $postTitle);
$query->bindValue(':author', $postAuthor);
$query->bindValue(':content', $postContent);
$query->bindValue(':editDate', $postTime);
$query->bindValue(':postID', $id);
$query->execute();
header('Location: adminPanel.php');
}
}
?>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="../sources/css/style.css">
<script type="text/javascript" src="../sources/scripts/time.js"></script>
<script type="text/javascript" src="../sources/scripts/scroll.js"></script>
</head>
<body onload="timeLine(); setInterval('timeLine()', 1000 )">
<header>
<div class="menu">
<ul>
<li> Blog </li>
<li> Archives </li>
<li> Contact </li>
<li id="#addPost"> Add Post </li>
<li id="#editPost"> Edit Post </li>
<li id="#deletePost"> Delete Post </li>
<li id="showBlogContent"> Hide Blog </li>
<li id="menuRightLogin"> Logout </li>
<li id="menuRightDate"><?php echo date('jS F Y') . ' '; ?><span id="clock"> </span></li>
</ul>
</div>
</header>
<div id="showBlog" style="display: block;">
<div class="container">
<div class="postsContainer">
<?php if (isset($error)) { ?>
<p id="error"><?php echo $error ?> </p>
<?php } ?>
<form action="editPostPanel.php" method="post">
<input type="text" name="post_title" value="<?php echo $post['post_title'];?>"/>
<input type="text" name="post_author" value="<?php echo $post['post_author'];?>"/>
<br/>
<br/>
<textarea name="post_content" rows="15" cols="90"><?php echo $post['post_content'];?></textarea>
<br/>
<br/>
<input type="submit" value="Wyślij post"/>
</form>
</div>
</div>
<footer>
<small> © Copyright 2015, n3stis </small>
</footer>
</div>
</body>
</html>
<?php
} else {
echo 'Error';
} }
else {
echo 'Error';
}
When I send a form I get this:
Notice: Undefined index: id on line 7
I will be very greatfull for yours help :)
change
$id = $_GET['id'];
if (isset ($id))
to
if (isset ($_GET['id'])) {
$id = $_GET['id'];
Your form doesn't have the id parameter in it. You need to change
<form action="editPostPanel.php" method="post">
to:
<form action="editPostPanel.php?id=<?php echo $id; ?>" method="post">
This is in addition to correcting the isset check that the other answers noted:
if (isset($_GET['id'])) {
$id = $_GET['id'];
While I don't have your line numbers, I'd guess that line 7 is $id = $_GET['id'];. This indicates that you don't have a GET (query) param called id set. To fix that Notice, you probably want to swap the two lines as follows:
if (isset($_GET['id'])){
$id = $_GET['id']
But all that will do is start echoing 'Error' back to you. You'll also want to figure out why your line editPostPanel.php?id='.$post['post_id'] is not apparently setting the id as desired.
I am new to PHP and trying to display data from the database.
However it only displays data from one row but I want to show the data from multiple rows where the condition match. Here is my code I am using:
<?PHP
session_start();
if (!(isset($_SESSION['username']) && $_SESSION['username'] != '')) {
header ("Location: checklogin.php");
}
$con = mysqli_connect("localhost", "root", "", "map_my_way");
$fetch_row = $_SESSION['username'];
$result = mysqli_query($con,"SELECT * FROM members where username='$fetch_row'");
while($row = mysqli_fetch_array($result)) {
$first_name = $row['first_name'];
$last_name = $row['last_name'];
$email = $row['email'];
$m_no = $row['m_no'];
$v_name = $row['v_name'];
$capacity = $row['capacity'];
$fuel_type = $row['fuel_type'];
}
$result2 = mysqli_query($con,"SELECT s_a_name FROM locations where username='$fetch_row'");
$row2 = mysqli_fetch_array($result2);
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Profile Page</title>
<link rel="stylesheet" type="text/css" href="profile.css">
</head>
<body id="body">
<div id="mmw"> <span> MAP MY WAY </span></div>
<div id="title_box">
<button id="lvbutton">My Profile</button>
<button id="lvbutton">Maps</button>
<button id="lvbutton">Edit Profile</button>
<button id="lvbutton" style="float:right; margin- right:10px;">Sign-Out</button>
</div>
<div id="box">
<div id="name_box"><span>Welcome <?php echo($_SESSION['username']); ?></span></div>
<div id="box1">
<div> <p id="link">Your Information </p>
<ul style="margin-top:20px; padding-left:0;">
<li><span>First Name : <?php echo $first_name; ?></span></li><br>
<li><span>Last Name : <?php echo $last_name; ?></span></li><br>
<li><span>Email : <?php echo $email; ?></span></li><br>
<li><span>Age : <?php echo $m_no; ?></span></li><br>
<li><span>Current Vehical : <?php echo $v_name; ?></span></li><br>
<li><span>Fuel Type: <?php echo $fuel_type; ?> </span></li><br>
<li><span>Seating Capacity : <?php echo $capacity; ?></span></li><br>
</ul>
</div>
</div>
<div id="box2"> <p id="link">Saved Routes </p>
<ul style="margin-top:20px;">
<span> <?php foreach($row2 as $data)
{echo "route Name : $data <br>" ; };
?>
</span>
</ul>
</div>
</div>
</div>
</body>
</html>
Your query on the members table is only going to return one row, so you don't really need to have $row = mysqli_fetch_array($result) in a loop (that shouldn't break your script, though). Your query on the locations table will potentially return more than one row, so you do need to loop on that one. Something like:
$result2 = mysqli_query($con,"SELECT s_a_name FROM locations where username='$fetch_row'");
$savedRoutes = "";
while($row2 = mysqli_fetch_array($result2))
{
$savedRoutes .= "route Name : " . $row2['s_a_name'] . "<br/>";
}
will put all the data together in a string ($savedRoutes) that can be echoed down in the "Saved Routes" section of your html code.
Alternatively, you can put the loop down in the "Saved Routes" section and just echo out each line as you loop through. Personally I think putting the loop in the top and concatenating the data into a string is a bit cleaner and easier to read.