Connecting Tech Pros Worldwide Help | Site Map

Gallery Pagination Result Problem

ste
Guest
 
Posts: n/a
#1: May 5 '06
Hi there,

Further to my recent posts where I've received excellent help from Rik and
Jerry, I've ended up with an image gallery on my website that displays
images in a table, 3 images per row. This works great and opens all images
in the database when I open the url mywebsite/gallery.php, or I can choose
certain images (by category) by going to url's like
mywebsite/gallery.php?category=landscape

Although the above worked perfectly with 15 images in the database, I've
realised that as I add more images to the database (I will probably have a
few hundred images in total before long), I'm going to need to sort out the
gallery pages so that instead of displaying, say, 100 images in a big long
page, it instead displays 12 images per page, and then has links to Next,
Previous, First, Last, etc.

After spending an hour going through Google searches, I've found some code
which enables pagination from this website tutorial:
http://www.tonymarston.co.uk/php-mysql/pagination.html

I've inserted this code into my existing code, yet have came across a small
problem. The pagination now works when I go to mywebsite/gallery.php and
it's great. However, when I go to mygallery/gallery.php?category=landscape,
instead of showing the paginated Landscape gallery, it instead shows all
images from the database in paginated format, which is basically the same as
the mywebsite/gallery.php page

In adding the above pagination code, I've somehow messed something up when
wanting to open galleries based on categories. I've copied the code below -
can anyone see anything obvious I've done wrong? Through trial and error,
I've tried to adjust the queries in the code, but to no avail.

Thanks for any help,

Stephen



<?php
include("databasepasswords");

$connection = mysql_connect($host,$user,$password) or die ("couldn't
connect to server");
$db = mysql_select_db($database,$connection) or die ("Couldn't select
database");

if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
} // if

$query = "SELECT count(*) FROM images ".$where;
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];

$rows_per_page = 12;
$lastpage = ceil($numrows/$rows_per_page);

$pageno = (int)$pageno;
if ($pageno < 1) {
$pageno = 1;
} elseif ($pageno > $lastpage) {
$pageno = $lastpage;
} // if

$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query = "SELECT * FROM images ORDER BY dateadded, datetaken DESC $limit
".$where ;
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);

if(get_magic_quotes_gpc()){
$_GET['category'] = stripslashes($_GET['category']);
}
$category = mysql_real_escape_string( $_GET['category'], $connection);
$category = ucfirst($category);
$where = (isset($_GET['category'])&&$_GET['category']!='') ? "WHERE category
= '".$category."'":'';
$result = mysql_query($query) or die ("Couldn't execute query.");

echo "\n<div id=\"content\">";
echo "\n<h2>$category Gallery</h2>";

if ($pageno == 1) {
echo " FIRST PREV ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
$prevpage = $pageno-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
} // if

echo " ( Page $pageno of $lastpage ) ";

if ($pageno == $lastpage) {
echo " NEXT LAST ";
} else {
$nextpage = $pageno+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";
} // if

echo "\n<table id=\"thumbgallery\" cellSpacing=\"0\" cellPadding=\"10\"
width=\"400\" border=\"0\">";
echo "\n<tbody>";
$i = 3;
while ($row = mysql_fetch_assoc($result))
{
if($i==3) echo "\n\t<tr>";
echo "\n\t\t<td valign=\"top\" width=\"113\" id=\"thumbs\"
align=\"center\"><a
href=\"/image_viewer.php?imageid=".$row['imageid']."\"><img
src=\"/images/gallery/t".$row['imageid'].".jpg\" border=\"0\"
alt=\"".$row['caption']."\" /></a><p class=\"captionref\">Ref:
".$row['imageid']."</p><p class=\"caption\">".$row['caption']."</p></td>";
$i--;
if($i==0) {
echo "\n\t<tr>";
$i = 3;
}
}
if($i!=3) echo "\n\t\t<td colspan=\"$i\"></td>\n\t</tr>";
echo "\n</tbody>";
echo "\n</table>";

?>


