I'm making a simple website using PHP and MySQL, where based on the entered criteria, the website outputs the results from the database. Since there'll be a lot of them (eventually, now there's like 6) I want to compress the table, by having two or three results next to each other. The results will be displayed as images (whose address is pulled from the database) within the table's cells, ideally with a title (also from the DB) under them. Everywhere i've looked (like w3s or here), the code puts each pulled attribute of a table's row into its own cell, and each row of the html table corresponds to the sql table.
Specifically:
from the search form, i $_GET
variables $color
and $altmode
in my table 'transformers', i have columns 'id' (auto incrementing), 'color', 'altmode', 'name' and 'image1'
using PDO, I want to SELECT id,name,image1 FROM transformers WHERE color=$color AND altmode=$altmode;
and have the results in one table.
basically like this except dynamically generated from the PDO query results, and with the name of each toy being listed under the image.
Honestly i don't know where to begin. So far I have this (with the $conn connection being initialised in required connect.php file)
if (isset($_GET['color']) && isset($_GET['altmode']))
{
$stmt = $conn->prepare("SELECT id,name,image1 FROM transformers WHERE color=:color AND altmode=:altmode");
$stmt->bindParam(':color', $_GET['color']);
$stmt->bindParam(':altmode',$_GET['altmode']);
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
echo "this works";
/*
foreach ($variable as $key => $value) {
and here i am lost
}
*/
} else
{
echo "<p id=\"error\">You didn't search for anything! Go to <a href=\"index.php\">the main page</a> to find a figure!</p>";
}
(edited the code because what I had included was just completely wrong, but still it shows no signs of being right) this code should, if Altmode and Color are set via the Get method, execute the query, not write it out anywhere but instead output "this works". Then I commented out some code that would be a start of a function writing out the table. However there is something wrong even with the query which i can't see because it doesn't say "this works" But my main problem is still how to continue on from that.