0

Hi guys, I think I need a help.
My teacher gave us a activity on Postgres and PHP to query what's inside the database file and code it to PHP to view the results.

I have a screenshot on the Database of the Postgre.
http://theoutdatedblogger.com/Email-Newsletters-Template/database.png

What I need to do is display the Referenceno column by Name
customerid, lastname, firstname, address, city, state, zip, referenceno
1007 GIANA TAMMY 9153 MAIN STREET AUSTIN TX 78710 1003

Instead I want it to display the 1003 reference number which is SMITH, LEILA based on the customerid. Screenshot provided above.

And this is my PHP code.

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Customer's Information</title>
<style type="text/css">
<!--
body,td,th {
	color: #000000;
	font-family: Geneva, Arial, Helvetica, sans-serif;
}
body {
	background-image: url(background.jpg);
	background-color: #FFFFFF;
}
table {
	border:solid #FF0000 2px;
}
-->
</style></head>

<body>
<div align="center">
<?php require_once('db_connection.inc.php'); ?>
  <h3> Customer's Information </h3>
  <hr />
<table border="2" bgcolor="#FFFFFF">
	<tr>
		<td><strong> Customer ID </strong></td>
		<td><strong> Customer Name </strong></td>
		<td><strong> Address </strong></td>
		<td><strong> Referred Customer </strong></td>
	</tr>

<?php
	$query = pg_query("SELECT * FROM tblcustomer");// WHERE referenceno IN(1003, 1006, 1010)");
	while($result = pg_fetch_array($query, NULL, PGSQL_ASSOC))
	{
?>
	<tr>
		<td><?php echo $result[customerid]; ?></td>
		<td><?php echo $result[lastname] . ", " . $result[firstname]; ?></td>
		<td><?php echo $result[address] . ", " . $result[city] . ", " . $result[state] . ", " . $result[zip]; ?></td>
		<td><?php if(empty($result[referenceno]))
					echo "&nbsp;";
				  else echo $result[referenceno]?></td>
<?php } ?>
</table>
<hr />
</div>
</body>
</html>

Here is also my database backup file: http://theoutdatedblogger.com/Email-Newsletters-Template/bookstore.backup

Any help will be great.

Attachments background.jpg 13.9 KB
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Customer's Information</title>
<style type="text/css">
<!--
body,td,th {
	color: #000000;
	font-family: Geneva, Arial, Helvetica, sans-serif;
}
body {
	background-image: url(background.jpg);
	background-color: #FFFFFF;
}
table {
	border:solid #FF0000 2px;
}
-->
</style></head>

<body>
<div align="center">
<?php require_once('db_connection.inc.php'); ?>
  <h3> Customer's Information </h3>
  <hr />
<table border="2" bgcolor="#FFFFFF">
	<tr>
		<td><strong> Customer ID </strong></td>
		<td><strong> Customer Name </strong></td>
		<td><strong> Address </strong></td>
		<td><strong> Referred Customer </strong></td>
	</tr>

<?php
	$query = pg_query("SELECT * FROM tblcustomer");// WHERE referenceno IN(1003, 1006, 1010)");
	while($result = pg_fetch_array($query, NULL, PGSQL_ASSOC))
	{
?>
	<tr>
		<td><?php echo $result[customerid]; ?></td>
		<td><?php echo $result[lastname] . ", " . $result[firstname]; ?></td>
		<td><?php echo $result[address] . ", " . $result[city] . ", " . $result[state] . ", " . $result[zip]; ?></td>
		<td><?php if(empty($result[referenceno]))
					echo "&nbsp;";
				  else echo $result[referenceno]?></td>
<?php } ?>
</table>
<hr />
</div>
</body>
</html>
2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by shushi
0

Have you tried:

"SELECT * FROM tblcustomer WHERE referenceno = 1003 ORDER BY lastname"

?

I already tried that one, instead from '1003' from the reference no, it should display as SMITH, LEILA..

0

I don't understand, you tried it with 1003 in the apostrophies? Try without the apostrophies because that usually means it is a string.
Otherwise if you want SMITH, LEILA to appear first, I would try:

SELECT lastname, firstname, address, city, state, zip, referenceno FROM tblcustomer WHERE referenceno = 1003 ORDER BY lastname

What is the result you currently get?

0

I don't understand, you tried it with 1003 in the apostrophies? Try without the apostrophies because that usually means it is a string.
Otherwise if you want SMITH, LEILA to appear first, I would try:

SELECT lastname, firstname, address, city, state, zip, referenceno FROM tblcustomer WHERE referenceno = 1003 ORDER BY lastname

What is the result you currently get?

http://theoutdatedblogger.com/untitled.PNG this link was the result from the screenshot I uploaded at the first post.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.