Jerry Stuckle
Guest
 
Posts: n/a
#2: May 5 '06

re: Gallery Pagination Result Problem


ste wrote:[color=blue]
> Hi there,
>
> Further to my recent posts where I've received excellent help from Rik and
> Jerry, I've ended up with an image gallery on my website that displays
> images in a table, 3 images per row. This works great and opens all images
> in the database when I open the url mywebsite/gallery.php, or I can choose
> certain images (by category) by going to url's like
> mywebsite/gallery.php?category=landscape
>
> Although the above worked perfectly with 15 images in the database, I've
> realised that as I add more images to the database (I will probably have a
> few hundred images in total before long), I'm going to need to sort out the
> gallery pages so that instead of displaying, say, 100 images in a big long
> page, it instead displays 12 images per page, and then has links to Next,
> Previous, First, Last, etc.
>
> After spending an hour going through Google searches, I've found some code
> which enables pagination from this website tutorial:
> http://www.tonymarston.co.uk/php-mysql/pagination.html
>
> I've inserted this code into my existing code, yet have came across a small
> problem. The pagination now works when I go to mywebsite/gallery.php and
> it's great. However, when I go to mygallery/gallery.php?category=landscape,
> instead of showing the paginated Landscape gallery, it instead shows all
> images from the database in paginated format, which is basically the same as
> the mywebsite/gallery.php page
>
> In adding the above pagination code, I've somehow messed something up when
> wanting to open galleries based on categories. I've copied the code below -
> can anyone see anything obvious I've done wrong? Through trial and error,
> I've tried to adjust the queries in the code, but to no avail.
>
> Thanks for any help,
>
> Stephen
>
>
>
> <?php
> include("databasepasswords");
>
> $connection = mysql_connect($host,$user,$password) or die ("couldn't
> connect to server");
> $db = mysql_select_db($database,$connection) or die ("Couldn't select
> database");
>
> if (isset($_GET['pageno'])) {
> $pageno = $_GET['pageno'];
> } else {
> $pageno = 1;
> } // if
>
> $query = "SELECT count(*) FROM images ".$where;
> $result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
> $query_data = mysql_fetch_row($result);
> $numrows = $query_data[0];
>
> $rows_per_page = 12;
> $lastpage = ceil($numrows/$rows_per_page);
>
> $pageno = (int)$pageno;
> if ($pageno < 1) {
> $pageno = 1;
> } elseif ($pageno > $lastpage) {
> $pageno = $lastpage;
> } // if
>
> $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
> $query = "SELECT * FROM images ORDER BY dateadded, datetaken DESC $limit
> ".$where ;
> $result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
>
> if(get_magic_quotes_gpc()){
> $_GET['category'] = stripslashes($_GET['category']);
> }
> $category = mysql_real_escape_string( $_GET['category'], $connection);
> $category = ucfirst($category);
> $where = (isset($_GET['category'])&&$_GET['category']!='') ? "WHERE category
> = '".$category."'":'';
> $result = mysql_query($query) or die ("Couldn't execute query.");
>
> echo "\n<div id=\"content\">";
> echo "\n<h2>$category Gallery</h2>";
>
> if ($pageno == 1) {
> echo " FIRST PREV ";
> } else {
> echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
> $prevpage = $pageno-1;
> echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
> } // if
>
> echo " ( Page $pageno of $lastpage ) ";
>
> if ($pageno == $lastpage) {
> echo " NEXT LAST ";
> } else {
> $nextpage = $pageno+1;
> echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";
> echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";
> } // if
>
> echo "\n<table id=\"thumbgallery\" cellSpacing=\"0\" cellPadding=\"10\"
> width=\"400\" border=\"0\">";
> echo "\n<tbody>";
> $i = 3;
> while ($row = mysql_fetch_assoc($result))
> {
> if($i==3) echo "\n\t<tr>";
> echo "\n\t\t<td valign=\"top\" width=\"113\" id=\"thumbs\"
> align=\"center\"><a
> href=\"/image_viewer.php?imageid=".$row['imageid']."\"><img
> src=\"/images/gallery/t".$row['imageid'].".jpg\" border=\"0\"
> alt=\"".$row['caption']."\" /></a><p class=\"captionref\">Ref:
> ".$row['imageid']."</p><p class=\"caption\">".$row['caption']."</p></td>";
> $i--;
> if($i==0) {
> echo "\n\t<tr>";
> $i = 3;
> }
> }
> if($i!=3) echo "\n\t\t<td colspan=\"$i\"></td>\n\t</tr>";
> echo "\n</tbody>";
> echo "\n</table>";
>
> ?>
>
>[/color]

Howdy.

One thing I see - you use $where before you set it. What happens if you move
the code which sets $where earlier in your routine?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
ste
Guest
 
Posts: n/a
#3: May 6 '06

re: Gallery Pagination Result Problem



"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
news:SNWdnWxNpsKsrMbZnZ2dnUVZ_v-dnZ2d@comcast.com...
<snip>[color=blue]
> Howdy.
>
> One thing I see - you use $where before you set it. What happens if you
> move the code which sets $where earlier in your routine?
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================[/color]

Hi Jerry,

When I moved the code which set's $where to above the first $where, I found
that although gallery.php worked fine, gallery.php?category=landscape failed
to run and I got an error message.

Do you have any more ideas at all?

I feel like the problem is to do with the $query values and I'm just not
setting them correcly with the new piece of code, or not in the right order.

To add to this, I've just noticed that when I load the landscape gallery,
not only does it display all images now (albeit in a paginated format)
instead of just the landscape images, but if I click the paginated result
for page 2, it changes the page title back to just Gallery, instead of the
main page of Landscape gallery.

This looks like it's more involved than I thought it would be! :-(

Again, if you or anyone else spot anything else obvious, please let me know.

Thanks,

Stephen


Jerry Stuckle
Guest
 
Posts: n/a
#4: May 6 '06

re: Gallery Pagination Result Problem


ste wrote:[color=blue]
> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
> news:SNWdnWxNpsKsrMbZnZ2dnUVZ_v-dnZ2d@comcast.com...
> <snip>
>[color=green]
>>Howdy.
>>
>>One thing I see - you use $where before you set it. What happens if you
>>move the code which sets $where earlier in your routine?
>>
>>--
>>==================
>>Remove the "x" from my email address
>>Jerry Stuckle
>>JDS Computer Training Corp.
>>jstucklex@attglobal.net
>>==================[/color]
>
>
> Hi Jerry,
>
> When I moved the code which set's $where to above the first $where, I found
> that although gallery.php worked fine, gallery.php?category=landscape failed
> to run and I got an error message.
>
> Do you have any more ideas at all?
>
> I feel like the problem is to do with the $query values and I'm just not
> setting them correcly with the new piece of code, or not in the right order.
>
> To add to this, I've just noticed that when I load the landscape gallery,
> not only does it display all images now (albeit in a paginated format)
> instead of just the landscape images, but if I click the paginated result
> for page 2, it changes the page title back to just Gallery, instead of the
> main page of Landscape gallery.
>
> This looks like it's more involved than I thought it would be! :-(
>
> Again, if you or anyone else spot anything else obvious, please let me know.
>
> Thanks,
>
> Stephen
>
>[/color]

Stephen,

Sounds like you need to study the code and understand it a little more.

I've never found it productive to change code (or even implement someone else's
code as part of mine) until I understood just what it was doing.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
ste
Guest
 
Posts: n/a
#5: May 6 '06

re: Gallery Pagination Result Problem



"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
news:mMedncq5GZlHdsbZnZ2dnUVZ_tSdnZ2d@comcast.com. ..[color=blue]
> ste wrote:[color=green]
>> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
>> news:SNWdnWxNpsKsrMbZnZ2dnUVZ_v-dnZ2d@comcast.com...
>> <snip>
>>[color=darkred]
>>>Howdy.
>>>
>>>One thing I see - you use $where before you set it. What happens if you
>>>move the code which sets $where earlier in your routine?
>>>
>>>--
>>>==================
>>>Remove the "x" from my email address
>>>Jerry Stuckle
>>>JDS Computer Training Corp.
>>>jstucklex@attglobal.net
>>>==================[/color]
>>
>>
>> Hi Jerry,
>>
>> When I moved the code which set's $where to above the first $where, I
>> found that although gallery.php worked fine,
>> gallery.php?category=landscape failed to run and I got an error message.
>>
>> Do you have any more ideas at all?
>>
>> I feel like the problem is to do with the $query values and I'm just not
>> setting them correcly with the new piece of code, or not in the right
>> order.
>>
>> To add to this, I've just noticed that when I load the landscape gallery,
>> not only does it display all images now (albeit in a paginated format)
>> instead of just the landscape images, but if I click the paginated result
>> for page 2, it changes the page title back to just Gallery, instead of
>> the main page of Landscape gallery.
>>
>> This looks like it's more involved than I thought it would be! :-(
>>
>> Again, if you or anyone else spot anything else obvious, please let me
>> know.
>>
>> Thanks,
>>
>> Stephen[/color]
>
> Stephen,
>
> Sounds like you need to study the code and understand it a little more.
>
> I've never found it productive to change code (or even implement someone
> else's code as part of mine) until I understood just what it was doing.
>
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================[/color]

Hi Jerry,

I am doing this too. I've got PHP and My SQL for Dummies, and PHP and MySQL
Web Development. Although I know HTML inside out, I'm finding PHP very
though going.

By the time I fully understand the code, it could be months and months down
the line. I seem quite close with my limited understanding and help from
the group, so was just wondering if there was anything quick and obvious
that someone could spot that would make it all work.

I'll keep plugging away at it, though I'm still open to suggestions! ;-)

