Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am very new at web development.
I have a php file that correctly queries a MySQL database and displays the results. When I try 'wrapping' this code into an html file, I get portions of the php code displaying and no data results.
I wrapped my php by the doing the following:
[syntax="html"]
<html>
<head>
<title>Joe PearDB Example</title>
</head>
<body>
<h3>This is My Pear DB Example</h3>
//<? php code here
</body>
</html>
Code: Select all
<?
$limit = 5;
require_once 'DB.php';
$user = 'root';
$pass = 'wp123;
$host = 'localhost';
$db_name = 'testdb';
$dsn = "mysql://$user:$pass@$host/$db_name";
$db = DB::connect($dsn);
if (DB::isError($db)) {
die ($db->getMessage());
}
if(isset($_GET['start'])): $start = $_GET['start']; else: $start = 0; endif;
$sql = "SELECT * FROM jos_incidents_combined ORDER BY incident_id";
$result = $db->query($sql);
if (DB::isError($result)) {
die ($result->getMessage());
}
foreach (range($start, $start + $limit - 1) as $rownum) {
if (!$row = $result->fetchrow(DB_FETCHMODE_ASSOC, $rownum)) {
break;
}
echo $row['incident_id'] . " ----- " . $row['fac_id'] . " ----- " . $row['room_descr'] . " ----- " .
$row['person_type'] . " ----- " . $row['injury'] . " ----- " . $row['severity'] . " ----- " . $row['inc_date'] . "
<BR>\n";
}
$result->free();
$numrows = $db->getOne('SELECT count(*) FROM jos_incidents_combined');
$db->disconnect();
if($start > 0) {
echo "<a href=\"".$_SERVER['PHP_SELF']."?start=".($start - $limit)."\">Back</a><BR>\n";
}
if (($start + $limit) < $numrows) {
echo "<a href=\"".$_SERVER['PHP_SELF']."?start=".($start + $limit)."\">Next</a><BR>\n";
}
?>==========
This is My Pear DB Example
Code: Select all
getMessage()); } if(isset($_GET['start'])): $start = $_GET['start']; else: $start = 0; endif; $sql = "SELECT * FROM jos_incidents_combined ORDER BY incident_id"; $result = $db->query($sql); if (DB::isError($result)) { die ($result->getMessage()); } foreach (range($start, $start + $limit - 1) as $rownum) { if (!$row = $result->fetchrow(DB_FETCHMODE_ASSOC, $rownum)) { break; } echo $row['incident_id'] . " ----- " . $row['fac_id'] . " ----- " . $row['room_descr'] . " ----- " . $row['person_type'] . " ----- " . $row['injury'] . " ----- " . $row['severity'] . " ----- " . $row['inc_date'] . "
\n"; } $result->free(); $numrows = $db->getOne('SELECT count(*) FROM jos_incidents_combined'); $db->disconnect(); if($start > 0) { echo "Back
\n"; } if (($start + $limit) < $numrows) { echo "Next
\n"; } ?>What html code is missing to display the results?
TIA,
jej1216
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]