I'm just starting to try and get my head round retrieving data from MySQL with PHP. This is the PHP I am using to get a few bits of data from my database:
This is the result I get:
Many thanks,
One confused edesignuk
btw, if this code is wrong, blame "PHP & MySQL for Dummies"
PHP:
<?php
// Connect to MySQL server on localhost
$connection = mysql_connect("localhost","root","catch22")
or die ("Could not connect to MySQL.");
// Select database from MySQL server
$db = mysql_select_db("intranet",$connection)
or die ("Could not select database.");
// Select all data from table
$query = "SELECT * FROM survey";
$result = mysql_query($query)
or die ("Could not select all data from table.");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
while ($row = mysql_fetch_array($result))
{
echo "SurveyID: ".$row['SurveyID']."<br>";
echo "Q1: ".$row['Q1']."<br>";
echo "Q2: ".$row['Q2']."<br>";
echo "Q3: ".$row['Q3']."<br>";
echo "Q4: ".$row['Q4']."<br>";
echo "Q5: ".$row['Q5']."<br>";
echo "Submitted: ".$row['SUBMITTED']."<br>";
}
?>
As you can see, "SurveyID: 1" is missing, this is the first row in the database. Does anyone know why the PHP I have is missing the first row?SurveyID: 2
Q1: 5
Q2: 3
Q3: 1
Q4: 3
Q5: 4
Submitted: 2009-12-20 04:00:00
SurveyID: 3
Q1: 3
Q2: 2
Q3: 4
Q4: 5
Q5: 3
Submitted: 2009-12-20 04:00:00
SurveyID: 4
Q1: 2
Q2: 2
Q3: 1
Q4: 3
Q5: 1
Submitted: 2009-12-20 04:00:00
Many thanks,
One confused edesignuk
btw, if this code is wrong, blame "PHP & MySQL for Dummies"