Thanks,

Stephen


Jerry Stuckle
Guest
 
Posts: n/a
#6: May 6 '06

re: Gallery Pagination Result Problem


ste wrote:[color=blue]
> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
> news:mMedncq5GZlHdsbZnZ2dnUVZ_tSdnZ2d@comcast.com. ..
>[color=green]
>>ste wrote:
>>[color=darkred]
>>>"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
>>>news:SNWdnWxNpsKsrMbZnZ2dnUVZ_v-dnZ2d@comcast.com...
>>><snip>
>>>
>>>>Howdy.
>>>>
>>>>One thing I see - you use $where before you set it. What happens if you
>>>>move the code which sets $where earlier in your routine?
>>>>
>>>>--
>>>>==================
>>>>Remove the "x" from my email address
>>>>Jerry Stuckle
>>>>JDS Computer Training Corp.
>>>>jstucklex@attglobal.net
>>>>==================
>>>
>>>
>>>Hi Jerry,
>>>
>>>When I moved the code which set's $where to above the first $where, I
>>>found that although gallery.php worked fine,
>>>gallery.php?category=landscape failed to run and I got an error message.
>>>
>>>Do you have any more ideas at all?
>>>
>>>I feel like the problem is to do with the $query values and I'm just not
>>>setting them correcly with the new piece of code, or not in the right
>>>order.
>>>
>>>To add to this, I've just noticed that when I load the landscape gallery,
>>>not only does it display all images now (albeit in a paginated format)
>>>instead of just the landscape images, but if I click the paginated result
>>>for page 2, it changes the page title back to just Gallery, instead of
>>>the main page of Landscape gallery.
>>>
>>>This looks like it's more involved than I thought it would be! :-(
>>>
>>>Again, if you or anyone else spot anything else obvious, please let me
>>>know.
>>>
>>>Thanks,
>>>
>>>Stephen[/color]
>>
>>Stephen,
>>
>>Sounds like you need to study the code and understand it a little more.
>>
>>I've never found it productive to change code (or even implement someone
>>else's code as part of mine) until I understood just what it was doing.
>>
>>
>>--
>>==================
>>Remove the "x" from my email address
>>Jerry Stuckle
>>JDS Computer Training Corp.
>>jstucklex@attglobal.net
>>==================[/color]
>
>
> Hi Jerry,
>
> I am doing this too. I've got PHP and My SQL for Dummies, and PHP and MySQL
> Web Development. Although I know HTML inside out, I'm finding PHP very
> though going.
>
> By the time I fully understand the code, it could be months and months down
> the line. I seem quite close with my limited understanding and help from
> the group, so was just wondering if there was anything quick and obvious
> that someone could spot that would make it all work.
>
> I'll keep plugging away at it, though I'm still open to suggestions! ;-)
>
> Thanks,
>
> Stephen
>
>[/color]

