Question

Discussion in 'PHP' started by personalpa, Feb 12, 2007.

  1. #1
    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
     
    personalpa, Feb 12, 2007 IP
  2. frankcow

    frankcow Well-Known Member

    Messages:
    4,859
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    180
    #2
    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
     
    frankcow, Feb 12, 2007 IP
  3. personalpa

    personalpa Peon

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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.
     
    personalpa, Feb 12, 2007 IP
  4. tandac

    tandac Active Member

    Messages:
    337
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #4
    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
     
    tandac, Feb 12, 2007 IP
  5. personalpa

    personalpa Peon

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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.
     
    personalpa, Feb 12, 2007 IP
  6. wenzlerpaul

    wenzlerpaul Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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.
     
    wenzlerpaul, Feb 12, 2007 IP
  7. personalpa

    personalpa Peon

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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?
     
    personalpa, Feb 12, 2007 IP
  8. rajnikant

    rajnikant Peon

    Messages:
    18
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    This will not work properly in mysql

    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);
     
    rajnikant, Feb 13, 2007 IP