Dividing data with php after sql query....
Posted 25 October 2006 - 01:02 PM
I need to retrieve startdates from mysql database in several date ranges, but I want to avoid having to run a separate query each time, so what I want to achieve is run one query with a larger date range and then retrieve the data I need using php. Then, I want to put that data, separated by date range conditions, into individual containers but without having the container take part in the while loop....
Anyone know what I mean, ever had similar issues or know of a solution to this? Below is the code...
$result7 = @mysql_query("SELECT START_DATE FROM sf_group_team WHERE START_DATE BETWEEN '2006-07-01' AND '2006-07-20'"); //Retrieves all startdates between a selected date range....
echo("<div class=\"teamlistcupcontainer\">"); //Main container.
echo("<div>"); //Subcontainer that stores each data set.
while ($row = mysql_fetch_array($result7)) //I have a separate while loop for every query with different date ranges.
Ideally, what I would want is:
$result7 = @mysql_query("SELECT START_DATE FROM sf_group_team WHERE START_DATE BETWEEN '2006-01-01' AND '2006-12-30' "); //One query that retrieves all possible startdates in 2006....
while ($row = mysql_fetch_array($result7))
$startdate = $row["START_DATE"];
if ($startdate => "2006-07-01" && $startdate <= "2006-07-20") <-- Break up the
data (not sure if conditions are what I need here....)
echo("<div>"); <-- This is the subcontainer in which I want to store separated data,
but I dont want it to loop...(only once per each data set..)
echo("</div>");<-- End tag to subcontainer (only once per each data set..)
Please let me know if Im not clear....
Posted 25 October 2006 - 01:26 PM
(Gone until 20 to November)
Posted 25 October 2006 - 01:38 PM
Thanks for your answer. So youre suggesting to just run multiple queries. Im all for that, it is a much simpler solution to code. I just thought running one query and breaking up the data with php would be quicker. I was gonna run a time test actually, but havent been able to get the php method to work as desired, so unable to actually compare. I doubt the time difference would be big between the two methods though, right?
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users