Jul 24, 2008

Include And Values

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Include And Values

drwael
hi everybody,
i am new to php programming,
i have this code in page number 1:
CODE

<?php
    $pages = array(
                'number1' => 'number1.php',
    'number2' => 'number2.php',
    'number3' => 'number3.php',
                'number4' => 'number4.php',
        );
            if (isset($_GET['page']) && isset($pages[$_GET['page']]))
                {
                    include($pages[$_GET['page']]);
                    } else {
                        include($pages['number1']);
                }
?>


but i dont want to have 4 pages called number1, number2, number3, number4

i wanna have just 1 page that have a code like this:

CODE

<?php
$number1 = "<img src=\"images/number1.gif\" width=\"57\" height=\"171\" alt=\"\">";
$number2 = "<img src=\"images/number2.gif\" width=\"57\" height=\"171\" alt=\"\">";
$number3 = "<img src=\"images/number3.gif\" width=\"57\" height=\"171\" alt=\"\">";
$number4 = "<img src=\"images/number4.gif\" width=\"57\" height=\"171\" alt=\"\">";
?>


so how can i include that second page through the first code?

thanks for your time

 

 

 


Reply

jlhaslip
Have a look here at the w3school site. They have a basic introduction to php coding and the syntax for php language. You may be able to find what you need on that site.
I don't quite follow exactly what it is you are trying to do using the code example you posted. Perhaps if you explained it a little better using words instead of the code, someone might be able to assist you. In the meantime, read up on the include function at the site I added above.

Reply

shadowx
Hi there, like jlhaslip im not entirely sure what youre after but ill take a shot and hpefully i can help abit.
i think i get what you mean. for example with the image code you posted you want the imnage to change depending on what the user inputs? so you could have a link that goes to a page like www.site.com/page1.php?image=1 and image one would be loaded up, but if they clicked a link like www.site.com/page1.php?image=2 image two would be shown? right?

if so you could do what i have done on my website. First of all follow the link given to you and learn about the include function. it will make things easier to learn and understand. then you would need code something like:
(assuming that you use the url like www.site.com/page1.php?image=1)
CODE

//get the value in the url into a variable
$image = $_GET['image'];

//use include to put this file onto page1.php
include($image);


im not sure how well include handles images as ive only ever used it to include php and html files. but if you wanted to use this to load different content (eg like trap17.com does with index.php?act=something and load a different content depending on the act. EG act=post lets the php know its looking at a forum post.) then you would use the code above but add something to it like:

CODE

//get the value in the url into a variable
$image = $_GET['image'];

// add ".html" to filename
$html = ".html";
$image = "$image$html";
//now $image is something like 1.html

//use include to put this file onto page1.php
include($image);


so if 1.html was a picture gallery the user would see a picture gallery. And if 2.html was a contact form they would see the contact form.

for better explainations check the link given to you, i just hope this is easier to understand because i sometimes find php manuals and such like to be hard to understand.

 

 

 


Reply

electron
You can have everything in just one page.
Use an array the way you did in the case of the array you build of all the files.
So the array would look like this:

CODE
<?php
$number['number1'] = "<img src=\"images/number1.gif\" width=\"57\" height=\"171\" alt=\"\">";
$number['number2'] = "<img src=\"images/number2.gif\" width=\"57\" height=\"171\" alt=\"\">";
$number['number3'] = "<img src=\"images/number3.gif\" width=\"57\" height=\"171\" alt=\"\">";
$number['number4'] = "<img src=\"images/number4.gif\" width=\"57\" height=\"171\" alt=\"\">";
?>


Now just use you if condition and call the Variable you got.
That was easy and you dont need to include a file for that.
However if you wanted to include then first include and then use array.

