Hi everyone,
I have seen a few topics like this one. Still cant find the specific thing, so I am asking - does anyone know this?
I am trying to combine a mysql query with this code I found at php-mysql-tutorial.com.
Essentially this is the rub. The pages are working fine, but I am flumoxxed as to how to apply the $imgid to a page (viewing one image per page).
The imgid are in numerical order but do not begin at one, and there may be gaps - eg img 3, 5, 7,8 ,9 and 10 on a 6 page pagination.
I can pass the $page variable because it is a simple increment iteration, but how do I apply the changing $imgid value? so that pp1 has an imgid of 3 passed, pp2 is 5, pp3 is 7 etc. I expect it is something to do with combining a query and an array and applying it, but I'm having a brain-strain at that point.
Gratefully, here is my code stripped of excess ( I hope).
<?php
// back button depending on which gallery is parent
if(!isset($_REQUEST['random'])) {
$file= "gallery";
$varid = 0;
} else {
$file= "random";
$varid = 1;
}
echo "<fieldset><div id="back_but"><a href="gallery.php?blog=$file"> <br /></a></div>";
$url = "blog=picture&pics=picdetail&";
// how many rows to show per page
$rowsPerPage = 1;
// by default we show first page
$pageNum = 1;
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
$query = "SELECT imgid, title, year, description, thumburl, imgurl, medium, style, clientname FROM images LEFT JOIN mediums ON images.mediumid = mediums.mediumid LEFT JOIN imgstyle ON images.styleid = imgstyle.styleid LEFT JOIN clients ON images.clientid = clients.clientid WHERE imgid = $imgid".
" LIMIT $offset, $rowsPerPage";
echo $query;
$result = mysql_query($query);
while($row=mysql_fetch_array($result, MYSQL_ASSOC))
{
$imgid = $row['imgid'];
$title = $row['title'];
$year = $row['year'];
$description = $row['description'];
$thumburl = $row['thumburl'];
$medium = $row['medium'];
$style = $row['style'];
$client = $row['clientname'];
}
?>
<fieldset><?php
// how many rows we have in database
$query = "SELECT COUNT(imgid) AS numrows FROM images WHERE tarot = $varid";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " $page "; // no need to create a link to current page
}
else
{
$nav .= " <a href="$self?$url&page=$page">$page</a> ";
}
}
// creating previous and next link
// plus the link to go straight to
// the first and last page
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href="$self?$url&page=$page">[Prev]</a> ";
$first = " <a href="$self?$url&page=1">[First Page]</a> ";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href="$self?$url&page=$page">[Next]</a> ";
$last = " <a href="$self?$url&page=$maxPage">[Last Page]</a> ";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
// print the navigation link
echo $first . $prev . $nav . $next . $last;
?></fieldset>
Problem with PHP/mySQL login code
Hello,There is an error in my login script and I can't figure out what it is...I believe it might be my "SELECT" statement...Can anyone help me? Code: <?php//define ('SASI Services
php multiple action on submit
I have a form which says:<form enctype='multipart/form-data' method='post' action='process.php' target='_blank'>I need to call process.php on submit or on clicking submit button. Now
Php script to read msword file
hi,I need to read a msword file and i want to print the contents in that word file.i used the fgets() and its working for text file. but its not working for word file.Help me in this.Thanks
how can we add data from dynamic fields to mysql db in php
i have a script which i found on the internet. i modify that script according to my needs. what is in that script is there are three form fields with two buttons. one button is "Give me more
PHP hyperlinks generator - HELP plz
HiI need some help to get this done using php:1 - I have few hyperlinks say 500 in format like:<a href="http://domaina.com/1.html"
Storing the referrer in session... problems with tabs
Hello AllI am currently working on an ERP project based on the MVC methodology, when a user navigates the site we store the referrer in session.The problem we have is that using multiple tabs upsets
[newb] Image hosting help.
Hey there, I'm new to php, I know some basics and i can code PWN, I'm only 14 but I'm interested in PHP, I have bought a dedicated server, (With unlimited bandwidth of corse, And 2tb Hard drives), And
Taylor Series Function
So I am working a a project for my intro C++ class, and I am having some trouble with a function for approximating exp(x) using a taylor series. The taylor series approximations for exp(x) is:
Recording popularity by day, week.. all time?
Hey everyone, I'm creating a site designed around users uploading music. How can I implement a system that would effectively record information such as view count so that a user could find the most
Need Help with a query
Hello, For some reason I am just not getting the right answer when I do this query and not quite sure why? $runinposition = mysql_query("SELECT * FROM bb_off WHERE user='$user' AND test1='test1'