#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Posts
    12
    Rep Power
    0

    Use one php page to display data depending which link is clicked on


    Hi,

    Instead of creating page1, page2, page3, page4 .... create one page instead of page1, page2, page3, page4. In other words, say I have 4 images that are linked to a details page. The details page displays the image plus details about the image.

    How can I build one page to display different content depending one which image is clicked on? Is there a way to do this?

    I've looked for tutorials but can't find one describing how to do this. Can someone provide a tutorial or provide the best secure way to do this?
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,074
    Rep Power
    9398
    You might not be finding tutorials because it's such a core concept to PHP that you learn it implicitly by simply using PHP.

    Let's start from the beginning: URLs. What URLs do you want to use for these images (or whatever)? Do you want them to look like regular files but come from a PHP script instead, such as /image-1.jpg? Maybe the URLs have something to do with the details page, like /details-image.php?image=1. Do you want something that's not obviously a PHP page, like /details/image/1?
    I suggest you choose something simple. Something you recognize. You can learn the fancier stuff once you have the basic version working. That's particularly true for images where people don't really ever see the URLs so they don't really matter in the first place.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Location
    delhi,india
    Posts
    32
    Rep Power
    1
    hi,
    i am new to php and dont know if this is the correct way but you can do that by passing
    a string to the url
    <img> <a href = index.php/?id=img1></img>

    and check the value of id using isset function.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Sep 2006
    Posts
    2,015
    Rep Power
    535
    Originally Posted by chauhanRohit
    hi,
    i am new to php and dont know if this is the correct way but you can do that by passing
    a string to the url
    <img> <a href = index.php/?id=img1></img>

    and check the value of id using isset function.
    Before you get into PHP, learn a little more about HTML. Try Googling "html anchor link"

    Also, I often use print_r() when trying to understand whats going on. To make it display nicer, try echo('<pre>'.print_r($_GET,1).'</pre>');
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Location
    delhi,india
    Posts
    32
    Rep Power
    1
    sorry for that there are no edit buttons here , this will work.
    <a href="default.php/?id=img1"><img></a>
    <a href="default.php/?id=img2"><img></a>
    check using isset the value of id passed.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,990
    Rep Power
    375
    whats with the default.php/?id=1 it should be default.php?id=1...
  12. #7
  13. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,549
    Rep Power
    2337
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,990
    Rep Power
    375
    the OP looks like a newbie.. I doubt he would have heard of this.. anyways if it was some kind of pattern it would have been: url/param1/value1/ etc..

    usually if you send index.php some params you could do: url.com/?param=1 since default file is index.php..
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Posts
    12
    Rep Power
    0
    I guess I'm not explaining well enough.

    Basically this is a page with square images - 5 columns and 5 rows = 25 total images. The whole idea is to display the details of the image you clicked on on the details.php page.

    Instead of creating 25 pages with details of each image -

    Is it possible to create one php page which changes the data depending on which image is clicked on?

    So it would be something like this - This is not the correct php or html. I'm trying to explain what I need.

    The image page - <a href="the-details-page.php?this-image......."><img src=''"></a>

    The details page -

    <?php
    print "title for all images"; Meaning - it will be one title depending which image was clicked on previously. Do not take images with an S the wrong way. It wont be ALL titles when one image is clicked on.
    print "the description for all descriptions"; Meaning - it will be one description depending which image was clicked on previously. Do not take descriptions with an S the wrong way. It wont be ALL descriptions when one image is clicked on
    ?>

    If this can be done what's the best solution?

    ** Remember display the data on one page after one image is clicked on for that image. Instead of creating 25 pages for each image .

    How can I -

    1. Pass the data about the image in the URL - if that's ok to do
    2. After an image is clicked on, display the title on the details page
    3. After an image is clicked on, display the description on the details page
    For the image you clicked on.

    Again talking about one details.php page. Instead of creating details1.php, details2.php, details3.php... etc etc.

    I guess I'm not explaining well enough.

    Basically this is a page with square images - 5 columns and 5 rows = 25 total images. The whole idea is to display the details of the image you clicked on on the details.php page.

    Instead of creating 25 pages with details of each image -

    Is it possible to create one php page which changes the data depending on which image is clicked on?

    So it would be something like this - This is not the correct php or html. I'm trying to explain what I need.

    The image page - <a href="the-details-page.php?this-image......."><img src=''"></a>

    The details page -

    <?php
    print "title for all images"; Meaning - it will be one title depending which image was clicked on previously. Do not take images with an S the wrong way. It wont be ALL titles when one image is clicked on.
    print "the description for all descriptions"; Meaning - it will be one description depending which image was clicked on previously. Do not take descriptions with an S the wrong way. It wont be ALL descriptions when one image is clicked on
    ?>

    If this can be done what's the best solution?

    ** Remember display the data on one page after one image is clicked on for that image. Instead of creating 25 pages for each image .

    How can I -

    1. Pass the data about the image in the URL - if that's ok to do
    2. After an image is clicked on, display the title on the details page
    3. After an image is clicked on, display the description on the details page
    For the image you clicked on.

    Again talking about one details.php page. Instead of creating details1.php, details2.php, details3.php... etc etc.

    I guess I'm not explaining well enough.

    Basically this is a page with square images - 5 columns and 5 rows = 25 total images. The whole idea is to display the details of the image you clicked on on the details.php page.

    Instead of creating 25 pages with details of each image -

    Is it possible to create one php page which changes the data depending on which image is clicked on?

    So it would be something like this - This is not the correct php or html. I'm trying to explain what I need.

    The image page - <a href="the-details-page.php?this-image......."><img src=''"></a>

    The details page -

    <?php
    print "title for all images"; Meaning - it will be one title depending which image was clicked on previously. Do not take images with an S the wrong way. It wont be ALL titles when one image is clicked on.
    print "the description for all descriptions"; Meaning - it will be one description depending which image was clicked on previously. Do not take descriptions with an S the wrong way. It wont be ALL descriptions when one image is clicked on
    ?>

    If this can be done what's the best solution?

    ** Remember display the data on one page after one image is clicked on for that image. Instead of creating 25 pages for each image .

    How can I -

    1. Pass the data about the image in the URL - if that's ok to do
    2. After an image is clicked on, display the title on the details page
    3. After an image is clicked on, display the description on the details page
    For the image you clicked on.

    Again talking about one details.php page. Instead of creating details1.php, details2.php, details3.php... etc etc.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,990
    Rep Power
    375
    No i think we all understand, as requinix has said this is a core PHP (programming concept)

    1. display all images.. each image has a href of "somefile.php?id=image_id
    2. on somefile.php? you check if id exists if it does get details from database
    3. display the details in a nice way.
  20. #11
  21. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    Paul is right, the tutorial for this operation is "this is exactly why server-side languages exist, learn one."

    Also, ALWAYS try to write correct code, even in examples. if you say "this is kinda what I want but I know it's not right, follow along anyway" people will be less likely to help you and you will be less likely to do things properly down the road. The example code you provided was wrong, and you expressed that you knew nothing about PHP. Since you provided incorrect HTML as well, the natural response was "finish learning HTML first." We can't figure out what your skill level is if you're purposely using incorrect code, or not caring if your code is correct. This is computer code, not a text message. It must be precise if anyone (especially a computer) is going to be able to make anything out of it.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2012
    Posts
    12
    Rep Power
    0
    I'm having a bad day and want to take out my frustration on everybody I see.

    __

    I figured it out by calling each item in the URL and displaying it on the details page. Actually its very simple.

    I thought it would be harder to use one details page to call the items needed to display the results.
    Last edited by requinix; June 5th, 2014 at 09:18 PM.
  24. #13
  25. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,074
    Rep Power
    9398
    Originally Posted by patmon
    I'm having a bad day and want to take out my frustration on everybody I see.
    There. I like that version much better than what you had before
  26. #14
  27. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    It appears that the random interjection of chauhanRohit's terrible code is what caused people to misunderstand OP's actual request.

    OP's absolutely unacceptable series of insults notwithstanding, we do owe OP an apology for getting them confused. The answer remains "this is what PHP was designed to do," however. When OP comes back, if he/she can be civil, maybe they can describe the actual problem concisely.

    If you click on a URL that looks like this:
    imagedetail.php?id=123

    Then inside imagedetail.php there will be what PHP calls a "magical super-global" array called $_GET. $_GET will be an array of all the variables included in the URL. Therefore, imagedetail.php will be able to access $_GET['id'] to retrieve the value of "123". That value can then be used in a (properly sanitized and secured) database query for retrieving the relevant data.

    For any more discussion, please open a new thread after reading the new user guide.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo