Page 2 of 2
Re: Need help with MYSQL connection & displaying output
Posted: Thu Sep 16, 2010 1:55 pm
by mikosiko
or using the code that you already have (showing the relevant fragment here and with a very simple example):
Code: Select all
.....
// 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)
.....
Re: Need help with MYSQL connection & displaying output
Posted: Thu Sep 16, 2010 2:28 pm
by prototype18
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?
Check it out on here
http://www.lieconomy.com/bizdir/bizdisplay5.php
Code: Select all
<?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));
}?>
Re: Need help with MYSQL connection & displaying output
Posted: Thu Sep 16, 2010 2:41 pm
by mikosiko
just look at the code that I did post for you....
the one that you did is wrong... you have a while inside of the main while... therefore... display your records twice.. sometimes

Re: Need help with MYSQL connection & displaying output
Posted: Thu Sep 16, 2010 2:52 pm
by prototype18
mikosiko wrote:just look at the code that I did post for you....
the one that you did is wrong... you have a while inside of the main while... therefore... display your records twice.. sometimes

Getting
Parse error: syntax error, unexpected '{' in bizdisplay6.php on line 34
Code: Select all
<?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>
Re: Need help with MYSQL connection & displaying output
Posted: Thu Sep 16, 2010 3:10 pm
by John Cartwright
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

Re: Need help with MYSQL connection & displaying output
Posted: Thu Sep 16, 2010 3:16 pm
by mikosiko
... at least try to analyze the errors..... you are not using the last code that I did provide to you!!
review the code again (with the modifications that I gave before) and in addition
change this line
Code: Select all
echo '<td>' . $row['bizzgooglemap'] . '</td>';
for this
Code: Select all
echo '<td>' . $row['bizgooglemap'] . '</td>';
I think that is the right name for your field right?
agree 100% with what John said...
Re: Need help with MYSQL connection & displaying output
Posted: Thu Sep 16, 2010 3:19 pm
by prototype18
Well my editor isnt finding any syntax errors or missing brackets, so im at a loss.

Re: Need help with MYSQL connection & displaying output
Posted: Thu Sep 16, 2010 3:20 pm
by John Cartwright
What's your editor got to do with anything?
while ($row = mysql_fetch_array($sqlresult, MYSQL_ASSOC))
Notice the highlighted bracket, that was missing.
Re: Need help with MYSQL connection & displaying output
Posted: Thu Sep 16, 2010 3:23 pm
by mikosiko
John... those errors where fixed before... and probably he is using again the unfixed code or made a mistake while posting it
Re: Need help with MYSQL connection & displaying output
Posted: Thu Sep 16, 2010 3:24 pm
by prototype18
lol, thanks. I wasn't even paying attention to the parens I was looking for a missing bracket
It works now.
Re: Need help with MYSQL connection & displaying output
Posted: Thu Sep 16, 2010 3:30 pm
by prototype18
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...?
Code: Select all
// 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>
Re: Need help with MYSQL connection & displaying output
Posted: Thu Sep 16, 2010 3:31 pm
by John Cartwright
prototype18 wrote:lol, thanks. I wasn't even paying attention to the parens I was looking for a missing bracket
It works now.
Yea it probably would have helped to call the parens by it's formal name. I'm used to just calling them brackets,
I.e.,
Brackets -- ()
Square Brackets -- []
Curly Brackets -- {}
Re: Need help with MYSQL connection & displaying output
Posted: Thu Sep 16, 2010 3:35 pm
by prototype18
Well, im very new to this whole thing, so please excuse my ignorance.
But thank you very much for tolerating my insolence.