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!
I have the peice of code below that returns what I am looking for. However there are 98 different prod_name entries I need to do this for. Is there any way to query by prod_type and output all the co_names for each prod_name entry?
<?php
include("adminincludes/adminphpheaders_inc.php");
//open DB
include("../includes/opendb_inc.php");
$strSQL="SELECT * FROM products INNER JOIN companies USING (co_uid) WHERE prod_type='Gifts Novelties & Stationery' AND prod_name='Bed & Bath Sets & Blankets' ORDER BY co_name";
$result=mysql_query($strSQL) or die(mysql_error());
$strXML="<bedbathblankets>\n";
while ($row=mysql_fetch_array($result))
{
$strXML.="\t<co_name>".$row["co_name"]."</co_name>\n";
}
$strXML.="</bedbathblankets>\n";
?>
Last edited by Weirdan on Tue Jun 03, 2008 4:49 pm, edited 1 time in total.
Reason:php tags
i think what your needing to do is make the mysql query looser, as in after the WHERE you don't keep your search as tight. In fact if you leave out the WHERE altogether then it should list all your product rows.
I forgot to mention there are 9 different prod_types. Total products table has 40,000 entries. I need to narrow it by prod_type first. I figure 9 different files is the easiest way to narrow that down.
So I would like to keep WHERE prod_type='???" part, but not the AND prod_name='???' part in the query. Which to me means I need to move it out of the query and further into the statment I'm just not sure where to move it and how to write it in.
Someone here mentioned functions but I nor they know how?
Essentially instead of pulling 98 files with company names, I want to pul 1 with 98 different sections of company names.
<?php
include("adminincludes/adminphpheaders_inc.php");
//open DB
include("../includes/opendb_inc.php");
$strSQL="SELECT * FROM products INNER JOIN companies USING (co_uid) WHERE prod_type='Gifts Novelties & Stationery' ORDER BY co_name";
$result=mysql_query($strSQL) or die(mysql_error());
$strXML="<bedbathblankets>\n";
while ($row=mysql_fetch_array($result))
{
$strXML.="\t<co_name>".$row["co_name"]."</co_name>\n";
}
$strXML.="</bedbathblankets>\n";
?>
if you want to limit the searchs per page then pagination is what you'll need. Best way is to do a search on here or google for pagination.
Snoegoer wrote:I have the peice of code below that returns what I am looking for. However there are 98 different prod_name entries I need to do this for. Is there any way to query by prod_type and output all the co_names for each prod_name entry?