Hello,
This happens to be my first foray into php-mySQL connections and I am failing miserably. I am working on a military aviation site in which the data on each plane is stored in a mySQL database which I have already created.
There are two tables in the database, one called "list" which has the general info on each plane (like for example, a P-51), and another called "data_ww2" which has the data on each plane sub-variant (P-51B, P-51D, P-51H).
The index.php file accesses both of these tables, for example, the title of the page is stored in the "list" table so that gets fetched first. Then for the creation of the table, the file is supposed to fetch the row data of the "data_ww2" table and display as many columns as there are sub-variants.
I have attached a picture of the HTML-only version of my site to show you how the final display should be like.
Currently the mySQL database only has 2 "list" entries (p-47 and p-51) while the "data_ww2" table has 5 entries (P-47D, P-47N, P-51B, P-51D, P-51H). The plane we want displayed is selected via $_GET method. The two possibilities are:
http://www.aviamil.net/index.php?m=p-47
http://www.aviamil.net/index.php?m=p-51
The p-47 file should display 2 columns of data since there are two sub-variants. The p-51 file should display 3 columns of data since there are three.
So what is wrong?
Nothing from the mySQL databases are fetched. 🙁
I don't know what the problem is, I've checked the variables and syntaxes and everything seems alright but for some reason no data which is fetched from the db gets displayed. What is truly strange is that the first row in the output table (the $data['country'] row) is supposed to be a small flag (like in the pic) yet no flag appears, however the source code indicated that the "while" statement worked and produced either 2 or 3 tables depending on whether you select the p-47 (2) or the p-51 (3).
Wierd. 😕
Here is the source code (I have not placed most of the output rows since they are all the same):
<?php
/* Variable list */
/* Connection Variables */
$conn = mysql_connect($host, $user, $pass) or die(mysql_error());
$db = mysql_select_db($mysql, $conn) or die(mysql_error());
/* Directory Variables */
$inc = "nameofrootfolder";
/* GET Variables */
$model = $_GET['m'];
/* Header */
include $inc . 'header.php';
$qlist = mysql_query("SELECT * FROM list WHERE model = '$model'", $conn);
$title = mysql_fetch_array($qlist);
echo "<title>AVIA - " . $title['title'] . "</title> \n";
/* Body */
echo "<body> \n";
$qdata = mysql_query("SELECT * FROM data_ww2 WHERE model = '$model'", $conn);
echo "<table cellspacing=\"0\" cellpadding=\"0\">
<tr class=\"data_toprow\">
<td class=\"data_list\"></td>";
while($data = mysql_fetch_array($qdata)) { echo "<td><img src=\"http://www.aviamil.net/images/sflag_" . $data['country'] . "gif\"></td>"; };
echo " </tr>
<tr>
<td class=\"data_list\">Design</td>";
while($data = mysql_fetch_array($qdata)) { echo "<td>" . $data['design'] . "</td>"; };
echo " </tr>
<tr>
<td class=\"data_list\">Name</td>";
while($data = mysql_fetch_array($qdata)) { echo "<td>" . $data['name'] . "</td>"; };
I'm probably doing something really stupid. Oh well. Btw, the CSS sheet has not been made so those classes are redundant at this point.