Hi all
As said its my 1st script and I have found the boards and articles here invaluable so thanks 🙂
My only problem is with some dropdowns on form that use a query to populate them - they are empty yet if I test the query independently it returns the 5 expected results.
Can anyone offer me some clues? (And any advice on my 1st chunk of code?)
Thankyou
<?php
$server = "localhost"; // this is the server address and port
$username = "root"; // change this to your username
$password = ""; // change this to your password
$db_name = "msas452"; //change this to the name of your database
// Get an initial connection to the db and store its reference in a variable
$link = @mysql_connect ($server, $username, $password)
or die (mysql_error());
//select the db to work with
if (!@mysql_select_db($db_name, $link)) {
echo "<P>Oh dear we have a problem finding the" . $db_name . "database</p>";
}
//queries to be used
$allships = "select * from eve_ships";
$raceships = "select * where ShipRace = " . $race . "from eve_ships";
$classships = "select * where ShipClass = " . $class . "from eve_ships";
$aship = "select * where ShipName = " . $name . "from eve_ships";
//queries for forms (only 1st field completed so far)
$select_race = "select distinct ShipRace from eve_ships";
$fresult1 = mysql_query($select_race, $link);
//functions
function html_form() {
?>
<p> Please Specify The Type of Ships you Wish to See </P>
<form name ="shipsearch" method = "post" action = "<? echo $SERVER['PHP_SELF'];
?>">Race:
<? echo ("<select name='race'>");
while($row = mysql_fetch_array($fresult1)) {
echo("<option value=" . "'" . $row['ShipRace'] . "'></option>'");
}
echo '</select>'; ?><br>
Class: <input type="text" name="class"><br>
Name: <input type="text" name="name"><br>
<input type="submit" name="submit"><br>
</form>
<?
}
//Querying the db with the established connection
$result = mysql_query($allships, $link);
if (!$result) {
echo("Problems" . mysql_error());
exit();
}
//display the form
html_form();
//start the table and headings off
?>
<table border="1">
<tr>
<?
// following is commented out to fix headings in future (remove the php)
/* <td><strong>Race</strong><td>
<td><strong>Class</strong><td>
<td><strong>Name</strong><td>
<td><strong>Special</strong><td>
<td><strong>CPU</strong><td>
<td><strong>Power</strong><td>
<td><strong>High</strong><td>
<td><strong>Middle</strong><td>
<td><strong>Low</strong><td>
<td><strong>Turrets</strong><td>
<td><strong>Missiles</strong><td>
<td><strong>Structure</strong><td>
<td><strong>Armour</strong><td>
<td><strong>Shield</strong><td>
<td><strong>Shield Recharge</strong><td>
<td><strong>Capacitor</strong><td>
<td><strong>Cap. Recharge</strong><td>
<td><strong>EM</strong><td>
<td><strong>Explosive</strong><td>
<td><strong>Kinetic</strong><td>
<td><strong>Thermal</strong><td>
<td><strong>EM</strong><td>
<td><strong>Explosive</strong><td>
<td><strong>Kinetic</strong><td>
<td><strong>Thermal</strong><td>
<td><strong>Drone Space</strong><td>
<td><strong>Speed</strong><td>
<td><strong>Cargo Bay</strong><td>
<td><strong>Signature Radius</strong><td>
<td><strong>Scan Resolution</strong><td>
<td><strong>Gravimetric</strong><td>
<td><strong>Ladar</strong><td>
<td><strong>Magno</strong><td>
<td><strong>Radar</strong><td>
<td><strong>Description</strong><td>
<td><strong>Mass</strong><td>
<td><strong>Volume</strong><td>
<td><strong>Range</strong><td>
<td><strong>Speed</strong><td>
<td><strong>Max Targets</strong><td> */
?>
</tr>
<?
//put data into an array and output it to the page
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo("<tr>\n<td>" . $row["ShipRace"] . "</td>");
echo("<td>" . $row["ShipClass"] . "</td>");
echo("<td>" . $row["ShipName"] . "</td>");
echo("<td>" . $row["ShipSpec"] . "</td>");
echo("<td>" . $row["ShipCpu"] . "</td>");
echo("<td>" . $row["ShipPwr"] . "</td>");
echo("<td>" . $row["ShipHi"] . "</td>");
echo("<td>" . $row["ShipMed"] . "</td>");
echo("<td>" . $row["ShipLow"] . "</td>");
echo("<td>" . $row["ShipTur"] . "</td>");
echo("<td>" . $row["ShipMis"] . "</td>");
echo("<td>" . $row["ShipStruc"] . "</td>");
echo("<td>" . $row["Armour"] . "</td>");
echo("<td>" . $row["Shield"] . "</td>");
echo("<td>" . $row["ShieldRec"] . "</td>");
echo("<td>" . $row["Cap"] . "</td>");
echo("<td>" . $row["CapRec"] . "</td>");
echo("<td>" . $row["ShieldEM"] . "</td>");
echo("<td>" . $row["ShieldExp"] . "</td>");
echo("<td>" . $row["ShieldKin"] . "</td>");
echo("<td>" . $row["ShieldThe"] . "</td>");
echo("<td>" . $row["ArmEM"] . "</td>");
echo("<td>" . $row["ArmExp"] . "</td>");
echo("<td>" . $row["ArmKin"] . "</td>");
echo("<td>" . $row["ArmThe"] . "</td>");
echo("<td>" . $row["ShipDrone"] . "</td>");
echo("<td>" . $row["ShipSpd"] . "</td>");
echo("<td>" . $row["ShipCargo"] . "</td>");
echo("<td>" . $row["SigRad"] . "</td>");
echo("<td>" . $row["ScanRes"] . "</td>");
echo("<td>" . $row["SensGra"] . "</td>");
echo("<td>" . $row["SensLad"] . "</td>");
echo("<td>" . $row["SensMag"] . "</td>");
echo("<td>" . $row["SensRad"] . "</td>");
echo("<td>" . $row["ShipDesc"] . "</td>");
echo("<td>" . $row["ShipMass"] . "</td>");
echo("<td>" . $row["ShipVol"] . "</td>");
echo("<td>" . $row["TarRan"] . "</td>");
echo("<td>" . $row["TarMax"] . "</td>");
echo("<td>" . $row["TarNum"] . "</td>");
}
//close the table
?>
</table>
</body>
<?
//close the connection when script has finished
mysql_close ($link);
?>
</html>