SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Member
    Join Date
    Jul 2006
    Location
    Florida
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation HELP PLEASE - Echo Values of Multi-Dimensional Array Based on ID

    I have 1 array with 2 dimensions which is hard coded on my page.

    THIS CODE WOULD BE ON REDIRECT.PHP
    PHP Code:

    $aff 
    = array(0=>array('title'='A Website Title','afurl'='http://www.external-affiliate-site.html?affiliateid=1234'),1=>array('title'='Another Website Title','afurl'='http://www.external-site-training-your-pitbull-made-easy.html?affiliateid=1234')); 

    I have a link on my website which when it is clicked goes to redirect.php. I need to get both Values from my Array which match up with an ID that is passed to my page via PHP GET.


    Code:
    http://www.link-on-my-site.com/redirect.php?myid=0
    Once the variable "myid" is passed to redirect.php, I will capture it on redirect.php.

    PHP Code:
    $affiliate $_GET['site']; 
    This is where I get stuck.
    From here I need to get both values "afurl" and "title" from the array and set each one of the values to an individual variable so I can print them.

    PLEASE PLEASE HELP....

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Uhm,

    Code php:
    $id=(int)$_GET['myid'];
     
    $site=$aff[$id]['title'];
    $url=$aff[$id]['afurl'];
    Saul

  3. #3
    SitePoint Member
    Join Date
    Jul 2006
    Location
    Florida
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Take it easy genius - some of us might be newbies...

    But thanks.

    I shall test this out.

  4. #4
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Sorry about that, it's my natural behavior
    Saul

  5. #5
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <pre>
    <?php
    $aff 
    = array(=> array('title' => 'A Website Title''afurl' => 'http://www.external-affiliate-site.html?affiliateid=1234'), 
    => array('title' => 'Another Website Title''afurl' => 'http://www.external-site-training-your-pitbull-made-easy.html?affiliateid=1234'));

    print_r($aff);

    $id=(int)$_GET['myid'];
     
    $site=$aff[$id]['title'];
    $url=$aff[$id]['afurl'];

    ?>
    <a href="<?php echo $url ?>"><?php echo $site ?></a>
    Code:
    Array
    (
        [0] => Array
            (
                [title] => A Website Title
                [afurl] => http://www.external-affiliate-site.html?affiliateid=1234
            )
    
        [1] => Array
            (
                [title] => Another Website Title
                [afurl] => http://www.external-site-training-your-pitbull-made-easy.html?affiliateid=1234
            )
    
    )
    my mobile portal
    ghiris.ro

  6. #6
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View Post
    Sorry about that, it's my natural behavior
    my mobile portal
    ghiris.ro

  7. #7
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Actually, we should carry it a bit further, to make things nice and clean:
    Code php:
    $id=(int)$_GET['myid'];
     
    if(array_key_exists($id,$aff)){
      $site=$aff[$id]['title'];
      $url=$aff[$id]['afurl'];
    }else{
      echo 'Affiliate not found!';
    }
    Saul

  8. #8
    SitePoint Member
    Join Date
    Jul 2006
    Location
    Florida
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK I know this is USER ERROR on my part... but i think i have a syntax error in my ARRAY..

    PHP Code:
    <?php

    $id
    =(int)$_GET['myid']; 

    $aff = array(0=>array('title'='A Website Title','afurl'=>'http://www.someaffiliate9.html?affiliateid=1234'),1=>array('title'='Another Website Title','afurl'=>'http://www.training-your-pitbull-made-easy.html?affiliateid=1234'));

    $site=$aff[$id]['title'];
    $url=$aff[$id]['afurl'];

    echo 
    $site 

    echo $url

    ?>
    I get the following error when i test this page.

    Parse error: syntax error, unexpected '=', expecting ')' in /home/7252/domains/hoosiermate.com/html/index.php on line 5

  9. #9
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    see post # 5
    my mobile portal
    ghiris.ro

  10. #10
    SitePoint Member
    Join Date
    Jul 2006
    Location
    Florida
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile



    MANY THANKS to Ernie1 and php_daemon for your help with this BIG problem for my NEWBIE self.

    You guys are Awesome!!

    Thanks again!

  11. #11
    SitePoint Member
    Join Date
    Jul 2006
    Location
    Florida
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ready for part 2

    Here is the situation...at some point the array is going to get large. And hard to read on the page.

    Part 1: Can the array be formatted in my php with line breaks or something to help it read better?

    Part 2: This array has the potential to be very large. At what point should I begin to worry about performance on this page with the size of my array?

    Thanks again!

  12. #12
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    1) Yes

    2) You should start worrying now. Consider using database.
    Saul

  13. #13
    SitePoint Member
    Join Date
    Jul 2006
    Location
    Florida
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1) can you provide an example?

    2) that is what i was afraid of :-(

  14. #14
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    1)
    Code php:
    $aff = array(
    0 => array( 'title' => 'A Website Title', 
                'afurl' => 'http://www.external-affiliate-site.html?affiliateid=1234' 
               ), 
     
    1 => array( 'title' => 'Another Website Title', 
                'afurl' => 'http://www.external-site-training-your-pitbull-made-easy.html?affiliateid=1234'
               )
    );

    2) It's not that hard as may seem. And worth learning anytime. You can start at http://www.php.net/mysql and/or look up SitePoint's articles.
    Saul

  15. #15
    SitePoint Member
    Join Date
    Jul 2006
    Location
    Florida
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks again.

    i am reading up now. I am sure I will have questions


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •