SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: PHP Help

  1. #1
    SitePoint Member
    Join Date
    May 2001
    Location
    Vulcan
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right so far i have been able to make a page display all the reviews in my review table on the page but what i cant figure out is how to get it to display one review per page depending on the url? in the review table i have two fields ID and text.
    Also i want to be able to have the reviews on multiple pages and again use the url to get it such as Reviews.php?ID=1+Page=2 or something.
    Any help apreciated.

    (bear with me programing isnt my strong point)

  2. #2
    Not Bad, eh? Justin Sampson's Avatar
    Join Date
    Aug 2000
    Location
    N.S., Canada
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,
    In your SQL statment add this to the end:
    where id = '$id'

    So it should look somthing like this:
    select title, body, author from reviews where id = '$id'

    Then when you type. whateverthepageis.php?id=3

    It will select the third record from your database and so on.

    If I confused you just tell me and I'll clarify.

  3. #3
    SitePoint Member
    Join Date
    May 2001
    Location
    Vulcan
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your a lifesaver that sorted it, you dont happen to know how to get it to use multiple pages do you? i plan to use this for my website reviews and some are longer than one page, i assume i will have to edit my dbase and possably add a page field?

  4. #4
    SitePoint Member
    Join Date
    May 2001
    Location
    Vulcan
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bump, anyone know how to do the multiple page thing?
    Ryan Munro
    Jsi Hardware
    Http://www.jsihardware.com
    "To Not Overclock Is Illogical"

  5. #5
    SitePoint Member
    Join Date
    May 2001
    Location
    Vulcan
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can probably work out the code needed but i am stuck on how to modify the database, do i add a extra field called page? if so where do i add the text for the extra pages in the reviews?
    Ryan Munro
    Jsi Hardware
    Http://www.jsihardware.com
    "To Not Overclock Is Illogical"

  6. #6
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the ideal data structure for what you want to achieve. Have one table called Review and one called ReviewPage.

    They might have the following fields

    Review
    ------
    id <- primary key
    title
    author
    etc...

    ReviewPage
    --------
    id <- primary key
    reviewID <- foreign key references Reiview.id
    pageNum
    content <- a text field that holds the actual text for the page

    That's the best structure according to the theory of data normalisation (ie, minimum redundancy, most data integrity).

    So lets say you want to get the info about a review:
    SELECT * FROM Review where id = '$id'

    Now lets say you want to work out how many pages that review has:
    SELECT COUNT(*) FROM ReviewPage WHERE reviewID= '$id'

    Lets say you want to get the contents of the first page of that review
    SELECT content FROM ReviewPage
    WHERE reviewID = '$id'
    AND page = 1


    Does that help at all?

  7. #7
    SitePoint Member
    Join Date
    May 2001
    Location
    Vulcan
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have been trying to use page breaks but can get the code to work, prolly something silly so can some one take a look for me?

    <?php
    $review = mysql_query("SELECT text FROM reviews ".
    "WHERE ID=$id");
    $review = mysql_fetch_array($review);
    $pagetext = $reveiw["text"];

    // If no page specified, default to the
    // first page ($page = 0)
    if (!isset($page)) $page = 0;
    // Split the text into an array of pages
    $textarray=split("\[PAGEBREAK]",$pagetext);
    // Select the page we want
    $pagetext=$textarray[$page];
    ?>

    in the dbase the fields are as follows :

    ID
    text

    at the mo is says :

    Warning: Supplied argument is not a valid MySQL result resource in /home.../reviews2.php on line 18

    That line contains the following text :

    $review = mysql_fetch_array($review);
    Ryan Munro
    Jsi Hardware
    Http://www.jsihardware.com
    "To Not Overclock Is Illogical"

  8. #8
    SitePoint Member
    Join Date
    May 2001
    Location
    Vulcan
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help guys, managed to get it working, dunno what the prob was but i have backed up the code for future use
    Ryan Munro
    Jsi Hardware
    Http://www.jsihardware.com
    "To Not Overclock Is Illogical"

  9. #9
    SitePoint Member Lavee's Avatar
    Join Date
    May 2001
    Location
    Omaha, Ne
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $review = mysql_fetch_array($review);
    $pagetext = $reveiw["text"];
    You have the review spelled wrong in the 19th line. Check it out.

    Thanks
    Lavee
    http://www.Aplusjokes.com - Hundreds of funny
    pictures and cartoons

  10. #10
    SitePoint Member
    Join Date
    May 2001
    Location
    Vulcan
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    all sorted now thanks for all the help
    Ryan Munro
    Jsi Hardware
    Http://www.jsihardware.com
    "To Not Overclock Is Illogical"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •