Grabbing text and image

Discussion in 'PHP' started by assault14, Feb 21, 2011.

  1. #1
    I am working on a script and i ran into a little snag. I have 6 images, and they are named 1-6 i use the value from a radio button to determin witch image was selected. Now i am not sure how to do it so that i can have it grab the text that goes with the image. but have it be a diffrent variable... for example

    $pic = the image

    $text = the text

    here is my code

    <form action="send.php" id="testForm" method="post">
    
    <center>
          <font size="5" color="#3B5998" face="Comic Sans MS, cursive"> Select Expression</font> <br />
    <table width=100% cellpadding=2 cellspacing=2>
    <tr>
    <td>
    <P class=centerP><img src="/images/1.jpg" border="0" width="100" height="100"></P><P class=centerP><center><input type="radio" name="pic" CHECKED value="1"><font size="2" >Cheer Up</font></center></P>
    </td>
    <td>
    <P class=centerP><img src="images/2.jpg" border="0" width="100" height="100"></P><P class=centerP><center><input type="radio" name="pic" value="2"><font size="2">Chill Out</font></center></P>
    </td>
    <td>
    <P class=centerP><img src="images/3.jpg" border="0" width="100" height="100"></P><P class=centerP><center><input type="radio" name="pic" value="3"><font size="2">Slap</font></center></P>
    </td>
    <td>
    <P class=centerP><img src="images/4.jpg" border="0" width="100" height="100"></P><P class=centerP><center><input type="radio" name="pic" value="4"><font size="2">Back OFF</font></center></P>
    </td>
    <td>
    <P class=centerP><img src="images/5.jpg" border="0" width="100" height="100"></P><P class=centerP><center><input type="radio" name="pic"  value="5"><font size="2">Hug</font></center></P>
    </td>
    <td>
    <P class=centerP><img src="images/6.jpg" border="0" width="100" height="100"></P><P class=centerP><center><input type="radio" name="pic"  value="6"><font size="2">Love Hug</font></center></P>
    </td>
    </tr>
    </table>
    
    <br/><br />
          <font size="5" color="#9966CC" face="Comic Sans MS, cursive"> Select Someone to Express</font> <br />
    <br />
    
    <fb:friend-selector uid="$user" name="uid" idname="uid2"/>
    <input class="inputbutton" style="cursor: pointer;" name="conv" value="Send Expression!" type="submit">
    </form>
    Code (markup):
    then to display the chosen image

    <?php
    echo '<img src="images/'.$pic.'.jpg" border="0" width="150" height="150"></a></center><br/><br />';
    ?>
    Code (markup):

     
    assault14, Feb 21, 2011 IP
  2. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #2

    AND, if you are trying to get all in single array, may be parsing (as your question was not clear to me):
     
    Vooler, Feb 21, 2011 IP
  3. assault14

    assault14 Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thank you, sorry my question wasnt clear to you. ill try to rephrase it. So i have 6 thumbnails with text below them on one page. a users selects a radio button benieth one of the thumbnails. once a user selects one they then click submit, and it directs them to another page and displays the thumbnail. But wat i want it to do is also display the text, because atm it only displays the image.
     
    assault14, Feb 21, 2011 IP
  4. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #4
    Well that is simple, add one hidden field with each caption:

    <P class=centerP><img src="/images/1.jpg" border="0" width="100" height="100" /></P><P class=centerP><center><input type="radio" name="pic" CHECKED value="1"><input type="hidden" name="text_1" value="Cheer Up" /><font size="2" >Cheer Up</font></center></P>


    
    //at php end
    $pic = $_POST['pic'];
    echo '<img src="images/'.$pic.'.jpg" border="0" width="150" height="150"></a></center><br/><br />'; 
    
    //display text
    echo $_POST["text_$pic"];
    
    Code (markup):
    that's it.
     
    Vooler, Feb 21, 2011 IP
  5. assault14

    assault14 Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you! works great
     
    assault14, Feb 21, 2011 IP