AMS245
Tue 19 December 2006, 09:24 pm GMT +0100
Hi:
I actually posted this on the php forum, but discovered afterward, that this forum is probably more to the point. This is my first time posting to this site and I'm very glad you all are here! This is what I posted on the other forum:
I am currently working with the My Pagina previous-next navigation script. All was working fine until I altered the sql statement for the purpose of limiting the number of records pulled from the MySQL table I'm working with. When I run the following query in the script, all works fine:
SELECT * FROM news ORDER BY dtime DESC;
When I change it to the following:
SELECT * FROM news ORDER BY dtime DESC LIMIT 5;
I get the following error message:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/magnet/public_html/NewsScript/Display/my_pagina_class.php</b> on line 90
I know this is a legitimate query because I ran it through a query analyzer and it worked fine. Can you tell me what the problem might be?
Anne Marie
olaf
Tue 19 December 2006, 10:33 pm GMT +0100
the limit is set by the class, just check the example:
$test->sql = "SELECT * FROM link_list ORDER BY id"; // the (basic) sql statement (use the SQL whatever you like)
and check also the comments inside the class...
AMS245
Wed 20 December 2006, 12:20 am GMT +0100
Hi Olaf:
I'm still a newbie with php, just need to say that! OK. I looked at the my_pagina_class.php page and found the $max_rows variable which the comments state is used to limit the number of records returned from the dbase. I set that variable to 5, hoping it would limit the number of records queried, but I still got the full record set coming up. I want to distinguish between how many records are being displayed on the page as opposed to the number I'm attempting to limit in my sql query. I have it displaying one page at a time, using the "simple_nav_links" function - that part is working fine. I now want to limit the number of records to cycling through to 5 records only. (These are going to be news articles and we want to limit their availability to the users to the most current 5 articles.) Here is the URL so you can see what we're trying to do:
http://magnet.caltech.edu/iFrameTest3.php.
AM
olaf
Wed 20 December 2006, 12:22 am GMT +0100
just read the comments:
(from the config file)
// some external constants to controle the output
define("QS_VAR", "page"); // the variable name inside the query string (don't use this name inside other links)
define("NUM_ROWS", 4); // the number of records on each page
define("STR_FWD", ">>"); // the string is used for a link (step forward)
define("STR_BWD", "<<"); // the string is used for a link (step backward)
// use the rught pathes to get it working with the php function getimagesize
define("IMG_FWD", "./forward.gif"); // the image for forward link
define("IMG_BWD", "./backward.gif"); // the image for backward link
define("NUM_LINKS", 5); // the number of links inside the navigation (the default value)
AMS245
Wed 20 December 2006, 01:14 am GMT +0100
I apologize for double-posting. My mistake. I'll stick to this forum, although I just blew it again and posted the response below to the other forum. Sorry! For the sake of consistency, I'll post what I meant to post here earlier:
******************************
What I see in the db_config.php file is a line to limit the number of records displayed on the page:
define("NUM_ROWS", 1); // the number of records on each page. This is set correctly for my purposes.
The next line I see that limits something is:
define("NUM_LINKS", 5); // the number of links inside the navigation (the default value). Since I'm using the $simple_nav_link, this doesn't appear to apply to my needs in the script.
What is not clear is why I can't seem to limit the number of records that are pulled from the database in the sql query. I want to be able to step forward and back the most recent 5 records only. What am I missing here?
AM
olaf
Wed 20 December 2006, 08:56 am GMT +0100
do you have a database with many records and you want to show only the last x records? why?
AMS245
Wed 20 December 2006, 08:29 pm GMT +0100
That's exactly what I want to do. The database will be the storehouse for multiple articles. Those that are older than the most recent 5 articles will be viewable in an "archive" section of our website. I'm trying to set things up so that I can run both the recent article display page and the archive page out of the same database table.
AM
olaf
Wed 20 December 2006, 09:39 pm GMT +0100
That's exactly what I want to do. The database will be the storehouse for multiple articles. Those that are older than the most recent 5 articles will be viewable in an "archive" section of our website. I'm trying to set things up so that I can run both the recent article display page and the archive page out of the same database table.
AM
and how many "new" articles do you wanna show?
AMS245
Wed 20 December 2006, 09:45 pm GMT +0100
Five.
AMS245
Wed 20 December 2006, 10:12 pm GMT +0100
I ran the page with the error on it. It's at
http://magnet.caltech.edu/iFrameTest3.php?page=0. I just noticed that the arrows are actually cycling through just 5 records (yay!), but the error message (need to look at View Source) indicates that "mysql_num_rows(): supplied argument is not a valid MySQL result resource". Does this help ferret out what the problem might be?
olaf
Wed 20 December 2006, 10:49 pm GMT +0100
Five.
why do you need a class like this for pagination?
olaf
Thu 21 December 2006, 02:51 pm GMT +0100
I think you're using the wrong script for this small result, try this one:
http://www.finalwebsites.com/snippets.php?id=37
AMS245
Wed 3 January 2007, 12:25 am GMT +0100
I was able to locate another script and got it working. Thank you for your response though.