Forum Moderators: mack
successfully connecting to the MySQL database and getting some query results using PHP
working on parsing the data files and creating the stand-alone buoy deployment table
making relational links to other tables
You have created some sql tables and probably put some test or real data into it.
You need make this data viewable over the network via a web browser.
<?php
//you have to connect to mysql first. Your mysql connection will have a username and password.
mysql_connect("localhost", "your_username", "your_password") or die(mysql_error());
//you have to enter the name of your database.
mysql_select_db("your_database_name") or die(mysql_error());
//"websites" needs to be the name of your table
$result = mysql_query("SELECT * from websites")
or die(mysql_error());
//this will loop printing out every row of the table "websites"
while($row = mysql_fetch_array($result))
{
//when inserting data, specify the title of the column using the $row[''] command.
//$row['this_needs_to_be_the_title_of_the_column_you_are_referencing'];
//example lines
echo "Date Added: ".$row['web_date']."<br />";
echo "Website Type: ".$row['web_type']."<br />";
}
?> mysql_connect("localhost", "your_username", "your_password") or die(mysql_error());
mysql_select_db("your_database_name") or die(mysql_error()); $filename = "riverine.txt";
$fp = fopen($filename, "r") or die("Couldn't open $filename");
$lat = "";
$long = "";
$depth = "";
$speed = "";
$direction = "";
$temp = "";
$quality = "";
mysql_query("INSERT INTO data (`lat``long``depth``speed``direction``temp``quality`) VALUES('$lat', '$long', '$depth', '$speed', '$direction', '$temp', '$quality') ") or die(mysql_error()); Column count doesn't match value count at row 1
the only thing I could really find mentioned something about an "id" field
1 Check all variables after input from text file, and set to the correct type (text, int, float, etc.) before insertion to the DB.
2 Separate SQL query & php code
"INSERT INTO some_table SET field1=$field1, ..." rather than your example, because it is self-documenting. Which brings me to the final advice... 3 DOCUMENT YOUR CODE!
30.30077,-89.70399,0.0,5.40,105.93,22.8,1
30.30067,-89.70371,0.0,5.14,112.88,22.8,1
30.30057,-89.70346,0.0,5.17,114.68,22.9,1
30.30046,-89.70321,0.0,5.10,124.66,22.9,1
30.30029,-89.70302,0.0,5.15,141.80,23.0,1
30.30008,-89.70287,0.0,5.00,153.77,23.0,1
30.29985,-89.70277,0.0,5.23,164.95,23.1,1
30.29962,-89.70271,0.0,5.19,172.38,23.2,1
30.29938,-89.70268,0.0,5.17,176.67,23.2,1
30.29915,-89.70267,0.0,5.20,177.89,23.3,1
30.29891,-89.70266,0.0,5.23,175.52,23.3,1
30.29868,-89.70264,0.0,5.07,170.47,23.4,1
30.29846,-89.70259,0.0,4.10,167.45,23.4,1
30.29824,-89.70255,0.0,4.87,174.12,23.5,1
30.29803,-89.70251,0.0,3.91,170.50,23.5,1
30.29783,-89.70252,0.0,3.91,170.50,23.6,1
30.29765,-89.70256,0.0,3.83,174.54,23.6,1
30.29761,-89.70234,0.0,3.26,121.18,23.7,1
$lat = "";
$long = "";
$depth = "";
$speed = "";
$direction = "";
$temp = "";
$quality = "";
30.30077,-89.70399,0.0,5.40,105.93,22.8,1
30.30067,-89.70371,0.0,5.14,112.88,22.8,1
30.30057,-89.70346,0.0,5.17,114.68,22.9,1
30.30046,-89.70321,0.0,5.10,124.66,22.9,1
30.30029,-89.70302,0.0,5.15,141.80,23.0,1
30.30008,-89.70287,0.0,5.00,153.77,23.0,1
30.29985,-89.70277,0.0,5.23,164.95,23.1,1
30.29962,-89.70271,0.0,5.19,172.38,23.2,1
30.29938,-89.70268,0.0,5.17,176.67,23.2,1
30.29915,-89.70267,0.0,5.20,177.89,23.3,1
30.29891,-89.70266,0.0,5.23,175.52,23.3,1
30.29868,-89.70264,0.0,5.07,170.47,23.4,1
30.29846,-89.70259,0.0,4.10,167.45,23.4,1
30.29824,-89.70255,0.0,4.87,174.12,23.5,1
30.29803,-89.70251,0.0,3.91,170.50,23.5,1
30.29783,-89.70252,0.0,3.91,170.50,23.6,1
30.29765,-89.70256,0.0,3.83,174.54,23.6,1
30.29761,-89.70234,0.0,3.26,121.18,23.7,1
file()([uk.php.net ]):
$file = "filename_of_text_file";
$fileArray = file( $file );
foreach( $fileArray as $lineNumber => $line ) {
list( $lat, ... $quality ) = each $line;
}