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!
mysql_select_db("liecon63_bizdir" , $db) or die("Couldn't open database: ".mysql_error());
$sqlquery = "SELECT * FROM liecon63_bizdir WHERE (bizcategory = '".$category."')";
$biznm = trim($row['bizname']);
$sqlresult = mysql_query($sqlquery);
$sqlmyrow = mysql_fetch_array($sqlresult, MYSQL_ASSOC);
Thats the code I have right now. I'm trying to build a PHP business directory that will fit into my site. I am having problems displaying output from the db.
I get a "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/liecon63/public_html/bizdir/bizdisplay3.php on line 62"
your code is incomplete... is not showing per example: where are you making a db connection, is not showing from where the variable $category is taken it value... in the code that you are showing you are not controlling errors.. per example:
<?php
// Set the error(s) reporting level
error_reporting(E_ALL);
ini_set("display_errors", 1);
// Open a connection link to your Database Engine
$link = mysql_connect('yourhost', 'yourusername', 'yourpassword') or die("Connection Error : " . mysql_error());
// Select the database to work with
mysql_select_db('yourdatabase') or die("Database Selection Error : " . mysql_error());
// Define your query
$sqlquery = "SELECT * FROM liecon63_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
{
// Process your records here... like
echo "BizName = " . $row['bizname'] . "<br />";
// etc.. etc..
}
// Close your Db Engine Link
mysql_close($link)
?>
<?php
// Set the error(s) reporting level
error_reporting(E_ALL);
ini_set("display_errors", 1);
// 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 liecon63_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
{
// Process your records here... like
echo "BizName = " . $row['bizname'] . "<br />";
// etc.. etc..
}
// Close your Db Engine Link
mysql_close($link)
?>
Says there is a syntax error on line 25, unexpected {
<?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
{
// Process your records here... like
echo "BizName = " . $row['bizname'] . "<br />";
echo "BizName = " . $row['bizaddress'] . "<br />";
echo "BizName = " . $row['bizphone'] . "<br />";
// etc.. etc..
}
// Close your Db Engine Link
mysql_close($link);
?>
Now how would I go about displaying the output in an array to show all the records of certain categories?
I also need to create a search utility as well that will display records in HTML tables on a page.
You guys on here are awesome, and I really appreciate the help!
<?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
{
// Process your records here... like
echo "BizName = " . $row['bizname'] . "<br />";
echo "BizName = " . $row['bizaddress'] . "<br />";
echo "BizName = " . $row['bizphone'] . "<br />";
// etc.. etc..
}
?>
<table border="0" width="100%" id="table3">
<tr>
<td width="400">
<b><i><font face="Arial" size="3">Affordable Accountants </font><font face="Arial" size="2">
<a target="_blank" href="http://maps.google.com/maps?q=367+Sunrise+Highway,+West+Babylon,+NY+11704&spn=0.026699,0.057811&hl=en">
<font size="3">
<img border="0" src="http://www.lieconomy.com/li/images/map.gif" width="46" height="19"></font></a></font><font face="Arial" size="3"></a>
</font>
</i>
</b><font face="Arial" size="3"><br>
</font><font face="Arial" size="2">4910 Merrick Road Suite B60<br>
Massapequa Park, New York 11762<br>
</font><font face="Arial" size="3"><b>(516) 795-1223</b></font><font size="2"><b> </b></font></td>
</tr>
</table>
<?
mysql_close($link);
?>
I need help being able to output multiple records based on the criteria that I set above. Businesses should be shown based on category & sub category.'
If anyone could assist me in this task, it would be MORE THAN APPRECIATED
I would think it needs to be put into an array, because I have like 40 records for businesses in the db for the "Professional Services" category. How would I set this array up?
I still find one of the best sites is the W3Schools site http://www.w3schools.com whether you are looking for introductions to html, css, php, mysql or many others.
is eluding me why you need an array ... if you only want to display the records that your select is retrieving in a html table why don't do that in the same while loop that you code has now? or your want to store those records in an array to process them later in another way?... your objectives are not clear for me
Hopefully this will give you a start in understanding how do/while loops work, its worth the pain as once you understand loops you will find php much easier to work with.