I am trying to code a page for a website with a small auction. I’ve got the page layout and input form for bids sorted but am trying now to sort out the display of bids. I’m not really up to speed on php but I’m working with ‘Build your own database driven website, using php & mysql’ (only edition 4 from 2009).
I can extract the data from the database using the following:
<html>
<head>
<title>Retrieve data from database </title>
</head>
<body>
<?php
// Connect to database server
mysql_connect(“localhost”, “deverono_mikejd”, “d4r1us”) or die (mysql_error ());
// Select database
mysql_select_db(“deverono_wb”) or die(mysql_error());
// SQL query
$strSQL = “SELECT field7,field11 FROM 2007mod_mpform_results_249 WHERE 1”;
// Execute the query (the recordset $rs contains the result)
$rs = mysql_query($strSQL);
// Loop the recordset $rs
// Each row will be made into an array ($row) using mysql_fetch_array
while($row = mysql_fetch_array($rs)) {
// Write the value of the column FirstName (which is now in the array $row)
echo $row[‘field7’].$row[‘field11’].”
“;
}
// Close the database connection
mysql_close();
?>
</body>
</html>
I then try to place it into a table for presentation, but this fails:
<html>
<head>
<title>Retrieve data from database </title>
</head>
<body>
<?php
// Connect to database server
mysql_connect(“localhost”, “deverono_mikejd”, “d4r1us”) or die (mysql_error ());
// Select database
mysql_select_db(“deverono_wb”) or die(mysql_error());
// SQL query
$strSQL = “SELECT field7,field11 FROM 2007mod_mpform_results_249 WHERE 1”;
// Execute the query (the recordset $rs contains the result)
$rs = mysql_query($strSQL);
// Loop the recordset $rs
// Each row will be made into an array ($row) using mysql_fetch_array
while($row = mysql_fetch_array($rs)) {
$lots[] = array(‘lotname’ => $row[‘field7’], ‘bid’ => $row[‘field11’]);
}
exit()
?>
<?php if (isset($lots)); ?>
<table>
<?php foreach ($lots as $lot): ?>
<tr>
<td> <?php htmlout($lot[‘lotname’]); ?></td>
<td> <?php htmlout($lot[‘bid’]); ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
</body>
</html>
I’m hoping it’s something simple, just not fully understanding php. So I’m appealing to STW, can anyone suggest where I’m going wrong, please?
cheers,
Mike