Have an account? Sign in
Login  Register  Facebook
problem with select a table with mysql
Hey guys,
Im new to php and i have been given a question which i dont understand:
--Create a PHP page that will display the content of each of the fields of the customer table of the warehouse database. Save the file as task3.php.The following code will be helpful (you will need to refer to the database table description above to determine the names of the fields that are not included in the code below):
<html>
<head>
<title>Prac 3 Task 3</title>
</head>
<body>
<?php
$conn = mysql_connect(\"localhost\", \"student\", \"prac3\");
mysql_select_db(\"warehouse\", $conn)
or die (\'Database not found \' . mysql_error() );
$sql = \"SELECT * FROM customer\";
$rs = mysql_query($sql, $conn)
or die (\'Problem with query\' . mysql_error());
?>
<table border=\"1\" summary=\"Customer Details\">
<tr>
<th>Customer ID</th>
<th>First Name</th>
<th>Last Name </th>
<th>Street Address</th>
<th>Suburb</th>
<th>State</th>
<th>postcode</th>
</tr>
<?php
while ($row = mysql_fetch_array($rs)) { ?>
<tr>
<td><?php echo $row[\"customerID\"]?></td>
<td><?php echo $row[\"firstName\"]?></td>
</tr>
<?php }
mysql_close($conn); ?>
</table></body></html>

The customer table basically has the following fields:
customerID | firstName| lastName |address | suburb |state |postcode
Started: September 16, 2011 Latest Activity: September 16, 2011 php mysql
1 Answer
it will be like that:
<html>
<head>
<title>Prac 3 Task 3</title>
</head>
<body>
<?php
$conn = @mysql_connect(\"localhost\", \"student\", \"prac3\");
mysql_select_db(\"warehouse\", $conn) or die (\'Database not found \' . mysql_error() );
?>
<table border=\"1\" summary=\"Customer Details\">
<tr>
    <th>Customer ID</th>
    <th>First Name</th>
    <th>Last Name </th>
    <th>Street Address</th>
    <th>Suburb</th>
    <th>State</th>
    <th>postcode</th>
</tr>
<?php
$query = mysql_query(\"SELECT * FROM `customer`\");

while ($row = mysql_fetch_array($query)) { ?>
<tr>
    <td><?php echo $row[\"customerID\"]?></td>
    <td><?php echo $row[\"firstName\"]?></td>
    <td><?php echo $row[\"lastName\"]?></td>
    <td><?php echo $row[\"address\"]?></td>
    <td><?php echo $row[\"suburb\"]?></td>
    <td><?php echo $row[\"state\"]?></td>
    <td><?php echo $row[\"postcode\"]?></td>
</tr>
<?php }
mysql_close($conn); ?>
</table></body></html>

Posted: MacOS
In: September 16, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer