Jump to content

artech

Members
  • Posts

    19
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

artech's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks BlueSky I just tried this from another server I just set up. Worked with no problem Thanks again for your help!
  2. Thanks BlueSky! If my host is configured to ignore POST's from off-site, how would I change this? I have full control over server settings, I'm just not sure what to look for. Thanks a mil!
  3. Hi, I'm working on a web application that will interact with an existing website from another company. On the other company's site, there will be a form (using POST) that has my web application as the action element. The user who clicked the submit button will be redirected to my site, where I need to receive the $_POST data from this form to process before redirecting into the web application. I have done work on the other side, using standard form posts to send data to another site, but I've never had to write the code for the receiving end. How do I receive the form data posted from the other website? Can I access the $_POST[''] array as I would with any normal same-site POST transaction? Please let me know if you need additional detail or if my question wasn't clear! I'm fast approaching deadlines and really appreciate your help! Thanks!
  4. first of all: Longer post describing what I've been trying at: http://www.phpfreaks.com/forums/index.php/topic,297252.0.html Basically, I can't figure out how to get UNIX timestamps for: The first and last second (i.e., 00:00:01 and 23:59:59) for each of the last 14 days. The first and last second for each of the last 14 weeks (i.e., first second of 05/10/2010 and last second of 05/16/2010). The first and last second for each of the last 12 months (i.e., first second of April 1, 2010 and last second of April 30, 2010). The answer may be so simple I'll be smacking myself over it later, and in the thread I posted above I was way too long winded about what I was trying. Could definitely use some guidance tho. Thx!
  5. Do you get the same result when you get the IP using a superglobal instead of getenv()? Try: echo $ip = $_SERVER['REMOTE_ADDR'];
  6. First of all: MySQL: 5.1.46 PHP: 5.3.2 Next: Summary Okay, so basically I have a dynamic graph that will allow the user to choose to view some data from the last 14 days, the last 14 weeks, and the last 12 months. But, I'm having a hard time getting the min/max dates done correctly. I get the right number of records for each day in the last 14 days graph, but not in the other two graphs. What I'm doing right now: Getting the MIN and MAX UNIX timestamps for each of the last 14 days (by min/max I mean 00:00:01 and 23:59:59 for each day). date_default_timezone_set('PDT'); // set current date $current_date = strtotime(date('Y-m-d')); // build an array for the last 14 days for ($d = 13; $d >= 0; $d--) { $day_date[] = strtotime("-$d days", $current_date); } // end days array // get the UNIX timestamp for the first and last second of the day foreach ($day_date as $key => $end) { $current_date_new = date('Y-m-d', $end); $current_date_max = $current_date_new." 23:59:59"; $current_date_min = $current_date_new." 00:00:01"; $current_date_maxUNIX = strtotime($current_date_max); $current_date_minUNIX = strtotime($current_date_min); // build the sql $day_SQL = sprintf("SELECT count(complete = 'yes') as total FROM " . $tableName . " WHERE timestampUNIX >= %s AND timestampUNIX <= %s", $current_date_minUNIX, $current_date_maxUNIX); // query for the results $data = DbRow($day_SQL, $database, $con); // !! this function just runs a standard query and returns the mysql_fetch_assoc array // format the date as we want to print it on the graph later $datef = date('M-d', $end); // add to the array $day_data[] = array("day" => $end, "dayf" => $datef, "total" => $data['total']); } // end foreach ($day_date) I have attached a gif showing the graph with all records correctly counted/displayed (i have labeled it "14 DAYS"). Next, (and here's where this seems to start breaking down), I try to get the data for each of the last 14 weeks. As a part of this I am trying to figure out the start and end max/min timestamps for the week. // build an array for the last 14 weeks for ($w = 13; $w >= 0; $w--) { $week_date[] = strtotime("-$w weeks", $current_date); } // end week array // get the unix timestamp for the first and last second of the week // $end represents the last day of each week foreach ($week_date as $key => $end) { // $end is the end of week date, so let's find the date of the beginning of the week $endymdhis = date('Y-m-d H:i:s', $end); $start = strtotime("-6 days", $endymdhis); // this line gives me an error of "A non well formed numeric value encountered " when I have debugging on. I don't really know what that means but thought I should mention it. // query for the data $week_SQL = sprintf("SELECT count(complete = 'yes') as total FROM " . $tableName . " WHERE timestampUNIX >= %s AND timestampUNIX <= %s", $start, $end); // get the mysql_fetch_assoc array $data = DbRow($week_SQL, $database, $con); // same function as described above returns assoc array // format date for display $datef = date('M-d', $end); // add to the array $week_data[] = array("week" => $end, "weekf" => $datef, "total" => $data['total']); } // end foreach ($week_date) This is not working properly. As shown in the attached gif labeled "14 WEEKS" it is only finding 9 records for this week and 2 for last week. All 59 records were entered in the last 2 weeks. Last, I try to grab the last 12 months and their first and last seconds in UNIX timestamps. // build an array for the last 12 months for ($m = 11; $m >= 0; $m--) { $month_date[] = strtotime("-$m months", $current_date); } // end date array: months // monthly totals foreach ($month_date as $end) { // $end is really the end of month, so let's get the first of the month $endymdhis = date('Y-m-d H:i:s', $end); $start = strtotime("- 1 month", $endymdhis);// this line gives me an error of "A non well formed numeric value encountered " when I have debugging on. I don't really know what that means but thought I should mention it. $startymdhis = date('Y-m-d H:i:s', $start); $start = strtotime("+ 1 day", $startymdhis); // query for the data $month_SQL = sprintf("SELECT count(complete = 'yes') as total FROM " . $tableName . " WHERE timestampUNIX >= %s AND timestampUNIX <= %s", $start, $end); $data = DbRow($month_SQL, $database, $con); // same function as before, returns assoc array // format the date as we'll print it out $datef = date('M \'y', $end); // add to the array $month_data[] = array("month" => $end, "monthf" => $datef, "total" => $data['total']); } // end foreach ($month_date) A third attachment, labeled "12 MONTHS" shows that this is only seeing 7 records this month and none for last month, when all 59 records were entered this month or last. Where have I gone wrong with my methods? I'm sure there are easier or less round-about ways to get the timestamps that I need. I just can't figure out what those easier ways are, LOL. In addition to the fact that I'm mostly likely making this harder than it needs to be, I'm not even getting the right data. To sum this up, what I need is: UNIX timestamps for the first and last second (00:00:01 and 23:59:59) for each of the last 14 days UNIX timestamps for the first and last second for each of the last 14 weeks UNIX timestamps for the first and last second for each of the last 12 months so that I can use these values to query the db for all records between those dates THANKS SO MUCH!!! [attachment deleted by admin]
  7. Yep, my ignorance made that whole thing WAY too complicated. Thanks for sticking with me on that, I learned a lot! When would I want to use GROUP BY ?
  8. They should come up just as in the previous post. The actual records are pretty randomly distributed. Basically the user can pick 3 criteria for sorting/grouping. Each option could be several different things - this will let them create a "custom" query. So I need the results to group by $sort_option_1, the group/sort by $sort_option_2, and then order by $sort_option_3 as shown in the example in my previous post. My example was only one possibility because the client could group by groupname, date, or lastname, then by (one of the remaining 2 options), and then by the third option. And the client can also choose ASC or DESC for each of the options. Does that make sense at all? Thanks !
  9. I don't know that I need to GROUP on one column. I didn't know *what* I need to be doing, LOL. If I GROUP BY the first column, and then sort by 2 columns, will they do what I basically want? i.e., GROUP BY groupname ASC ORDER BY mydate DESC, lname ASC would produce something that looks like this: 1001 | 2010-04-30 | abc 1001 | 2010-04-30 | bcd 1001 | 2010-04-29 | ghi 1001 | 2010-04-29 | hij ... ... 1002 | 2010-04-30 | rst 1002 | 2010-04-30 | stu 1002 | 2010-04-29 | xyz 1002 | 2010-04-29 | yza ...etc... because this is also not giving me consistent results (which is why I started trying grouping by 2 columns, lol) Thanks!
  10. The php vars from the original posts, when put together, result in (for example) the following SQL statement: SELECT * FROM tblName WHERE groupname=1002 AND UNIXdatetime>=1270450801 AND UNIXdatetime<=1272351599 And this is returning the expected rows (i.e., 30 rows like this:) Array ( [pk_recordID] => 19 [lname] => lastname [groupname] => 1002 [mydate] => 2010-04-26 [uNIXdatetime] => 1272266174 ) So. I know it's working up through my WHERE statement. I've been trying something like this: My last attempt: SELECT * FROM tblName WHERE groupname=1002 AND UNIXdatetime>=1270450801 AND UNIXdatetime<=1272351599 GROUP BY groupname ASC, mydate DESC ORDER BY lname ASC but it's not giving me the results I need. The query I just wrote is intended (although obviously failing) to give me 30 results. Result of that sql should be grouped first by groupname (there are 30 records total, with 10 each for groupname == 1002, 1003, and 1004). within each groupname (10 records) there are 5 dates (2 records per date). So within 1002, there should be 2 records listed as 2010-04-30, 2 records listed as 2010-04-29, etc. and the records should be grouped by these dates within the groupname groups. Within each of these groups of 2 records with the same date within the same groupname, the records should be sorted by lastname in ascending order. The results of my attempts are not coming back as expected. For example, I'm only getting 20 of the 30 records, and they are correctly grouped by ascending groupname, but the order of the date sorting does not change, and within the dates, the lastname is not sorting anything at all. If I try grouping first by date and then by group number, sorting last by lastname instead of groupname first and then date, I get all 30 results but the ASC and DESC doesn't do anything, groupname doesn't do anything, and lastname doesn't do anything... I feel like this should be fairly simple. I know that I've made this question much more difficult than it needed to be. A simplified version of my question is: How do I group by a column (ASC OR DESC depending on client input), group the records inside of each of those groups (ASC OR DESC depending on client input), and sort the records inside of each subgroup (ASC or DESC depending on client input).
  11. also by the way, this should say: $where = " WHERE "; the query up to that point $sql = $select . $where; is properly returning limited results as expected.
  12. By the way: MySQL: 5.1.x (not sure, think x=46?) PHP: 5.3.2 and Table: tblName Create Table: CREATE TABLE tblName ( pk_recordID INT(11) default NULL auto_increment, lastname char(60) default NULL, groupname int(4) default NULL, UNIXdatetime int(12) default NULL, mydate date default NULL, PRIMARY KEY (pk_recordID) ) ENGINE=MyISAM NOTE: the column mydate above is what I called "date" in the original post. YYYY-MM-DD corresponding to the UNIX stamp. thanks again!
  13. Okay, so this may be so much more simple than I am finding it to be, but I just can't wrap my head around what I need to be doing here. I have records in a database, and only a few fields are relevant here. table = 'tblName' fields: (all variable names and column names have been made generic for clarity) pk_recordID lastname groupname UNIXdatetime date auto_increment integer string integer integer date 1 a 1001 1272266174 2010-04-30 ... etc I have a form that I should allow my client to create a 'custom' query to pull a batch of records. The query will select all fields, but the form gives them the following options limit to a start datetime which after processing is stored as a UNIX timestamp in $start_date limit to an end datetime which after processing is stored as a UNIX timestamp in $end_date if they don't select any dates, $start_date is set to the earliest UNIX value and $end_date is set to UNIX version of now() if they select only one date, the other is filled as just described. they may also limit the records to a certain groupname (which is an integer) if they don't choose a groupname in the form, it is not included in my where. here's what I've got for the where statement // create the select portion of the SQL $select = "SELECT * FROM tblName"; // create the where statement // start the where statement with a space $where = " "; $where_end = ""; if ($filter_group) { $where .= "groupname=".$filter_group." AND ("; $where_end = ")"; } $where .= "UNIXdatetime>=".$start_date." AND UNIXdatetime<=".$end_date.$where_end; I don't know that this is the best way to go about the first part, but there we are. Now for (what I think will be) GROUP BY and ORDER BY: The form gives the client 3 levels (first_sort, second_sort, third_sort) of sorting/grouping all with the same options (date ascending, date descending, lastname ascending, lastname descending, groupname ascending). the way I want this to happen is that the second sort option is 'nested in?' the first sorting option, and the third within the second so, for example, if the client selects: first_sort = groupname ascending second_sort = date descending third_sort = lastname ascending I want the results to be grouped first by groupname (1001, then 1002, then 1003, etc) but then within each groupname grouped by date (1272655073, 1272266174, 1272179667, etc) but then within each date, sort records by last name (a, b, c, etc) if the client only selects an option for the first sorting level, the records can be further sorted however the DB wishes. This seems like a simple GROUP BY statement if the client selects an option for both the first and second sorting level, the records can be further sorted however the DB wishes. This seems like a GROUP BY statement followed by an ORDER BY statement. This is where I get stuck. I can't wrap my head around what I need to do to get this part working with 3 sorting levels. I will probably just do a php check of the post vars to determine whether I need to group on 1, 2, or 3 options (and then produce different values for a grouping variable based on this check). My final query should built from these vars like this (at least the way I have envisioned this so far) $batch_SQL = $select . $where . $grouping; So, I haven't given the SQL a shot for the grouping because I just can't figure out what I need to do or even really how GROUP and ORDER work together. I've never used even used GROUP BY and have never needed to ORDER BY more than a single field. Thanks so much for your guidance/suggestions/etc! Hopefully I'm not being too much of an idiot here! Cheers, ~me
×
×
  • 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.