SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    make a link from an array variable

    Hello everybody,
    anyone can help me with this problem?
    instead of just display the child (in array)..echo $Valuechild[$i]."; ";
    (see the below code)..I would like to make a link from $Valuechild[$i] to a details of that variable..

    here is the full code


    Code PHP:
    <TEXTAREA NAME="comments3" style='width:50%' rows='4'>
          <?php
            for ($i =0; $i < $ValuenumtableChildren; $i++)
     
          {
     
          echo '<a href="viewingdetails.php?name='.$Valuechild[$i].'</a>';
     
          }
          ?>
     
          </TEXTAREA>

    hope someone can help me..I have tried so many ways to do this..
    many thanks.

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Not sure what you are after here, but if you want that to be a correctly formatted html link change it to this:
    PHP Code:
    echo '<a href="viewingdetails.php?name=' 
              
    $Valuechild[$i] . '">' $Valuechild[$i
              . 
    '</a>' PHP_EOL
    I split the line to help improve readability, I hope.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi, thanks for your help..
    But it appears like this.

    <a href="viewingdetails.php?name=Matter in Nature">Matter in Nature</a>

    it seems that a href does not work here..not translated to html format..
    What I wanted to do is to make a link from Matter in Nature..or whatever childs it is to a detail page..I have tried several syantax but it still appear like the above result.

    Any other suggestion please?
    thanks

  4. #4
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you give us an example of the link you want to produce? The code you posted implies you want to produce a link as per Cups' post.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    I think what did he meant is similar to me..
    to make a link from a variable $Valuechild[$i] .
    the problem is that the output is not as what expected..
    It should be like this
    Matter in Nature

    however the output displayed is like this..

    <a href="viewingdetails.php?name=Matter in Nature">Matter in Nature</a>.
    href is appear in the output..it should be a link , shouldn't it?

    many thanks for your help

  6. #6
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb

    I think you must use urlencode( $Valuechild[$i] );

    is that what you want?
    eYeew! Founder and Developer

    Madipta

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pipisdicelana View Post
    I think you must use urlencode( $Valuechild[$i] );

    is that what you want?
    hi..is it like thisecho '<a href="viewingdetails.php?name='urlencode (.$Valuechild[$i].)' ">' </a>';

    I have tried this and there is an error on that line..syntax error .

    any suggestion?
    thanks

  8. #8
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Your problem is that you are trying to have a link inside a textarea.

    Bottom line is that textareas are for editing, so HTML isn't rendered inside them.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  9. #9
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your problem is that you are trying to have a link inside a textarea.
    ic..ok thanks..

    Bottom line is that textareas are for editing, so HTML isn't rendered inside them.
    so, what should I do now.. I do not have an idea about it..
    thank you

  10. #10
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Well, why do you want to put a link inside a control designed for user-input anyway?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  11. #11
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
    echo '<a href="viewingdetails.php?name=' 
              
    urlencode$Valuechild[$i] ) . '">' $Valuechild[$i
              . 
    '</a>' PHP_EOL
    Some of the problems you are encountering are to do with basic HTML.

    e.g. $Valuechild[1] clearly contain spaces, browsers will do odd things with that, as explained, links inside a textarea may not display exactly as you expect etc.

    We all had to learn this stuff the hard way.

    You might benefit a lot from first of all creating your 'page' in basic HTML and get your forms working as you expect. Then slowly get PHP to generate that page for you.

  12. #12
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    Well, why do you want to put a link inside a control designed for user-input anyway?
    ok..it is not a user input actually..
    when user key-in a keyword ( in differenet page)..any related term to that keyword will appear as a child value here..
    then.. if users click the child value..(in this case: Matter in Nature)..all records that contains that term will be displayed in a detail page..

    hope someone can helps
    thanks

  13. #13
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You are using the wrong element for this then.

    You should be using a <select size="..."> element, with the size being the number of items you want to show before scrolling.

    You then put each related term into an option element.

    So, for example, your code could be:
    PHP Code:
    <select size="6">
        <?php
        
    foreach(getRelatedKeywords($InputKeyword) as $Keyword){
            echo 
    "<option>{$Keyword}</option>";
        }
        
    ?>
    </select>
    If you want the form to submit right away, you'd use:

    PHP Code:
    <select size="6" onchange="form.submit()">
        <?php
        
    foreach(getRelatedKeywords($InputKeyword) as $Keyword){
            echo 
    "<option>{$Keyword}</option>";
        }
        
    ?>
    </select>
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  14. #14
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    still doesn't work.
    anyway, thanks all for your kind help, suggestions, comments and input

  15. #15
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HI arkinstall..Could you pease elaborate this in details..
    Really have to make it works.


    Quote Originally Posted by arkinstall View Post
    You are using the wrong element for this then.

    You should be using a <select size="..."> element, with the size being the number of items you want to show before scrolling.

    You then put each related term into an option element.

    So, for example, your code could be:
    PHP Code:
    <select size="6">
        <?php
        
    foreach(getRelatedKeywords($InputKeyword) as $Keyword){
            echo 
    "<option>{$Keyword}</option>";
        }
        
    ?>
    </select>
    the output that should be displayed here are variables in array. (can refer to my previous posts in this thread.
    COuld you please explain this?
    thank you.

  16. #16
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The function GetRelatedKeywords($InputKeyword) should be replaced with the array you get for grabbing the related keywords.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  17. #17
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is this what did you mean?
    PHP Code:
     <select size="2">
     
    <?php
    for ($i =0$i $ValuenumtableChildren$i++)
    {

        
        foreach(
    getRelatedKeywords($Valuechild[$i].) as $Keyword){
            echo 
    "<option>{$Keyword}</option>";
        }
        
    ?>    
    <?php
    }
    ?>    
    </select>
    I tried this as well
    PHP Code:
    <textarea name="comments3" style='width:50%' rows='4'>
    <?php
    for ($i =0$i $ValuenumtableChildren$i++)
    {
        foreach(
    getRelatedKeywords($Valuechild[$i].) as $Keyword){
            echo 
    "<option>{$Keyword}</option>";
        }
    ?>    
    <?php
    }
    ?>    
    </textarea>
    both do not work.
    really need your help.
    the ($Valuechild[$i].) are displayed correctly..just to make a link form it.

    thanks

  18. #18
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Ok, so to make it act like a link you'd need some JS to fire it:
    PHP Code:
    <form action="viewingdetails.php" method="get">
        <select size="2" name="name" onChange="form.submit();">
            <?php
                
    foreach($ValuenumtableChildren as $Keyword){
                    echo 
    "<option>{$Keyword}</option>";
                }
            
    ?>
        </select>
        <input type="submit" value="Go > " /> <!-- This is needed for those without JavaScript -->
    </form>
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  19. #19
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi..thanks for your input.
    I have tried it..but there is no value appear.
    the variable - $ValuenumtableChildren- is not read as keyword.

    the whole code is like this..thank you

    PHP Code:
    </p>
      <p>Children: </p>
     
    <p>    
    <form action="viewingdetails.php" method="get">
        <select size="6" name="name" onChange="form.submit();">
            <?php
                
    foreach($ValuenumtableChildren as $Keyword){
                    echo 
    "<option>{$Keyword}</option>";
                }
            
    ?>
        </select>
        <input type="submit" value="Go > " /> 
    </form>
    </p>


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
  •