View Full Version : Question
personalpa
Feb 12th 2007, 4:52 am
I made a script and I added lot of data in a MYSQL Database. Then I made a few pages, now I want only some records to appear in pages. At the moment, what I do is, if I want record
A B C D
to appear on 4 pages, I put it 4 times, and I have a column PageId in Database.
Other option is I make 4 columns in table and set 0 or 1 in those fields either to show or hide data on the page.
Third option is I have a field PAGEID and put page numbers like 1,2,3 so that it shows that record on page 1,2,3 but if I do that, how do I select it ? For example, if I write code for page 2 and want to see which data has to be put there, what SQL statement do I put ? Will this work ?
SELECT * from xyz WHERE PAGEID=2;
Thanks
Gautam
frankcow
Feb 12th 2007, 5:02 am
Why don't you just use paging, and display the number of records you want at a time? It's super easy with PHP, and you don't need to modify your MySQL database at all
personalpa
Feb 12th 2007, 5:05 am
That is not what I am trying to do.
There are many records and many pages. A record can be on more than one page.
tandac
Feb 12th 2007, 6:48 am
I'm not quite sure I understand what you're after... I'm assuming you have an article or something that can be many pages and you want to display potentially the same article on different pages/sections of your site.
select * from xyz articles where articleid=1 and pageid=2
would work nicely.
You could then have a showarticle.php page:
showarticle.php?id=1
If you want to get really fancy use a keyword and mod rewrite.
/article/keyword/pageX.html -> showarticle.php?keyword=blah&page=X
personalpa
Feb 12th 2007, 6:59 am
There are many articles and many pages. One article may appear on more than one page. Also, an article can only be limited to one page. So, these are choices I have
Table - articles :
Name, Content, PID
TEST TEST 1
TEST TEST 2
TEST TEST 3
Then on Page 1, I have SELECT * from articles where PID=1; and so on. The disadvantage is I have to copy same article again and again to get it on different pages.
Second choice. Table articles :
Name, Content, PID1, PID2, PID3
TEST TEST 1 1 1 (1 = show, 0 = don't show)
Then on Page 1, I have SELECT * from articles WHERE PID1=1;
Third Option, Table Articles
Name, Content, PID
TEST TEST 1,2,3
If I do this, then SELECT * from articles WHERE PID=1 does not work.
Which is best way to do it ?
Thanks for your help.
wenzlerpaul
Feb 12th 2007, 8:41 am
I do not know if i understand you correctly but the way i see it is you need to call articles and consolidate them in a given page.
I suggest that you create a separate table hold the PID's and a groupid/article id with an incremental id, so now you have 3 fields. sample:
id groupid pid
groupid will stand as your grouper of all of the pid's.
you can now select * from groupertable where pid=1;
You will need to edit your php or create a new page where you can assign a pid to a groupid where the groupid will be your page.
so if page 1 is groupid 1,
you can now select * from groupertable where pid=1 AND groupid=1;
or you can use range queries like > or =< type of queries to echo 1,2,3
or jut play around qith your queries then.
I hope this is what you meant, and also hope you understood my point hehe.
personalpa
Feb 12th 2007, 8:45 am
Suppose in a MySql Field PageId, the following data is there
1,2,5,10,15
& If I want to search that to see if 5 is there or not. If I Use
SELECT * From TABLE where PageId = 5 , It won't work because it is not 5.
If I use WHERE PageId Like 5%, it will create problem if I have 50+ Pages.
So, basically , how do I search a string?
rajnikant
Feb 13th 2007, 11:43 pm
This will not work properly in mysql
Suppose in a MySql Field PageId, the following data is there
1,2,5,10,15
& If I want to search that to see if 5 is there or not. If I Use
SELECT * From TABLE where PageId = 5 , It won't work because it is not 5.
Instead you should write a query like this :
SELECT * From TABLE where 5 in (PageId); PageId = 1,2,5,10,15 OR
if PageId = '1','2','5','10','15' in the database then it should be like this:
SELECT * From TABLE where '5' in (PageId);
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.