-2

enter image description here

I want that if I click on the select option , the image will appear below , how to do that here's my code:

<?php
            include('connection/connect.php');
            $YearNow=Date('Y');
            $dsds=$rowasa['posid'];
            $results = $db->prepare("SELECT * FROM candidates,student,school_year,partylist where student.idno = candidates.idno AND school_year.syearid = candidates.syearid AND posid =:a  AND candidates.partyid = partylist.partyid AND school_year.from_year like $YearNow");

            $results->bindParam(':a', $dsds);
            $results->execute();
            for($i=0; $rows = $results->fetch(); $i++){
    ?>
                <option style="padding: 35px 50px 35px 80px; background:url('admin/savephp/images/<?php echo $rows['image']; ?>')  no-repeat scroll 5px 7px / 70px  auto rgba(0, 0, 0, 0);" 

                value="<?php echo $rows['candid'] ?>"><?php echo $rows['lastname'] ?>,
                    <?php echo $rows['firstname'] ?>
                - <?php 
                        echo $rows['party_name']?></option>
                <?php

            }

        ?>

        </select>
                <input type="button" value="Next" class="next action-button" name="next">

Should I need to echo which part help me please

Sanjuktha
  • 1,065
  • 3
  • 13
  • 26

1 Answers1

0

What you can do is to use Javascript (or jQuery) and Ajax.

I'll assume first that you have a <div></div> which stores the selected candidate's image.

<div id="selected_candidate_image"></div>

You did not also provide the tag details of your select, so we can just assign an id for it:

<select id="president">

And when an option is selected from it, this script would run:

$(document).on("change", "#president", function(){

  var candidateid = $(this).val(); /* THE SELECTED CANDIDATE */

  $.ajax({
    type: "POST", /* METHOD TO USE TO PASS THE DATA */
    url: "getimage.php", /* ACTION WHERE WE WILL PROCESS THE DATA */
    data: { "candidateid": candidateid }, /* THE DATA TO BE PASSED */
    success: function(result){ /* GET RETURNED DATA FROM getimage.php */
      $("#selected_candidate_image").html(result); /* THE RETURNED DATA WILL BE STORED INSIDE THE selected_candidate_image DIV */
    }
  });

});

As you might notice in the script, we process the data in getimage.php. You can do something like this:

$stmt = $db->prepare("SELECT image FROM candidates WHERE idno = ?");
$stmt->bind_param("i", $_POST["candidateid"]);
$stmt->execute();
$stmt->bind_result($image); /* GET THE CORRESPINDING IMAGE */
$stmt->fetch();
$stmt->close();

echo '<img src="/system/admin/savephp/images/'.$image.'">'; /* WHAT YOU ECHO IS WHAT WILL BE RETURNED IN YOUR MAIN FILE */
Logan Wayne
  • 6,001
  • 16
  • 31
  • 49