Stephen,

Not really at this point. Obvious problems are resolved, but anyone would have
to look through a lot more code to understand your latest problems.

Welcome to the world of programming! :-)


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
ste
Guest
 
Posts: n/a
#7: May 6 '06

re: Gallery Pagination Result Problem



"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
news:QPmdnf0cdJAxncHZRVn-rg@comcast.com...
<snip>[color=blue]
>
> Stephen,
>
> Not really at this point. Obvious problems are resolved, but anyone would
> have to look through a lot more code to understand your latest problems.
>
> Welcome to the world of programming! :-)
>
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================[/color]

Hi Jerry,

Indeed! :-)

By the way, I've been writing the HTML / PHP etc using Notepad++ for the
syntax highlighting. I use Altova XML Spy Home Edition when writing simple
XML scripts, and it has the added benefit of validating the XML and pointing
out errors against the DTD.

Is there such a free program for writing PHP that has a good debugging mode
or validation?

Thanks,

Stephen


Jerry Stuckle
Guest
 
Posts: n/a
#8: May 6 '06

re: Gallery Pagination Result Problem


ste wrote:[color=blue]
> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
> news:QPmdnf0cdJAxncHZRVn-rg@comcast.com...
> <snip>
>[color=green]
>>Stephen,
>>
>>Not really at this point. Obvious problems are resolved, but anyone would
>>have to look through a lot more code to understand your latest problems.
>>
>>Welcome to the world of programming! :-)
>>
>>
>>--
>>==================
>>Remove the "x" from my email address
>>Jerry Stuckle
>>JDS Computer Training Corp.
>>jstucklex@attglobal.net
>>==================[/color]
>
>
> Hi Jerry,
>
> Indeed! :-)
>
> By the way, I've been writing the HTML / PHP etc using Notepad++ for the
> syntax highlighting. I use Altova XML Spy Home Edition when writing simple
> XML scripts, and it has the added benefit of validating the XML and pointing
> out errors against the DTD.
>
> Is there such a free program for writing PHP that has a good debugging mode
> or validation?
>
> Thanks,
>
> Stephen
>
>[/color]

