SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    UK
    Posts
    303
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    pulling together

    Well - i'm back, and i got another problem...

    For those who visit this forum often may have followed the various problems i have had, and noticed that i'm building a site that sorts recent articles and displays them on my index page (very much in a phpnuke way, although a lot simpler).

    Ok - now ive kinda reached a crunch point where i need a whole lotta advice and a whole lotta help. Explanations in english in the immediate future i think will serve me better atm. Working out the code i will work through slowly.

    I will explain the problem, this may take sum time... *pauses for breath, sips water*

    Ii have a multi page site that has the same layout but different content on each page (like sitepoint). I wanted to create a single page - that automatically queried a db table called 'content' using an id number pulled from the url (ie www.address.com/index.php?id=3) this would load the index page and would pull the content of the page from the db where id=3.

    This, i believed, would be simple enough but i also wanted one of the pages (originally index but now news.php) to pull recent articles from a separate db table 'articles'.

    so...

    How do i write a script that pulls content from the db on certain IDs for normal pages, but runs a separate script (can be included on same page) for alternative id numbers. this second script is the one that collects sorts and echoes the articles.

    Is the answer (have been thinking as i type) gonna be a simple if statement (possibly nested) or is this gonna be well complicated.

    Any advice would be much appreciated along with some clear explanations.

    I hope my explanation was satisfactory and i will of course attempt to clarify any queries.

    Thanks for your time.

    Azaar
    Last edited by Azaar; Jan 14, 2002 at 17:13.

  2. #2
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Think I see what you're saying.

    The simplest solution would be an if (or a switch statement even better).

    Something like

    switch ( $id ) {

    case "6":
    include ( "includes/articlegrab.php" );
    break;

    default:
    include ( "includes/defaultgrab.php" );
    break;

    }

    Where articlegrab.php runs the query for the special case and defaultgrab.php is the normal query you run.

    Trouble is you're then hard coding id numbers. Would be better to either use different variable names for the different queries (e.g. news.php?article=6 then you can check with the ISSET function) or if that's a no go, use either a special range of ids for these artices (e.g. if ( $id > 1000 )... ) or use letters instead to prepend the numbers in $id values of articles (e.g. $id = a6 ) then you can use something like the strstr function to find the letter a in $id.

  3. #3
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    UK
    Posts
    303
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    interesting, thank you.


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
  •