Creating a php program to compare video game characters

What You actually need is logical approach. You have to ask yourself a question “what You want”, “what You need” and “how to do it”.

So in Your case You want to compare something but You didn’t actually say what exactly You need. So if You’re new i can can help You that:

What You need for sure is webpage, where user can select character from a list. But what then? I don’t know. You didn’t specify so…:

1) Show user a select box to choose character. How to get them? Select from database. This is what You already have.

2) After user select character You need to send this data to the server. How to do it? Use <form> tag like:

<form method="post">
    <select name="character">...option list...</select>
    <input type="submit" value="Search">
</form>

3) Get data sent by Your form and use them to compare with… something You have.

<?php

if( isset( $_POST['character'] ) ){
// do something with this character
}

?>

4) Show user response like found or not found or something else. Pass this data into some div like:

<?php
$found = 'set this true OR false';

if( $found ){
    $message="Found it!";
}else{
    $message="Not_found!";
}

?>

Then in HTML write something like:

<div><?php echo isset( $message ) ? $message : "'; ?></div>

Thats it, rest is up to You. Any simple problem You will solve by searching in Google.

——– Edit

First of all if You’re using multiple select box, the name must be:

<select name="character[]" multiple>

Then Your $_POST[‘character’] is now an array. You can check its content by:

echo '<pre>';
var_dump($_POST);
echo '</pre>';

Use foreach:

$ids = []; // or $ids = array(); if php version lower than 5.4

foreach( $_POST['character'] as $v ){
    $ids []= (int) $v;
}

$query = 'SELECT * FROM `character` where id IN ('. implode(',', $ids) .') ';

Leave a Comment