Stephen,

Sorry, I don't know about free - I don't use them. I do know Zend Studio, while
not free, is excellent, though. Well worth the price, IMHO. And if I'm not
using a debugger, I've found strategically placed echo statements do wonders for
debugging.

Disclaimer: And no, I have no relationship with the other than having used their
software. :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
ste
Guest
 
Posts: n/a
#9: May 6 '06

re: Gallery Pagination Result Problem



"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
news:TIidnSVAeLoAmMHZRVn-vA@comcast.com...
<snip>[color=blue]
> Stephen,
>
> Sorry, I don't know about free - I don't use them. I do know Zend Studio,
> while not free, is excellent, though. Well worth the price, IMHO. And if
> I'm not using a debugger, I've found strategically placed echo statements
> do wonders for debugging.
>
> Disclaimer: And no, I have no relationship with the other than having used
> their software. :-)
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================[/color]

Thanks Jerry, I'll check it out.

So you won't even get a commission if I mention your name? ;-)

Stephen


Rik
Guest
 
Posts: n/a
#10: May 6 '06

re: Gallery Pagination Result Problem


ste wrote:[color=blue]
> <?php
> include("databasepasswords");
> if (isset($_GET['pageno'])) {
> $pageno = $_GET['pageno'];[/color]

Tssk, if thought I told you to escape GET variables if used in queries :-).
$pageno = mysql_real_escape_string(_GET['pageno'],$connection);
[color=blue]
> $query = "SELECT count(*) FROM images ".$where;
> $result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);[/color]

