Forum Moderators: coopster
I want to display some rows of my db on a page. It goes like this:
<html>title 1
<php>prod relevant to title 1
<php>prod relevant to title 1
<html>title 2
<php>prod relevant to title 2
<php>prod relevant to title 2
<php>prod relevant to title 2
at the moment the page is coded like that:
mysql db declaration1
select * from db where title="title1"
mysql db declaration2
select * from db where title="title2"
<html>Title 1
<php>do{
<php>print prod
<php>} while there is still prod in declaration1
<html>Title 2
<php>do{
<php>print prod
<php>} while there is still prod in declaration2
I have tnecat so I have ten:
mysql db declaration
select * from db where title="titleX"
and ten
do{
print prod
} while there is still prod in declaration1
surely as all the data is coming from the same table, it should be possible to do something like:
mysql db uniqueDeclaration
select * from db
<html>Title 1
<php>print all the prods relevant to title 1
<html>Title 2
<php>print all the prods relevant to title 2
etc...
but I tried to get my head round it without success (for, foreach, while, do...while) I don't seem understand how to build it.
Any ideas from you guys?
Cheers
Leo
then read from the recordset with your while or for or whatever. Within each recursion check what the title is an assign the db row to an array:
while ($Anotherbloodyrow)
if (title is title1) $title1_array[] = $Anotherbloodyrow
if (title is title2) $title2_array[] = $Anotherbloodyrow
etc...
}
So, this may or may not be helpful.
It looks like you want to connect to your database, select the information and then display the information by the category it is in, and with in those results display the information by the title that is present...
If that is the case, unfortunately, a simple quip of select by 'id' is not very helpful, because a new id will be generated for each new entry, and will not order the results properly.
Selecting by individual title, would work, but you would still need the ten connection strings, or ten 'OR' statements that would result in getting the entire database... If my assumptions are correct I think this would solve your problem...
$query = "SELECT * FROM db_table ORDER BY category,product";
$result = mysql_query($query);
while($show-stuff = mysql_fetch_array($result))
{
if($show-stuff['category'] === "Title1"){
Your tables and stuff here
}
else if($show-stuff['category'] === "Title2"){
Your tables and stuff here
}
else if($show-stuff['category'] === "Title3"){
Your tables and stuff here
}
}
Obviously this version would need to have the if()/elseif() repeated for each of your categories, but can be refined if you find it is working for you...
Hope this is helpful
Justin
Edited for clarity