Jump to content

Dividing data with php after sql query....


mkosmosports

Recommended Posts

Hello Everyone,

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...
Currently:
$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....

Followed by:
  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.
        {
          include("phps/retteamscup.php");
        }
  echo("</div>");
  echo("</div>");

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....

  echo("<div class=\"teamlistcupcontainer\">");
  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..)
                            {
                include("phps/retteamscup.php");
              }
          echo("</div>");<-- End tag to subcontainer (only once per each data set..)             
                          }
          echo("</div>");

Thanks Everyone!
Please let me know if Im not clear....
Link to comment
Share on other sites

The SQL's date functions are much better than PHP's ones. If you want to do it with php you'll have to convert the dates into timestamps, preform the matematical operations needed and then convert back to the date you want, compare....

Orio.
Link to comment
Share on other sites

Hey Orio,

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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.