As said, $where whould be set BEFORE this query.
[color=blue]
> $query = "SELECT * FROM images ORDER BY dateadded,
> datetaken DESC $limit ".$where ;[/color]

Echo this query and you'll see what's wrong. It should be

$query = "SELECT * FROM images ORDER BY `dateadded`, `datetaken` DESC $where
$limit";

Wether your code creates proper pages I'm not going to check.

For future reference:
Echoing variables after they are set or print_r() arrays will make a lot
more clear to you in debugging.
In this instance, echoing the query would have told you right away the query
was composed in the wrong order.

Grtz,
--
Rik Wasmus


Jerry Stuckle
Guest
 
Posts: n/a
#11: May 6 '06

re: Gallery Pagination Result Problem


ste wrote:[color=blue]
> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
> news:TIidnSVAeLoAmMHZRVn-vA@comcast.com...
> <snip>
>[color=green]
>>Stephen,
>>
>>Sorry, I don't know about free - I don't use them. I do know Zend Studio,
>>while not free, is excellent, though. Well worth the price, IMHO. And if
>>I'm not using a debugger, I've found strategically placed echo statements
>>do wonders for debugging.
>>
>>Disclaimer: And no, I have no relationship with the other than having used
>>their software. :-)
>>
>>--
>>==================
>>Remove the "x" from my email address
>>Jerry Stuckle
>>JDS Computer Training Corp.
>>jstucklex@attglobal.net
>>==================[/color]
>
>
> Thanks Jerry, I'll check it out.
>
> So you won't even get a commission if I mention your name? ;-)
>
> Stephen
>
>[/color]

No, but they might refuse to sell it to you for any price! :-)


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
ste
Guest
 
Posts: n/a
#12: May 11 '06

re: Gallery Pagination Result Problem



"Rik" <luiheidsgoeroe@hotmail.com> wrote in message
news:e3i4l7$ivk$1@netlx020.civ.utwente.nl...[color=blue]
> ste wrote:[color=green]
>> <?php
>> include("databasepasswords");
>> if (isset($_GET['pageno'])) {
>> $pageno = $_GET['pageno'];[/color]
>
> Tssk, if thought I told you to escape GET variables if used in queries
> :-).
> $pageno = mysql_real_escape_string(_GET['pageno'],$connection);
>[color=green]
>> $query = "SELECT count(*) FROM images ".$where;
>> $result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);[/color]
>
> As said, $where whould be set BEFORE this query.
>[color=green]
>> $query = "SELECT * FROM images ORDER BY dateadded,
>> datetaken DESC $limit ".$where ;[/color]
>
> Echo this query and you'll see what's wrong. It should be
>
> $query = "SELECT * FROM images ORDER BY `dateadded`, `datetaken` DESC
> $where
> $limit";
>
> Wether your code creates proper pages I'm not going to check.
>
> For future reference:
> Echoing variables after they are set or print_r() arrays will make a lot
> more clear to you in debugging.
> In this instance, echoing the query would have told you right away the
> query
> was composed in the wrong order.
>
> Grtz,
> --
> Rik Wasmus[/color]


Hi Rik,

I echo'd the actual query to see what was failing, then I tried the query in
question in MyPHPAdmin to see if it worked there, and it didn't of course.

After a bit of trial and error, I have changed the query from:

SELECT *
FROM images
ORDER BY dateadded, datetaken DESC
LIMIT 0,9
WHERE category = 'Abstract'

To:

SELECT *
FROM images
WHERE category = 'Abstract'
ORDER BY dateadded, datetaken
LIMIT 0 , 9

....and this now works! :-)

Thanks again,

Ste


Closed Thread


Similar PHP bytes