![]() |
Well, here is my first vB hack. I have not cut any code for a long time so that if anyone wants to clean up my PHP, please feel free to comment. I do wonder if there is a way to get the total number of records without a second query; I thought of counting to see if fewer than 30 (my page limit) smilies were returned, but then I would have to give up the "First to Last of Total" report.
I added the following variables: $startsmilies, $smilieslink, $linkstartsmilies, $smiliescountresult, $smiliescountrow and $smiliescount Any way: Replace the section in index.php (the main one, not the /admin/ one) that deals with "action=showsmilies" -- I have not posted it here as all my code has been added between the start and end of the section so that it should be simple for you to find (lines 44 to 56 in an un-hacked index.php). Code:
if ($action=="showsmilies") {
Peter E. Humphries [Edited by phumphries on 07-26-2000 at 01:14 PM] |
$smilies=$DB_site->query("SELECT smilietext,title,smiliepath,COUNT(title)as Total FROM smilie ORDER BY title LIMIT $startsmilies,30");
You should be able to do that and the result set would have the total smilies in the "Total" field. I am not sure if the count will be set to 30 by the LIMIT statement though. Hmm? [Edited by rangersfan on 07-26-2000 at 01:28 PM] |
I will have to try that, again. I did try "COUNT(*) AS Total" and received a nice little "Your database is having problems" type error. :eek:
Peter E. Humphries |
That should work also.
It is valid SQL syntax as I have this code in one of my files: Code:
"SELECT post.userid, count(post.userid) as count, user.username from " . |
Well, I have not tried to change the query, although it was with that intention that I openned the script for modification. I ended up adding a much nicer navigation bar.
To use it, find your favourite First, Previous, Next and Last graphics and replace nav_first_on.gif, nav_first_off.giff, nav_prev_on.gif, &c, in the following code. I added one more variable, $smilieslinklast, to determine whether or not to enable the navigation for the last page button. Code:
if ($action=="showsmilies") { |
Further to the COUNT() problem, I tried all sorts of combinations to no avail. However, the mySQL manual states that running "SELECT COUNT(*) AS Total FROM smilie" is optimized to return the fastest possible result so that it is, in any case, the right way to get the value.
Ah, well. |
rangersfan: I thought that you might, for interest's sake, like to know that my COUNT() error was due to not having a GROUP BY clause. To quote:
Quote:
|
I still don't see how running two queries is going to be faster than putting the count with a group by into one query.
I read that statement to mean that using count(*) is going to return the fastest answer as opposed to running count(some field name). Which I think doesn't imply that you should use 2 queries but you should use count(*) with the group by to achieve the fastest answer as opposed to doing two select statements. (make any sense?) [Edited by rangersfan on 08-10-2000 at 04:50 PM] |
Well, I have a couple of little hacks to do for my Intranet people -- while I have the source open, I will try it out and let you know what blows up.
|
All times are GMT. The time now is 03:00 AM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|