![]() |
|
#1
|
|||
|
|||
Viewing data in multiple groups in PHPI'm working on developing a forum system for one of my newer websites. I have all of the tables that I will need for this, as far as database linking is concerned, and managing the forums with the user database. However, I've run into a road block.
Almost the only thing I haven't worked with, using PHP and MySQL, is viewing data in multiple groups. I don't want a forum topic page to list all 1,000 posts that it has in it, rather listing them in groups of 20 and allowing the user to browse their way through the groups. This is how most professional forum systems work, including this one I assume. I haven't done this type of thing with any of my websites before. Can anyone point me in the right direction to get started? |
|
#2
|
||||
|
||||
Try with SQL_CALC_FOUND_ROWSYou need to set the max number of posts per page. Say you set it at 10...
Assuming you have 2 basic tables; 1. `threads` 2. `posts` Here's an example forum show-thread script with the basic but relevant bits to help you get started. See the comments within the script and also note the SQL_CALC_FOUND_ROWS keyword in the first SQL statement. PHP Code:
Please understand that this example code is just that -- an example. I didn't like test it or anything like that... and may contain errors/typos... ![]() __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#3
|
|||
|
|||
Re: Viewing data in multiple groups in PHPThanks!
I have formatted the code for my site and the offset limiter for the pages seems to work great. I'm having a little trouble doing the multipage links, however. Do you think you could go more indepth into that possibly? [EDIT:] Also, I was having problems returning a value from the FOUND_ROWS() clause. Can it only be used if the previous SQL_CALC_FOUND_ROWS statement is a UNION? You used a statement in the first sql line as LEFT JOIN and ON. This is something I had to leave out in my first line as it was returning errors. |
|
#4
|
|||
|
|||
Re: Viewing data in multiple groups in PHPAnother problem I was having with this is the SQL_CALC_FOUND_ROWS....it seems to always return a SQL syntax error.
PHP Code:
The SQL statement returns: You have an error in your SQL syntax near 'FROM forum_thread JOIN forum_assoc ON forum_thread.assoc_forum_id = forum_assoc.' at line 1 forum_thread.assoc_forum_id = the forum number where the thread belongs forum_assoc.id = the id of the forum that the thread/forum id is supposed to match. This syntax is similar to the SQL that you previously posted, with alterations to make it work for my table structure. Any idea why it returns these errors? |
|
#5
|
||||
|
||||
Re: Viewing data in multiple groups in PHPI am sorry I missed replying to your previous post but now I am not sure if you still require help with the multi-page links. But I'll include a very simple example just for the people reading this thread sometime in the near future...
PHP Code:
Frankly, I have never used UNION before. I mean I know what it's supposed to do but I never really needed to use it. Since it always means joining two SELECT statements, I suppose you need to insert SQL_CALC_FOUND_ROWS into both e.g. SELECT SQL_CALC_FOUND_ROWS * ... UNION SELECT SQL_CALC_FOUND_ROWS * .... __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#6
|
||||
|
||||
Re: Viewing data in multiple groups in PHPQuote:
At a glance, your SQL statement seems valid and I am not sure what is wrong. If in doubt, please test it out with a simple SQL e.g. PHP Code:
__________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#7
|
|||
|
|||
Re: Viewing data in multiple groups in PHPYou have an error in your SQL syntax near 'FROM forum_thread LIMIT 0, 3' at line 1
It seems that I can't use SQL_CALC_FONUD_ROWS at all. |
|
#8
|
||||
|
||||
Re: Viewing data in multiple groups in PHPWhat do I think? I think it's okay for you to use any method that works.
Also, if I were you, I would want to find out why I cannot use SQL_CALC_FOUND_ROWS! e.g. What is the version of the MySQL server and client? If you figure out what is wrong eventually, please update this thread with the information so you can help save someone else some time looking for the solution. __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#9
|
|||
|
|||
Re: Viewing data in multiple groups in PHPMySQL version is....3.23.54
[EDIT] Seeing that my version in 3.23, I read on a site about 2 seconds before this edit that the SQL_CALC_FOUND_ROWS comes with version 4.0. I am going to try to update and see if that solves the problem. Are there any risks to updating MySQL on a server that has established and much needed databases? |
Recent GIDBlog
A Week in Kuwait by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Include] Doubly-linked List | dsmith | C Programming Language | 6 | 14-Apr-2006 13:12 |
| [CONTEST?]Data Structure Test | dsmith | C Programming Language | 2 | 06-Jun-2004 15:13 |
| Grouping data from MySQL with PHP - Newbie question. | giobbi | MySQL / PHP Forum | 12 | 27-Feb-2004 00:34 |
| Automate a data change php form | mjfmn | MySQL / PHP Forum | 4 | 20-Oct-2003 09:37 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The