Include And Values

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

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 : values

  1. Php An Js Window.open Pages Trouble. - I need a way to set hidden input values to the new window. (3)
  2. 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....
  3. [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' ...
  4. 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); ...



Looking for include, values

Searching Video's for include, values
advertisement



Include And Values



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free 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