too much if() and stuff at top of page? - or is there a more efficient way?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • juglesh

    too much if() and stuff at top of page? - or is there a more efficient way?

    hi, I'm just getting started here in php, but i've been able to get some
    basic variable stuff working, so I'm just looking for advice on the basic
    set up of some thumbnail->picture pages. the thumbnail page will send the
    variable $picname to the picturepage.php .

    I'm thinking, picturepage.php would look like this:

    <?
    if($picname == "birds"){
    $picture = "birds.jpg" ;
    $pagetitle = "Here are Some Birds";
    $prev = "thePreviouspag e.htm";
    $next = "theNextpage.ht m";
    $descrip = "<h1>Birds/<H1>
    this is some text describing the picture,
    it could be a lengthy paragraph with html formatting,
    maybe even a table with a little chart or something";
    }
    if($picname == "dogs"){
    $picture = "dogs.jpg";
    $pagetitle = "Here are Some Dogs";

    // if if if, lotsa ifs
    // etc etc, blah blah
    // could be 20 or more pictures, could be lots more
    // how much is too much?
    }

    ?>

    <HTML>
    <title> <?php echo($pagetitle ) ?> </title>
    <body>Welcome to my Picture page<br>
    here is the picture:
    <img src="<?php echo($picture) ?>" >
    here is where it was taken: <?php echo($descrip) ?>
    <etc, etc>


    I was wondering if this would be too long of a .php page, what with all the
    variables, description paragraph, etc. Or does that matter much? is it
    better to use an include? or an array? like, I could put the description
    paragraphs in separate txt files and include them?

    there's lots and lots of pictures, with lots of if()'s? possibly with long
    paragraphs of description? I guess the user only loads the actual outputted
    html, so, it wouldn't be a big thing. So, if the server is able to do its
    thing in a timely manner its ok?

    --

    thanks for your time,
    juglesh B>{)}


  • chris

    #2
    Re: too much if() and stuff at top of page? - or is there a more efficient way?

    check out the switch



    do something like this


    switch($picname )
    case "birds":
    $picture = "birds.jpg" ;
    $pagetitle = "Here are Some Birds";
    $prev = "thePreviouspag e.htm";
    $next = "theNextpage.ht m";
    $descrip = "<h1>Birds/<H1>
    this is some text describing the picture,
    it could be a lengthy paragraph with html formatting,
    maybe even a table with a little chart or something";
    break;
    case "dogs"
    $picture = "dogs.jpg";
    $pagetitle = "Here are Some Dogs";
    and so on and so on.....


    or IMHO you would be better off using a database - put all the information
    in a database nd retrieve what is needed, this will also be a lot easier to
    add , edit and delete information than all thise if or switch statements..

    HTH

    Chris


    "juglesh" <juglesh@nospam RadioKDUG.com> wrote in message
    news:RBvsd.1363 15$V41.34405@at tbi_s52...[color=blue]
    > hi, I'm just getting started here in php, but i've been able to get some
    > basic variable stuff working, so I'm just looking for advice on the basic
    > set up of some thumbnail->picture pages. the thumbnail page will send the
    > variable $picname to the picturepage.php .
    >
    > I'm thinking, picturepage.php would look like this:
    >
    > <?
    > if($picname == "birds"){
    > $picture = "birds.jpg" ;
    > $pagetitle = "Here are Some Birds";
    > $prev = "thePreviouspag e.htm";
    > $next = "theNextpage.ht m";
    > $descrip = "<h1>Birds/<H1>
    > this is some text describing the picture,
    > it could be a lengthy paragraph with html formatting,
    > maybe even a table with a little chart or something";
    > }
    > if($picname == "dogs"){
    > $picture = "dogs.jpg";
    > $pagetitle = "Here are Some Dogs";
    >
    > // if if if, lotsa ifs
    > // etc etc, blah blah
    > // could be 20 or more pictures, could be lots more
    > // how much is too much?
    > }
    >
    > ?>
    >
    > <HTML>
    > <title> <?php echo($pagetitle ) ?> </title>
    > <body>Welcome to my Picture page<br>
    > here is the picture:
    > <img src="<?php echo($picture) ?>" >
    > here is where it was taken: <?php echo($descrip) ?>
    > <etc, etc>
    >
    >
    > I was wondering if this would be too long of a .php page, what with all
    > the variables, description paragraph, etc. Or does that matter much? is
    > it better to use an include? or an array? like, I could put the
    > description paragraphs in separate txt files and include them?
    >
    > there's lots and lots of pictures, with lots of if()'s? possibly with long
    > paragraphs of description? I guess the user only loads the actual
    > outputted html, so, it wouldn't be a big thing. So, if the server is able
    > to do its thing in a timely manner its ok?
    >
    > --
    >
    > thanks for your time,
    > juglesh B>{)}
    >
    >[/color]


    Comment

    • Janwillem Borleffs

      #3
      Re: too much if() and stuff at top of page? - or is there a more efficient way?

      juglesh wrote:[color=blue]
      > I was wondering if this would be too long of a .php page, what with
      > all the variables, description paragraph, etc. Or does that matter
      > much? is it better to use an include? or an array? like, I could put
      > the description paragraphs in separate txt files and include them?
      >[/color]

      Besides performance, there is another thing which you should consider:
      Maintainance.

      A central file with a clear structure is easier to maintain then several
      seperate files. For small collections, I prever to use arrays, like:

      $assets = array(
      'birds' => array(
      'picture' => "birds.jpg" ,
      'pagetitle' => "Here are Some Birds",
      'prev' => "thePreviouspag e.htm",
      'next' => "theNextpage.ht m",
      'descrip' => "<h1>Birds/<H1>
      this is some text describing the picture,
      it could be a lengthy paragraph with html formatting,
      maybe even a table with a little chart or something"
      )
      );

      if (isset($assets[$picname])) {
      list($birds, $picture, $pagetitle, $prev, $next, $descrip) =
      array_values($a ssets[$picname]);
      }else {
      // No match, use a default or throw an error
      }

      You could also use an ini file, see http://www.php.net/parse_ini_file for
      details. With larger collections, a database should be the first option to
      consider.


      JW



      Comment

      • jn

        #4
        Re: too much if() and stuff at top of page? - or is there a more efficient way?

        "juglesh" <juglesh@nospam RadioKDUG.com> wrote in message
        news:RBvsd.1363 15$V41.34405@at tbi_s52...[color=blue]
        > hi, I'm just getting started here in php, but i've been able to get some
        > basic variable stuff working, so I'm just looking for advice on the basic
        > set up of some thumbnail->picture pages. the thumbnail page will send the
        > variable $picname to the picturepage.php .
        >
        > I'm thinking, picturepage.php would look like this:
        >
        > <?
        > if($picname == "birds"){
        > $picture = "birds.jpg" ;
        > $pagetitle = "Here are Some Birds";
        > $prev = "thePreviouspag e.htm";
        > $next = "theNextpage.ht m";
        > $descrip = "<h1>Birds/<H1>
        > this is some text describing the picture,
        > it could be a lengthy paragraph with html formatting,
        > maybe even a table with a little chart or something";
        > }
        > if($picname == "dogs"){
        > $picture = "dogs.jpg";
        > $pagetitle = "Here are Some Dogs";
        >
        > // if if if, lotsa ifs
        > // etc etc, blah blah
        > // could be 20 or more pictures, could be lots more
        > // how much is too much?
        > }
        >
        > ?>
        >
        > <HTML>
        > <title> <?php echo($pagetitle ) ?> </title>
        > <body>Welcome to my Picture page<br>
        > here is the picture:
        > <img src="<?php echo($picture) ?>" >
        > here is where it was taken: <?php echo($descrip) ?>
        > <etc, etc>
        >
        >
        > I was wondering if this would be too long of a .php page, what with all[/color]
        the[color=blue]
        > variables, description paragraph, etc. Or does that matter much? is it
        > better to use an include? or an array? like, I could put the description
        > paragraphs in separate txt files and include them?
        >
        > there's lots and lots of pictures, with lots of if()'s? possibly with long
        > paragraphs of description? I guess the user only loads the actual[/color]
        outputted[color=blue]
        > html, so, it wouldn't be a big thing. So, if the server is able to do its
        > thing in a timely manner its ok?
        >
        > --
        >
        > thanks for your time,
        > juglesh B>{)}
        >
        >[/color]


        Doing it that way for a small gallery is fine...but you really want to put
        your data in a database, then query it out on the page.



        Comment

        • Norman Peelman

          #5
          Re: too much if() and stuff at top of page? - or is there a more efficient way?

          "juglesh" <juglesh@nospam RadioKDUG.com> wrote in message
          news:RBvsd.1363 15$V41.34405@at tbi_s52...[color=blue]
          > hi, I'm just getting started here in php, but i've been able to get some
          > basic variable stuff working, so I'm just looking for advice on the basic
          > set up of some thumbnail->picture pages. the thumbnail page will send the
          > variable $picname to the picturepage.php .
          >
          > I'm thinking, picturepage.php would look like this:
          >
          > <?
          > if($picname == "birds"){
          > $picture = "birds.jpg" ;
          > $pagetitle = "Here are Some Birds";
          > $prev = "thePreviouspag e.htm";
          > $next = "theNextpage.ht m";
          > $descrip = "<h1>Birds/<H1>
          > this is some text describing the picture,
          > it could be a lengthy paragraph with html formatting,
          > maybe even a table with a little chart or something";
          > }
          > if($picname == "dogs"){
          > $picture = "dogs.jpg";
          > $pagetitle = "Here are Some Dogs";
          >
          > // if if if, lotsa ifs
          > // etc etc, blah blah
          > // could be 20 or more pictures, could be lots more
          > // how much is too much?
          > }
          >
          > ?>
          >
          > <HTML>
          > <title> <?php echo($pagetitle ) ?> </title>
          > <body>Welcome to my Picture page<br>
          > here is the picture:
          > <img src="<?php echo($picture) ?>" >
          > here is where it was taken: <?php echo($descrip) ?>
          > <etc, etc>
          >
          >
          > I was wondering if this would be too long of a .php page, what with all[/color]
          the[color=blue]
          > variables, description paragraph, etc. Or does that matter much? is it
          > better to use an include? or an array? like, I could put the description
          > paragraphs in separate txt files and include them?
          >
          > there's lots and lots of pictures, with lots of if()'s? possibly with long
          > paragraphs of description? I guess the user only loads the actual[/color]
          outputted[color=blue]
          > html, so, it wouldn't be a big thing. So, if the server is able to do its
          > thing in a timely manner its ok?
          >
          > --
          >
          > thanks for your time,
          > juglesh B>{)}
          >
          >[/color]

          Sure, it's ok. Using INCLUDES would really only make it easier for you to
          read. For starters, you could reduce some of the 'duplicated' code, try
          something like this:

          <?PHP
          $prev = "thePreviouspag e.htm";
          $next = "theNextpage.ht m";
          $desc_heading = '<H1>'.ucfirst( $picname).'</H1>';
          $pagetitle = 'Here are some '.ucfirst($picn ame);
          $picture = $picname.'.jpg' ;

          switch ($picname)
          {
          case 'birds':
          {
          $descrip = "$desc_head ing
          this is some text describing the picture,
          it could be a lengthy paragraph with html
          formatting,
          maybe even a table with a little chart or
          something";
          // add anything else for birds here
          break;
          }
          case 'dogs':
          {
          $descrip = "$desc_head ing
          this is some text describing the picture,
          it could be a lengthy paragraph with html
          formatting,
          maybe even a table with a little chart or
          something";
          // add anything else for dogs here
          break;
          }
          default:
          {
          $descrip = "<H1>No picture selected!</H1>
          Please go back and make another selection.";
          break;
          }
          }
          ?>

          <HTML>
          <title> <?php echo $pagetitle; ?> </title>
          <body>Welcome to my Picture page<br>
          here is the picture:
          <img src="<?php echo $picture; ?>" >
          here is where it was taken: <?php echo $descrip; ?>
          <etc, etc>

          ---
          Norman

          Avatar hosting at



          Comment

          • juglesh

            #6
            Re: too much if() and stuff at top of page? - or is there a more efficient way?


            "Norman Peelman" <npeelman@cfl.r r.com> wrote in message
            news:I9Dsd.9380 8$8G4.2465@torn ado.tampabay.rr .com...[color=blue]
            > "juglesh" <juglesh@nospam RadioKDUG.com> wrote in message
            > news:RBvsd.1363 15$V41.34405@at tbi_s52...[color=green]
            >> hi, I'm just getting started here in php, but i've been able to get some
            >> basic variable stuff working, so I'm just looking for advice on the basic
            >> set up of some thumbnail->picture pages. the thumbnail page will send the
            >> variable $picname to the picturepage.php .
            >>
            >> I'm thinking, picturepage.php would look like this:
            >>
            >> <?
            >> if($picname == "birds"){
            >> $picture = "birds.jpg" ;
            >> $pagetitle = "Here are Some Birds";
            >> $prev = "thePreviouspag e.htm";
            >> $next = "theNextpage.ht m";
            >> $descrip = "<h1>Birds/<H1>
            >> this is some text describing the picture,
            >> it could be a lengthy paragraph with html formatting,
            >> maybe even a table with a little chart or something";
            >> }
            >> if($picname == "dogs"){
            >> $picture = "dogs.jpg";
            >> $pagetitle = "Here are Some Dogs";
            >>
            >> // if if if, lotsa ifs
            >> // etc etc, blah blah
            >> // could be 20 or more pictures, could be lots more
            >> // how much is too much?
            >> }
            >>
            >> ?>
            >>
            >> <HTML>
            >> <title> <?php echo($pagetitle ) ?> </title>
            >> <body>Welcome to my Picture page<br>
            >> here is the picture:
            >> <img src="<?php echo($picture) ?>" >
            >> here is where it was taken: <?php echo($descrip) ?>
            >> <etc, etc>
            >>
            >>
            >> I was wondering if this would be too long of a .php page, what with all[/color]
            > the[color=green]
            >> variables, description paragraph, etc. Or does that matter much? is it
            >> better to use an include? or an array? like, I could put the description
            >> paragraphs in separate txt files and include them?
            >>
            >> there's lots and lots of pictures, with lots of if()'s? possibly with
            >> long
            >> paragraphs of description? I guess the user only loads the actual[/color]
            > outputted[color=green]
            >> html, so, it wouldn't be a big thing. So, if the server is able to do its
            >> thing in a timely manner its ok?
            >>
            >> --
            >>
            >> thanks for your time,
            >> juglesh B>{)}
            >>
            >>[/color]
            >
            > Sure, it's ok. Using INCLUDES would really only make it easier for you to
            > read. For starters, you could reduce some of the 'duplicated' code, try
            > something like this:
            >
            > <?PHP
            > $prev = "thePreviouspag e.htm";
            > $next = "theNextpage.ht m";
            > $desc_heading = '<H1>'.ucfirst( $picname).'</H1>';
            > $pagetitle = 'Here are some '.ucfirst($picn ame);
            > $picture = $picname.'.jpg' ;
            >
            > switch ($picname)
            > {
            > case 'birds':
            > {
            > $descrip = "$desc_head ing
            > this is some text describing the picture,
            > it could be a lengthy paragraph with html
            > formatting,
            > maybe even a table with a little chart or
            > something";
            > // add anything else for birds here
            > break;
            > }
            > case 'dogs':
            > {
            > $descrip = "$desc_head ing
            > this is some text describing the picture,
            > it could be a lengthy paragraph with html
            > formatting,
            > maybe even a table with a little chart or
            > something";
            > // add anything else for dogs here
            > break;
            > }
            > default:
            > {
            > $descrip = "<H1>No picture selected!</H1>
            > Please go back and make another selection.";
            > break;
            > }
            > }
            > ?>
            >
            > <HTML>
            > <title> <?php echo $pagetitle; ?> </title>
            > <body>Welcome to my Picture page<br>
            > here is the picture:
            > <img src="<?php echo $picture; ?>" >
            > here is where it was taken: <?php echo $descrip; ?>
            > <etc, etc>
            >
            > ---
            > Norman[/color]

            ok, thanks people. i decided to do a combo, sorta, of the ideas here.
            using my url string to do most of the work, as described above. also,
            decided to number my pictures to make the prev/next thing easier. and i put
            the long descriptions in includes, along with a js command to insert the
            page titles.

            the template page: (both the thumbnails and detail pages): pictures.php?th =1
            (1-20 or so)

            <?PHP
            switch ($th)
            {
            case NULL:{
            $imageinclude = "thumbs.php ";
            $textinclude = "thumbtext.php" ;
            break;}
            default:{
            $imageinclude = "notthumbs.php" ;
            $textinclude = $th.'.php';
            break;}
            }
            $myIncludePath = "includers/" ;

            ?>
            <body>
            here is the picture: <?php include ($myIncludePath .$imageinclude) ;?>
            here is the description ?php include ($myIncludePath .$textinclude) ;?>

            the thumbs.php has a big table of thumbnails, thumbtext.php just has the js
            title maker. $th.'php' are all the descriptions. i'm just gonna have a
            bunch of them.

            now ive got to figure out the next/prev buttons.
            $prev = $th-1
            $next=$th+1
            if $prev < 1{$prev = 20}
            if $next > 20 {$next=1}
            or something to that effect.

            i guess i could automate the links from the thumbnails, too. use a FOR
            statement or something? they all have rollovers, so i guess it could get
            messy,

            --
            thanks
            juglesh


            Comment

            • athakur@gmail.com

              #7
              Re: too much if() and stuff at top of page? - or is there a more efficient way?

              juglesh wrote:[color=blue]
              > ok, thanks people. i decided to do a combo, sorta, of the ideas[/color]
              here.[color=blue]
              > using my url string to do most of the work, as described above.[/color]
              also,[color=blue]
              > decided to number my pictures to make the prev/next thing easier.[/color]
              and i put[color=blue]
              > the long descriptions in includes, along with a js command to insert[/color]
              the[color=blue]
              > page titles.[/color]

              You may want to do some some filtering on '$th', otherwise I could
              instruct PHP to include any arbitary PHP script I want to by passing in
              a '$th' value such as "../../someotherdir/someotherfile". I don't know
              how much harm an attacker could do using something like this but it's
              something to keep in mind.

              Comment

              Working...