issue with displaying data with php from mysql | Newbie | | Join Date: Oct 2009
Posts: 31
| |
Hi All,
The following script will display the grid, with its headers but will not display any data. Im sure ive made a mistake in the syntax somewhere but i can see the wood for the trees.
Ive ran the sql statement directly in mysql and it gives me results.
any help is greatly appreciated -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-
<title>CG0119 mysql - studentList.php</title>
-
</head>
-
-
<body>
-
<h1>Student Listing</h1>
-
-
<?php
-
-
// Connect to the Oracle database
-
$link = mysqli_connect("localhost","root","root","university")
-
or die("ERROR: Could not connect : " . mysql_error());
-
-
// Set up a query to select the required fields and records
-
$result = mysqli_query($link, "SELECT studentCode, forename, surname, startYear, typeDesc FROM student, studyType WHERE student.studyTypeID = studyType.studyTypeID")
-
or die("ERROR:query failed (Student) - " . mysql_error());
-
-
$studentResult = mysqli_query($link, $sql);
-
?>
-
-
<!-- Move out of PHP mode and start the table tags (note you
-
could have stayed in PHP mode and achieved the same
-
result by placing these tags within echo statements. -->
-
-
<table width="70%" border="1">
-
<tr>
-
<td width="15%"><strong>Student Code</strong></td>
-
<td width="25%"><strong>Surname</strong></td>
-
<td width="25%"><strong>Forename</strong></td>
-
<td width="20%"><strong>Study Type</strong></td>
-
<td width="15%"><strong>Start Year</strong></td>
-
</tr>
-
-
<?php
-
-
// For every row that was returned by the query, do something.
-
// In this example, display data from each row within an XHTML table.
-
-
// NOTE: The array keys (the field names are the array keys, the values are the field values returned by the SQL query)
-
-
echo "<tr>\n";
-
echo "<td> </td>\n";
-
echo "<td>".$studentResult['studentCode']."</td>\n";
-
echo "<td>".$studentResult['surname']."</td>\n";
-
echo "<td>".$studentResult['forename']."</td>\n";
-
echo "<td>".$studentResult['studyType']."</td>\n";
-
echo "<td>".$studentResult['startYear']."</td>\n";
-
echo "</tr>\n";
-
-
// General clean-up of resources (i.e. memory).
-
-
mysqli_free_result($studentResult);
-
mysqli_close($link);
-
-
?>
-
-
</body>
-
</html>
-
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: issue with displaying data with php from mysql
you should get some useful error messages
#22 $sql not defined
#47-51 (?) $studentResult is not an array
and of course you don't fetch data anywhere...
| | Newbie | | Join Date: Oct 2009
Posts: 31
| | | re: issue with displaying data with php from mysql
thank you for this, i get no error messages at all.
ill take a look and try to fix
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: issue with displaying data with php from mysql Quote:
Originally Posted by whitep8 thank you for this, i get no error messages at all. this may be due to suppressed error reporting
| | Newbie | | Join Date: Oct 2009
Posts: 31
| | | re: issue with displaying data with php from mysql
i think im having a thick morning.
ive added
error_reporting(E_ALL);
ini_set('display_errors', '1');
into php.ini
you know any good labotomy doctors?
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: issue with displaying data with php from mysql Quote:
Originally Posted by whitep8 you know any good labotomy doctors? shall I recommend a good decapitator?
| | Newbie | | Join Date: Oct 2009
Posts: 31
| | | re: issue with displaying data with php from mysql
lol i think thats a good idea.
it should be in .htaccess shouldnt it
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: issue with displaying data with php from mysql Quote:
Originally Posted by whitep8 it should be in .htaccess shouldnt it although you can place it there I rather recommend it to be in the PHP file* (it is easyto forget that PHP relevant code is placed in .htaccess and then you have the time of your life finding the setting)
* - especially if it is temporary
| | Newbie | | Join Date: Oct 2009
Posts: 31
| | | re: issue with displaying data with php from mysql
Ok, i dont think im going totally mad.
I have created a php.ini AND a php5.ini file. both with error activation.
I have simplified everything right down to the following but it still shows nothing.
its so annoying - <?php
-
-
// Connect to the Oracle database
-
$connection = mysql_connect("localhost","root","root","university")
-
or die("ERROR: Could not connect : " . mysql_error());
-
-
// Set up a query to select the required fields and records
-
$sql = "SELECT studentCode FROM student";
-
-
-
echo $sql;
-
-
$query = mysql_query($sql);
-
-
echo $query;
-
while ($row = mysql_fetch_array($query)) {
-
-
echo "<p>", $row['studentCode'];
-
}
-
-
-
?>
| | Newbie | | Join Date: Oct 2009
Posts: 31
| | | re: issue with displaying data with php from mysql
sorted
error reporting is switched on again. im using MAMP. silly thing, stupid me
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,272 network members.
|