0

I am using wordpress and I am fetching images from the mysql database with below code. And I display the image and there is a button just with every image and what I want is that when that button is pressed the id of that row of database that is fetched is printed on the screen.

Code

$sql = "SELECT * FROM 1user";
$results = $wpdb->get_results($sql) or die(mysql_error());

foreach( $results as $result ) {
echo '<form action="" method="post">';
echo "<img src='$result->path' width='150' height='150' >" . '<br><br>'.'<input type="submit" name="show" id="show" value="Upvote"></form>';    

}

if(isset($_POST['show'])){

echo "<br>".$result->path;
}
1

Like your sample:

$results = array(
    (object)array('id'=>1, 'path'=>'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5OjcBCgoKDQwNGg8PGjclHyU3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N//AABEIAHwAfAMBIgACEQEDEQH/xAAcAAABBAMBAAAAAAAAAAAAAAAHAAMFBgEECAL/xABDEAABAwMBBAYHBQYEBwEAAAABAgMEAAURBgcSITETQVFhcYEUIiMykaHBQlKSsdEVFjNygrJiosLSFyQ0Q1Ph4gj/xAAZAQADAQEBAAAAAAAAAAAAAAACAwQAAQX/xAAoEQACAgEDBAEEAwEAAAAAAAAAAQIRAxIhMQQiMkETUWFxsWKR0SP/2gAMAwEAAhEDEQA/ADjSpUqxhUqweFQmoNTQrMncWemkkeqwg8e7J6hRRi5OooGUlFWybUQBk8qhLlquz28lLkoOrHNDPrkePUKg0W3UGpfaXWQYEI8RHQMEjvH6/Ct02/S2mUJMwxw7jIMhXSOK8E/oKcseOLqTt/Rf6J+ScvFUvqxg65L5ItlnlyOwkf7QaX7x6jVxRpxYHfvfoK8SdodtaG7ChSn8cjuhtJ+Jz8q0VbSXs+rZ28d8v/4pqxyfGL+2KeRLnJ/SJA6svLHGXpyQE9ZRv/7afia9t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y0xkq2qwddxXed3xowtNkg2pvViMgKPvOK2qV3mrGt1R8rn7ojI2s2Wqyt1qhq6ysrK3UUX//2Q==')   
);
foreach ($results as $result) {
    echo '<form action="" method="post">';
    echo '<input type="hidden" name="id" value="'.$result->id.'">';
    echo "<img src='$result->path' width='150' height='150' >" . '<br><br>'.'<input type="submit" name="show" id="show" value="Upvote">';
    echo '</form>';
}

if(isset($_POST['show'])){
    $id = (isset($_POST['id'])) ? intval($_POST['id']): null;
    echo "<br>".$id;
}

With javascript

foreach ($results as $result) {
    echo '<img src="'.$result->path.'" width="150" height="150" data-id="'.$result->id.'">';
}

<script>
var images = document.getElementsByTagName("img");
for(var i = 0; i < images.length; i++) {
    var image = images[i];
    image.onclick = function(event) {
        alert(this.dataset.id);
    };
}
</script>
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.