469,626 Members | 868 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

I have a weird database problem: it is returning spurious rows withall the fields concatenated into one

I have a PHP program that almost works. I'm running it from the command
line and simulating a form using a GET method. That part is working,
but I get spurious records with all of the fields concatenated into a
single field.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="content-type">
<title>eqdb_read.php - Read the Equipment Database</title>
</head>
<body>
<small>This document last modified
<script>document.writeln(document.lastModified)</script>.</small>

<?php
$_GET['hostname'] = $argv[1]; // grab [1] because [0] holds the script
name FOR DEVELOPMENT ON THE COMMAND LINE ONLY

$hostname = $_GET['hostname'];
if ( is_null($hostname) ) {
?>

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="GET">
Host Name:
<input type="text" name="hostname" /> <br />
<input type="submit" name="Lookup by hostname" />
</form>

<?php
} else {
require_once('DB.php');
$dsn = "mysql://read@black/equipment_test";
print("Connecting to database $dsn <br>\n");
$db=DB::connect($dsn, array('debug'=>1 ));
if (DB::iserror($db)) {
die($db->getMessage());
};
print("Connected. Looking up $hostname <br/>\n");
$sql = "SELECT name, location, kernel, distribution, sysadmin, ip,
mac, vendor_sn, real_num
FROM computers WHERE name LIKE '".$hostname."%' ORDER BY name ASC";

$q = $db->query($sql);
if ( DB::iserror($q)) {
die( $q->getMessage());
}
print("Completed the query<br><br>");
// generate the table
?>
<table>
<tr>
<th>name</th>
<th>location</th>
<th>kernel</th>
<th>distribution</th>
<th>sysadmin</th>
<th>ip</th>
<th>mac</th>
<th>vendor_sn</th>
<th>real_num</th>
</tr>
<?php
while ( $row = $q->fetchRow() ) {
if ( DB::isError($row) ) {
die ( $row->getMessage() );
}
print(" <tr>\n");
for ($field=0; $field<4; $field++ ) {
print(" <td>$row[$field] </td>\n");
};
print(" </tr>\n");
}
$db->disconnect();
}

?>
</table>
</body>
</html>

When I run the program, I get no error messages, but I get spurious records:

[jeffs@black public_html]$ php eqdb_read.php 238lvs | more
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="content-type">
<title>eqdb_read.php - Read the Equipment Database</title>
</head>
<body>
<small>This document last modified
<script>document.writeln(document.lastModified)</script>.</small>

Connecting to database mysql://read@black/equipment_test <br>
Connected. Looking up 238lvs <br/>
Completed the query<br><br><table>
<tr>
<th>name</th>
<th>location</th>
<th>kernel</th>
<th>distribution</th>
<th>sysadmin</th>
<th>ip</th>
<th>mac</th>
<th>vendor_sn</th>
<th>real_num</th>
</tr>
<tr>
<td>238lvs01.prognet.com N debian Linux 2.4.20 prod
Se </td> <---- this is incorrect!!!!
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<------ This is okay!!!!!
<td>238lvs01.prognet.com </td>
<td>Seattle,MSR,C05,43 </td>
<td>Linux 2.4.20 </td>
<td>debian </td>
<td>ISO </td>
<td>192.168.238.25 </td>
<td>00:03:47:84:D6:63 </td>
<td> </td>
</tr>
<tr>
<td>238lvs02.prognet.com N debian Linux 2.4.20 prod
Se </td> <------- this is INCORRECT!!!!!!!!
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>238lvs02.prognet.com </td>
<-------- This is okay!!!!
<td>Seattle,MSR,C05,28 </td>
<td>Linux 2.4.20 </td>
<td>debian </td>
<td>ISO </td>
<td>192.168.238.112 </td>
<td>00:03:47:7C:25:CE </td>
<td> </td>
</tr>
</table>
</body>
</html>
[jeffs@black public_html]$

I don't get it. Does anybody have an insight?
Many thanks,
Jeff Silverman

jeff aat commercialventvac d0t com

Mar 4 '06 #1
1 1490
Jeff Silverman" <""\"Remove the letters in all caps\" <jeff\ wrote:
I have a PHP program that almost works. I'm running it from the
command line and simulating a form using a GET method. That part is
working, but I get spurious records with all of the fields concatenated
into a
single field.
[...] <small>This document last modified
<script>document.writeln(document.lastModified)</script>.</small>

You are using PHP, no use for JS here:

<small> This document last modified
<?php print date("F d Y H:i:s.", getlastmod()) ?></small>
$sql = "SELECT name, location, kernel, distribution, sysadmin, ip,
mac, vendor_sn, real_num
FROM computers WHERE name LIKE '".$hostname."%' ORDER BY name
ASC";
You are selecting 9 fields from each row...
print(" <tr>\n");
for ($field=0; $field<4; $field++ ) {
print(" <td>$row[$field] </td>\n");
};
print(" </tr>\n");


....but are only using the 4 first fields from each row?

Why not doing something like:

print "<tr>\n\t<td>";
print implode("</td>\n\t<td>", $row);
print "</td>\n</tr>";
JW
Mar 4 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Dmitry Tkach | last post: by
2 posts views Thread by Kums | last post: by
5 posts views Thread by Jim Strathmeyer | last post: by
3 posts views Thread by josh.kuo | last post: by
12 posts views Thread by grace | last post: by
6 posts views Thread by efrenba | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.