Hope that helps

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : include, values

  1. Domain Constants --- A, Mx, Ns & Cname Values
    What should I input for A, MX, NS & CNAME Values at Domain Registr (2)
  2. Php Allow Url Include Question!
    Need an admin to clarify something... (10)
    Hi, i've just signed up to your hosting over the last few days, and its been very fustrating
    that you don't allow the directive: allow_url_include. Do you think that there could be anyway
    that you could turn it on? i've installed a login and hit counter script and i had to edit half
    of it. I also want to 'include' my page list on all of my pages, to make it easier to
    update them, but the only way i would be able to do this is upload a page list to every directory,
    which defeates the purpose. And i can't use SSI because i can't use PHP with ....
  3. Php - Forms, Date And Include
    Working with POST and GET and also the Date() function (0)
    /--------PHP FORMS, DATE AND INCLUDE TUTORIAL BY FLASHY--------\ Hi and welcome to my
    tutorial. I will show you how to make simple PHP forms with the POST and GET statements. I will
    also show show you the Date() function too, aswell as the include() function. OK, so first you need
    a good understanding of HTML, and you need to create your form using that. So lets start off with
    the HTML form. 1. Create a page called form.html. 2. Insert your standard tags like: CODE
    <html> <head> <title>Working with php forms.</title> </he....
  4. Question About Php Includes
    How would you include a frame AROUND the page? (17)
    I'm trying to make a layout for my website for the areas that aren't occupied by Wordpress,
    and I want to use PHP includes to do it. So far, I know how to use tags, like this: CODE
    <table> <?php include "sidebar.php" ?> </table> This is okay,
    but I want to be able to include everything in one "container" file. Kind of like this: For every
    HTML file that I include: CODE <html> <head> <?php include
    "frame.php" ?> <title></title> </head> <body> <!....
  5. How Do I Include A Php Sidebar In My Website?
    This is a question about PHP... (5)
    (If I am posting this in the wrong forum, please tell me the correct place to be putting it.) I
    want to install a global announcement banner on the top my website, in case there is some major
    update. I am currently learning PHP for this very purpose, and would like to ask how it is made. (I
    know how the HTML layout is going to look like, I just want to be able to actually include the PHP
    portion on the website.) I heard it had something to do with includes in PHP... how exactly does
    this work?....
  6. Does Php Include Work?
    not for me aparantly... ? (17)
    So I joined this hosting because of the promoted "no limits" because ALOT of other servers don't
    allow the use of the PHP fnction include, which is something I'm DEARLY FOND OF; when I posted
    my pages on my newly hosted site ( bselvar.trap17.com ) I find that my includes for a ?page= style
    simple navigation doesn't work. Doesn't that mean there ARE restrictions? and is there a way
    to enable this?....
  7. Hosting Account Should Include Wysiwyg Editor
    Hosting account should include wysiwyg editor (7)
    I think Most of people looking to build a website don't know html or php therefore I think
    trap17 should include a wysiwyg editor with functions like drag and drop features. /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> It will be a great benefit
    to trap17 hosted members if it has some predefined templates for various categories.I myself is
    facing difficulties as I don't Know Html and I know there are other visual editors.But I think
    An Wysiwyg editor integrated with trap17 would do good to the newbies who have just put thei....
  8. Harry Potter: The Deathly Hallows
    WARNING: MAY INCLUDE SPOILERS! ONLY READ IF YOU HAVE READ THE WHOL (18)
    I was wondering, can this be a discussion for the seventh and final book of the Harry Potter
    series? Because I really want to talk about it. Great book! Do you think that the ending is a
    bit.. predictable? I mean, it was kind of obvious (to me) that Hermione and Ron would
    eventually.. Marry each other? As with Harry and Ginny. But I like Harry's kid the best, the one
    that looks like him. Albus Severus, right? Or was it Albus Snape? Hmm.. I remember it was Albus
    _______.. ....
  9. Php An Js Window.open Pages Trouble.
    I need a way to set hidden input values to the new window. (3)
    I have 2 main pages Page A(events_locked.php) and Page B(add_attendance.php). Both are php files.
    Page A takes a post var from another page(not Page B ) and then used to query for displaying records
    in a mysql datase. This variable has set as a session variable because there is 1 <script
    LANGUAGE="JavaScript"> window.name="main_index"; function openFormWindow() {
    OpenWindow=window.open("add_attendance.php", "newwin", "height=250,
    width=400,toolbar=no,scrollbars=no,menubar=no,location=no,resizable=no"); var x =
    getElementByName("form1"); x.target="newwin"; x.s....
  10. Php Include Problem [resolved]
    (4)
    Can someone help me out i am having a problem with one of my pages i am trying to use the include
    code for my navigation and top links. Here is the page
    http://www.neoevolution.net/neo_guides/Kadoatie.php Php Code-All my include code have this path
    way just with diffrent names. I tried putting the path ways like /home/phpinclude/filename but that
    did not work. I have searched for a lot of tutorials but i have tried all and they have not helped.
    So can anyone help me out? CODE <?PHP       include($DOCUMENT_ROOT .
    "/phpincludes/top_link_1.php"&....
  11. Text Image Java Problem
    How to include text and image in some scrollable container? (1)
    Hello everyone, I am just writing some kind of text editor as practice for some school project and I
    have come to certain point where I can not solve certain problem. I wanted to make it available
    for people to insert images but I cannot figure how to combine images and text and which container
    should I use. I am working in Java and using swing. Also I would like to say that this content
    should be scrollable. So if anyone knows something about this and could be able to help me thanks in
    advance. Everyone opinion is accepted.....
  12. Php Include Troubles
    (6)
    My PHP include scripts were working fine for a long time until one day they simply decided to give
    me errors that I can't seem to fix. I deleted the original homepage because of this and because
    it was time for a new layout anyways. I'm still having trouble, however. The site is set up so
    that the index page is the only page with formatting. This is the page that provides the layout. The
    content pages of the site are accessible through hyperlinks, which are clicked to include the
    content on the index page. In the area of index.php where I want to include the co....
  13. Passing Values By Get
    (16)
    I have problem I've been doing some programming in php that is something similar to registration
    but whenever I want to check something it seems like variables are not passed or that the php
    variables are empty I am using get instead of post however I am also considering to switch to post
    as I cannot find an error. Anyone had similar experience that he could help me? Thanks in advance.....
  14. [php](simple) Using Functions To Combine Values In A Form
    Really simple example on how to combine values with function (2)
    I just learned this simple method on how to use functions to combine two values from a form. First
    we create ourselves a simple POST form CODE <form method="POST"> Name:
    <input type="text" name="nickname"> Location: <input
    type="text" name="location"> <input type="submit"
    value="Input"> </form> Now we add this php to that same file CODE
    <?php $nick = $_POST['nickname']; $location =
    $_POST['location' ....
  15. Include() Statements
    (4)
    If I include a PHP file from another web server, will it return the output of the PHP file, or the
    actual contents of the PHP file? My guess is the first one, but can anyone confirm this? Thanks.....
  16. Getting Values From A Form
    (2)
    Alright I have created the form and the validation was done using a for-loop. What I need to know
    is how to bring it to an processing page which is an .asp format so I can effectively add it to a
    database. I have created several forms through javascript as well. Would appreciate it if I could
    get some assistance. Can anyone suggest to me how I can do it?....
  17. Help With Assigning Values To Form Options?
    (6)
    Hey, Let me try to do my best to explain this... I have a business website that specializes in
    building custom computers. Customers can use our online form to select components for their computer
    from various categories (Hard drive size, processor, memory, ect..) Take a look at the page here:
    www.plugcomputers.com/amdschedule.php As you can see there are many radio buttons with different
    computer part choices. I wanted to add some way to assign a dollar value to each different part, so
    the customer knows how much its costing them with each upgrade. If you scroll to t....
  18. Topic View Changed To Include Custom Fields
    custom fields enabled (3)
    When you read a topic next time, notice the new profile information under a member's avatar. It
    will show as: Member name Profile title Group icon Group: Posts: Joined: From: Member No.: T17
    GFX Crew (or Spam Patrol) This new custom field was added to the topic view to enhance the
    awareness of T17 GFX Crew. For moderators and administrators we will be able to see hosted
    member's cPanel username as well. No other members can see this value, not even their own. This
    can cut down crucial delay time when members are request for hosting support. Instead of "what....
  19. Where Is Include Path?!
    help plz urgent (5)
    hi i used this path: (include_path='.:/usr/lib/php:/usr/local/lib/php' as include path!
    but it does not work! please help me! where is the include path of ur free hosting?....
  20. Converting Characters In A Variable To Individual Values In An Array
    turning variables into arrays (2)
    Say I have a variable such as $nav_item and it had to contents Home . IE: CODE
    $nav_item = 'Home'; How would I make so that $nav_item was an array and
    had the following contents? CODE $nav_item = array ('h', 'o',
    'm', 'e'); With the case changing (ie H would become h and U
    would become u ) EDIT: Okay found out that I could change the case with
    array_change_key_case ($nav_item, CASE_LOWER); ....
  21. Include Funtion Php Problems
    in xammp and php 5.1.1 (11)
    Hi, I just recently installed the latest versin of XAMMP on my computer which comes with php5.1.1
    and i have been noticing some problems with the include(); funtion. This is a code that worked
    fine on trap17 hosting so I am thinking it has something to do with the php version of 5.1.1 since
    trap17 uses 4.3.X. Now what the actual problem is is using the variables in the include function.
    If i have a normal include sentence like this one: CODE include "hello.php"; then it
    works fine but as soon as i start using variables it somehow dosent work at all. ....
  22. Would A New Tech Include A Game Engine?
    (2)
    well i wa sjust wondering because i make game engines for free and for friends and wondering if i
    could help people if they can help me out. Just a simple thing realy, if your into playing games or
    just someone who can sprite just for fun feel free to contact me at bender07777@hotmail.com
    everything is free from me. (cool it rhymed)....
  23. How To? Include Website In Search Engine..
    ??? (3)
    what should i do? nothing to say.. Trap17 forum asks you to post contributes with quality, not
    quantity. ....
  24. Include File.php?id=something
    using the include() function (13)
    Well, I am making a full CMS system for my site, and want to make the index.php file to include the
    view.php?id=1 file. I tried with this code, but it didn't work: CODE <?php include
    'view.php?id=1' ?> This is the error I get: CODE Warning:
    main(view.php?id=1) [function.main]: failed to open stream: Invalid argument
    in C:\server\xampp\htdocs\test\index.php on line 1 Warning:
    main() [function.include]: Failed opening 'view.php?id=1' for inclusion
    (i....
  25. Is Ssi Available ?
    Server Side Include (5)
    Aw right, I haven't been making an extensive search about that on the other topics or on the
    site's management tools /mad.gif' border='0' style='vertical-align:middle' alt='mad.gif' />
    , and I might be the umpteenth guy to ask. Is there a possibility to get SSI (Server Side Include)
    on a trap17 user domain, be it upon request? It is not NOT absolutely required for me, but it could
    come in handy, if it were available /laugh.gif' border='0' style='vertical-align:middle'
    alt='laugh.gif' /> . Thanks in advance.....
  26. Php Include Root Ref
    whats the root? (6)
    Every one knows that we can include files in our site, so we have a folder with 2 files, an
    index.php with a menu.php included. But they are on the same folder, what if we wanted to make a
    relative reference for it, so we will always put include("/files/menu.php") and it will always work
    wherever that file is (the file calling the include). Ive had troubles with this, as it doesnt seem
    to be working, i have to change to the dot notation (like ../../../../../files/menu.php) in order to
    keep my includes right. Does any one know what the root is for the include or how can ....
  27. Loading Some Of The Title From The Include Tag
    (2)
    Let's say I have the same PHP script on all pages, with the same menus, footer etc, but with
    different content. The PHP page is called "Sitename - ", and the included pages (which is in HTML)
    is called "Thingy". I want it to load both titles, so the title will be "Sitename - Thingy". The
    second page have the same PHP code (with the normal title, "Sitename - "), but is called "Why not?".
    This one have the title "Sitename - Why not?". Hope you understand what I want, and that you can
    help me. /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> ....
  28. Changing Include Tag On All Pages
    (11)
    I want to change an include tag (include menu.htm) to include menu.php on all my pages on my
    website. Is there any fast way to do this, or do I have to edit all of my pages manually?
    /unsure.gif' border='0' style='vertical-align:middle' alt='unsure.gif' /> ....
  29. Sprites Full Sig Tutorial V2
    how to make a full sig...brushes include (15)
    IF YOU LIKED THIS TUTORIAL PLEASE REGISTER ->HERE In this tutorial you will be creating a
    signature similiar to this: Part 1: Part 2: Part Two: Enjoy! I DID NOT MAKE THE
    BRUSHES I USED, THEY CAN BE FOUND HERE: http://totalwarmu.com/~krazy/sparkleps7.abr and...
    http://www.deviantart.com/view/18564160/ ....
  30. Php And Flash Movie Ie Problem
    php include problem (2)
    I'm working on a site right now and everything's working fine. I had all the links and
    includes working but when i check the site in ie i found that the small flash movie which is part of
    the header and is included in the top php, isn't loading. Anyone here ever had that problem. I
    don't remember ever myself but i really need this stupid thing fixed. round ....

    1. Looking for include, values

Searching Video's for include, values
Similar
Domain
Constants
--- A, Mx,
Ns &
Cname Values
- What
should I
input for A,
MX, NS &
CNAME Values
at Domain
Registr
Php Allow
Url Include
Question!
; - Need an
admin to
clarify
something...
Php - Forms,
Date And
Include -
Working with
POST and GET
and also the
Date()
function
Question
About Php
Includes -
How would
you include
a frame
AROUND the
page?
How Do I
Include A
Php Sidebar
In My
Website? -
This is a
question
about PHP...
Does Php
Include
Work? - not
for me
aparantly...
?
Hosting
Account
Should
Include
Wysiwyg
Editor -
Hosting
account
should
include
wysiwyg
editor
Harry
Potter: The
Deathly
Hallows -
WARNING: MAY
INCLUDE
SPOILERS!
; ONLY READ
IF YOU HAVE
READ THE
WHOL
Php An Js
Window.open
Pages
Trouble. - I
need a way
to set
hidden input
values to
the new
window.
Php Include
Problem
[resolved]
Text Image
Java Problem
- How to
include text
and image in
some
scrollable
container?
Php Include
Troubles
Passing
Values By
Get
[php](simple
) Using
Functions To
Combine
Values In A
Form -
Really
simple
example on
how to
combine
values with
function
Include()
Statements
Getting
Values From
A Form
Help With
Assigning
Values To
Form
Options?
Topic View
Changed To
Include
Custom
Fields -
custom
fields
enabled
Where Is
Include
Path?! -
help plz
urgent
Converting
Characters
In A
Variable To
Individual
Values In An
Array -
turning
variables
into arrays
Include
Funtion Php
Problems -
in xammp and
php 5.1.1
Would A New
Tech Include
A Game
Engine?
How To?
Include
Website In
Search
Engine.. -
???
Include
File.php?id=
something -
using the
include()
function
Is Ssi
Available ?
- Server
Side Include
Php Include
Root Ref -
whats the
root?
Loading Some
Of The Title
From The
Include Tag
Changing
Include Tag
On All Pages
Sprites Full
Sig Tutorial
V2 - how to
make a full
sig...brushe
s include
Php And
Flash Movie
Ie Problem -
php include
problem
advertisement



Include And Values



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE