473,383 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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 = "thePreviouspage.htm";
$next = "theNextpage.htm";
$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>{)}
Jul 17 '05 #1
6 1629
check out the switch

http://au2.php.net/manual/en/control...res.switch.php

do something like this
switch($picname)
case "birds":
$picture = "birds.jpg";
$pagetitle = "Here are Some Birds";
$prev = "thePreviouspage.htm";
$next = "theNextpage.htm";
$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" <ju*****@nospamRadioKDUG.com> wrote in message
news:RBvsd.136315$V41.34405@attbi_s52...
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 = "thePreviouspage.htm";
$next = "theNextpage.htm";
$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>{)}

Jul 17 '05 #2
juglesh wrote:
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?


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' => "thePreviouspage.htm",
'next' => "theNextpage.htm",
'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($assets[$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

Jul 17 '05 #3
jn
"juglesh" <ju*****@nospamRadioKDUG.com> wrote in message
news:RBvsd.136315$V41.34405@attbi_s52...
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 = "thePreviouspage.htm";
$next = "theNextpage.htm";
$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>{)}

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.

Jul 17 '05 #4
"juglesh" <ju*****@nospamRadioKDUG.com> wrote in message
news:RBvsd.136315$V41.34405@attbi_s52...
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 = "thePreviouspage.htm";
$next = "theNextpage.htm";
$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>{)}


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 = "thePreviouspage.htm";
$next = "theNextpage.htm";
$desc_heading = '<H1>'.ucfirst($picname).'</H1>';
$pagetitle = 'Here are some '.ucfirst($picname);
$picture = $picname.'.jpg';

switch ($picname)
{
case 'birds':
{
$descrip = "$desc_heading
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_heading
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
www.easyavatar.com
Jul 17 '05 #5

"Norman Peelman" <np******@cfl.rr.com> wrote in message
news:I9******************@tornado.tampabay.rr.com. ..
"juglesh" <ju*****@nospamRadioKDUG.com> wrote in message
news:RBvsd.136315$V41.34405@attbi_s52...
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 = "thePreviouspage.htm";
$next = "theNextpage.htm";
$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>{)}


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 = "thePreviouspage.htm";
$next = "theNextpage.htm";
$desc_heading = '<H1>'.ucfirst($picname).'</H1>';
$pagetitle = 'Here are some '.ucfirst($picname);
$picture = $picname.'.jpg';

switch ($picname)
{
case 'birds':
{
$descrip = "$desc_heading
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_heading
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


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
Jul 17 '05 #6
juglesh wrote:
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.


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.

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
124
by: 43 | last post by:
how come m$Office isn't written in .net? how come Open Office isn't written in j2ee? how come dbms systems aren't written in either? how come browsers aren't written in either? how come...
1
by: Paulos | last post by:
Hi Guys I am a bit of a nocice at some aspects of PL/SQL and I have to write some code in a function that checks if a row in a given table exists...something on the lines of : IF(...
8
by: abbylee26 | last post by:
User enters account number if another account number is needed User clicks add account which creates another row When validating when they hit submit I want to check to make sure they tell us...
16
by: RC | last post by:
I have some code that needs to know if an int variable is one of several possible values. What is a better way of performing the test than stacking a bunch of case: in a switch statement? I also...
1
by: Mutley | last post by:
Hi, I have written an HttpHandler to process page requests for a custom file extension. Other considerations aside which of the following 3 options is the most efficient or preferred method of...
5
by: Donald Adams | last post by:
Hi, I will have both web and win clients and would like to page my data. I could not find out how the datagrid control does it's paging though I did find some sample code that says they do it...
8
by: =?Utf-8?B?UmljaA==?= | last post by:
Is it possible to find the end of an If block in VB2005 -- similar to C# where in C# if you place your cursor next to a bracket and press ctrl something it highlights the ending bracket? I have...
14
by: =?Utf-8?B?R1ROMTcwNzc3?= | last post by:
Hi there, I'm trying to only show part of my page based on a variable, I have two Session Variables - Session("EMPLOYEEMAXUSERS") Session("EMPLOYERUSERS") Now what I'm trying to do is -
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.