drop down list show data

Hi!
I’ve created this page: www.wbplanecompare.com/fighters2.php

I’ve also created a mysql database with all airplanes (+specific id for each plane) and ratings from 1-12 in each category (speed, firepower, turnrate etc etc)

What I want the webpage to do: You choose planes from the drop down lists, press the “send request” button, and the page will then be filled with numbers in the tables below. So in “speed above 20k”, the selected plane’s rating in that area will be displayed. (I later want the numbers be translated to stars, but that is a later problem. I’ve made a visual example at www.wbplanecompare.com/fighters.html)

I have done drop down lists with the following coding:

example 1 in the 2 tables next to submit button:

-Choose a plane- Spitfire MkI Spitfire MkII Spitfire Vb Spitfire Vc Spitfire IXe Spitfire XIV [b] example 2 in bottom left screen:[/b] -Choose a plane- <?php $link = mysql_connect('wbplanecomparecom.ipagemysql.com', 'wbplanecompare', 'xxx'); mysql_select_db(wbfighters);

$planequery=“SELECT * FROM fighters”;
$planeresult=mysql_query($planequery) or die ("Query to get data from firsttable failed: ".mysql_error());

while ($planerow=mysql_fetch_array($planeresult)) {
$plane=$planerow[“plane”];
$id=$planerow[“id”];
echo “<option value=”$id">
$plane ";
}
?>

I am new to coding, but learned fast. However I cannot find a single tutorial on how to show the specific data from the MySQL-db, in the appropriate grey tables below. All 100+ tutorials I’ve found only show how to make the drop-list, which I’ve already done.

P.S. I’ve filled the tables with numbers as a test by using:

<?php $link = mysql_connect('wbplanecomparecom.ipagemysql.com', 'wbplanecompare', 'xxx'); mysql_select_db(wbfighters); $query = mysql_query("SELECT * FROM fighters WHERE id=5"); WHILE($rows = mysql_fetch_array($query)): $firepower = $rows['firepower']; echo "$firepower"; endwhile; ?>

however the id= in this case is static, and I want the id to change depending on what plane you select.

Cheers and would be forever greatful if you could help!
/Robert

[php] <?php
for ($x = 1; $x < 11; $x++) {
echo ‘’ . $planerow[‘plane’] . ‘’ . PHP_EOL;
}
?> [/php]

Maybe something like the above???

An since you’re learning PHP, you might as well learn about msyqli or PDO, for mysql is DEPRECIATED. :wink:

P.S. you can omit the .PHP_EOL, for I only do that so my HTML will look pretty. 8)

Me bad…you have to do a foreach for the loop… ;D but I think you can figure it out. If not just ask for help again, it’s a great way to learn to see if you can do it on you own first … well that’s my opinion.

The first thing you need to do is learn how to use Pdo or MySQLi. You are using obsolete code as previously point it out. You need a solid foundation to build on. The link in my signature will take you to a download of a working PDO database to get you started.

Also, it will be helpful if you post your database SQL so we can take a look at that as well.

Sponsor our Newsletter | Privacy Policy | Terms of Service