[SOLVED] queries and arrays
Posted: Tue Feb 10, 2004 4:54 pm
Ok so I posted this before and no one answered, so i guess I'll just try again.
this is what I'm doing: pulling related results out of two mysql tables, namely events and instances. There are lots of events and each event can have multiple instances. I'm looking to display them on the page logically and without duplicate events.
First I query the results:
Then put them into an array:
Ok thats just fine and dandy except for one thing, my results are duplicated - if there is more than one instance to an event a duplicate event is displayed with that instance as well.
eg.
1.applepicking,date1,location1,time1
2.applepicking,date2,location2,time2
3.ciderdrinking,date1,location1,time1
but I want:
1.applepicking,date1,location1,time1,date2,location2,time2
How am I going wrong? Should I be using two queries? Or a multidimensional array?
Please enlighten me...
much appreciated,
pN
this is what I'm doing: pulling related results out of two mysql tables, namely events and instances. There are lots of events and each event can have multiple instances. I'm looking to display them on the page logically and without duplicate events.
First I query the results:
Code: Select all
$q = "SELECT events.title,events.text,events.image,instances.location,DATE_FORMAT(instances.date,'%d %M %Y,') as date,TIME_FORMAT(instances.time,'%l:%i %p') as time FROM events,instances WHERE events.eventid=instances.eventid ORDER BY instances.date desc ";
$result= mysql_query($q, $connection) or die
("Could not execute query : $q." . mysql_error());Code: Select all
while ($row=mysql_fetch_array($result))
{
$title=$rowї"title"];
$text=$rowї"text"];
$image=$rowї"image"];
$location=$rowї"location"];
$date=$rowї"date"];
$time=$rowї"time"];
//and print them out
echo "$title";
echo "$text";
echo "$location";
echo "$date";
echo "$time";
}Ok thats just fine and dandy except for one thing, my results are duplicated - if there is more than one instance to an event a duplicate event is displayed with that instance as well.
eg.
1.applepicking,date1,location1,time1
2.applepicking,date2,location2,time2
3.ciderdrinking,date1,location1,time1
but I want:
1.applepicking,date1,location1,time1,date2,location2,time2
How am I going wrong? Should I be using two queries? Or a multidimensional array?
Please enlighten me...
much appreciated,
pN