PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
.....
// Execute your query (returning a result set in this case
$sqlresult = mysql_query($sqlquery) or die("Query Error : " . $sqlquery . "<br /> Error: " . mysql_error());
// Validate that the query returned records
if (mysql_num_rows($sqlresult) > 0) {
// Start display of the records
echo "Business Category : " . $category . "<BR />";
echo "<table>";
// Loop through your result set to process the results
while ($row = mysql_fetch_array($sqlresult, MYSQL_ASSOC) // here you can simply use mysql_fetch_assoc() instead
{
// Process your records here... like
echo '<tr>';
echo '<td>' . $row['bizname'] . '</td>';
echo '<td>' . $row['bizaddress'] . '</td>';
echo '<td>' . $row['bizcity'] . '</td>';
echo '<td>' . $row['bizstate'] . '</td>';
echo '<td>' . $row['bizzip'] . '</td>';
echo '<td>' . $row['bizphone'] . '</td>';
echo '<td>' . $row['bizzgooglemap'] . '</td>';
echo '</tr>';
}
echo "</table>";
} else {
echo "No records have been found for the category " . $category;
}
// Close your Db Engine Link
mysql_close($link)
.....
Okay, well I got the while{} loop working and it is spewing out multiple records BUT now my problem is that it seems to duplicate certain records in the HTML table... Any idea how to fix that?
<?php
// Set the error(s) reporting level
error_reporting(E_ALL);
ini_set("display_errors", 1);
$category = "Professional Services";
// Open a connection link to your Database Engine
$link = mysql_connect('localhost', 'liecon63_bizdir', 'pass') or die("Connection Error : " . mysql_error());
// Select the database to work with
mysql_select_db('liecon63_bizdir') or die("Database Selection Error : " . mysql_error());
// Define your query
$sqlquery = "SELECT * FROM bizdir WHERE bizcategory = '".$category."'"; //assuming that you have defined $category variable before in some way
// Execute your query (returning a result set in this case
$sqlresult = mysql_query($sqlquery) or die("Query Error : " . $sqlquery . "<br /> Error: " . mysql_error());
// Loop through your result set to process the results
while ($row = mysql_fetch_array($sqlresult, MYSQL_ASSOC)) // here you can simply use mysql_fetch_assoc() instead
{
do { ?>
<table border="0" width="100%" id="table3">
<td width="400"><tr>
<td><?php echo $row['bizname']; ?>
<br>
<?php echo $row['bizaddress']; ?>
<br>
<?php echo $row['bizcity']; ?>, <?php echo $row['bizstate']; ?> <?php echo $row['bizzip']; ?>
<br>
<?php echo $row['bizphone']; ?></td>
<td><?php echo $row['bizname']; ?>
<br>
<?php echo $row['bizaddress']; ?>
<br>
<?php echo $row['bizcity']; ?>, <?php echo $row['bizstate']; ?> <?php echo $row['bizzip']; ?>
<br>
<?php echo $row['bizphone']; ?></td>
</tr>
</table>
<?php } while ($row = mysql_fetch_array($sqlresult, MYSQL_ASSOC));
}?>
<?php
// Set the error(s) reporting level
error_reporting(E_ALL);
ini_set("display_errors", 1);
$category = "Professional Services";
// Open a connection link to your Database Engine
$link = mysql_connect('localhost', 'liecon63_bizdir', 'pass') or die("Connection Error : " . mysql_error());
// Select the database to work with
mysql_select_db('liecon63_bizdir') or die("Database Selection Error : " . mysql_error());
// Define your query
$sqlquery = "SELECT * FROM bizdir WHERE bizcategory = '".$category."'"; //assuming that you have defined $category variable before in some way
// Execute your query (returning a result set in this case
$sqlresult = mysql_query($sqlquery) or die("Query Error : " . $sqlquery . "<br /> Error: " . mysql_error());
// Validate that the query returned records
if (mysql_num_rows($sqlresult) > 0) {
// Start display of the records
echo "Business Category : " . $category . "<BR />";
echo "<table>";
// Loop through your result set to process the results
while ($row = mysql_fetch_array($sqlresult, MYSQL_ASSOC) // here you can simply use mysql_fetch_assoc() instead
{
// Process your records here... like
echo '<tr>';
echo '<td>' . $row['bizname'] . '</td>';
echo '<td>' . $row['bizaddress'] . '</td>';
echo '<td>' . $row['bizcity'] . '</td>';
echo '<td>' . $row['bizstate'] . '</td>';
echo '<td>' . $row['bizzip'] . '</td>';
echo '<td>' . $row['bizphone'] . '</td>';
echo '<td>' . $row['bizzgooglemap'] . '</td>';
echo '</tr>';
}
echo "</table>";
} else {
echo "No records have been found for the category " . $category;
}
// Close your Db Engine Link
mysql_close($link)
?>
</html>
Your missing a closing bracket on your while statement, and missing a semi colon on your mysql_close statement.
Do not make it a habit of us fixing your parse errors. This could have been easily solved had you looked just a little more carefully. We are here to teach you, not do the work for you
I'm still having the same problem, I need two columns but the data is repeating in those columns. How can I get the first record the show in the first column cell and then the second record and so on in the second column...?
// Define your query
$sqlquery = "SELECT * FROM bizdir WHERE bizcategory = '".$category."'";
//assuming that you have defined $category variable before in some way
// Execute your query (returning a result set in this case
$sqlresult = mysql_query($sqlquery) or die("Query Error : " . $sqlquery . "<br /> Error: " . mysql_error());
// Validate that the query returned records
if (mysql_num_rows($sqlresult) > 0) {
// Start display of the records
echo "Business Category : " . $category . "<BR />";
echo "<table>";
// Loop through your result set to process the results
while ($row = mysql_fetch_array($sqlresult, MYSQL_ASSOC)) // here you can simply use mysql_fetch_assoc() instead
{
// Process your records here... like
?><table border="0" width="100%" id="table3">
<td width="400"><tr>
<td><?php echo $row['bizname']; ?>
<br>
<?php echo $row['bizaddress']; ?>
<br>
<?php echo $row['bizcity']; ?>, <?php echo $row['bizstate']; ?> <?php echo $row['bizzip']; ?>
<br>
<?php echo $row['bizphone']; ?></td>
<td><?php echo $row['bizname']; ?>
<br>
<?php echo $row['bizaddress']; ?>
<br>
<?php echo $row['bizcity']; ?>, <?php echo $row['bizstate']; ?> <?php echo $row['bizzip']; ?>
<br>
<?php echo $row['bizphone']; ?></td>
</tr>
</table>
<?
}
echo "</table>";
} else {
echo "No records have been found for the category " . $category;
}
// Close your Db Engine Link
mysql_close($link);
?>
</html>