Jump to content

thomasw_lrd

Members
  • Posts

    71
  • Joined

  • Last visited

Everything posted by thomasw_lrd

  1. $sql = "INSERT INTO rc_subjects (report_card_id ,student_id, subject_id, report_card_column_1, report_card_column_2 , created_on ) VALUES ('$theRecordPeriod', '$stu_Id', '$stu_subject', mysql_real_escape_string($stud_book), '$studGL','$today' )";
  2. I finally fixed it. Here is the code if anybody is interested. I'm still not sure why it works like this. Any ideas would be appreciated. // output data rows if (isset($apptable['retarr']) && isset($apptable['retarr']['rs']) && count($apptable['retarr']['rs'])>0){ foreach ($apptable['retarr']['rs'] as $row=>$r){ if (is_numeric($row)){ //echo '<pre>'.print_r($r, true).'</pre>';exit; $cols=0; foreach ([b]$colarr[/b] as $col=>$c){ if (isset($colarr[$col])){ //echo '<pre>'.print_r($r, true).'</pre>';exit; $objPHPExcel->getActiveSheet()->SetCellValue($xlcols[$cols].$rows, $r[$col]); $objPHPExcel->getActiveSheet()->getStyle($xlcols[$cols].$rows, $r[$col])->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); $cols++; } } The bolded $colarr used to be $r.
  3. I'm having trouble with some foreach statements. I'm pretty sure I've narrowed it down to one foreach statement. Not sure where to go from here. // output column headers $rows=1; $cols=0; foreach ($colarr as $col){ //echo "<pre>"; print_r($col); echo "</pre>"; $text=str_replace("<br>", "\r\n", $col['desc']); $objPHPExcel->getActiveSheet()->SetCellValue($xlcols[$cols].$rows, $text); $objPHPExcel->getActiveSheet()->getStyle($xlcols[$cols].$rows)->getAlignment()->setWrapText(true); $objPHPExcel->getActiveSheet()->getStyle($xlcols[$cols].$rows)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); $cols++; } $rows++; // output data rows if (isset($apptable['retarr']) && isset($apptable['retarr']['rs']) && count($apptable['retarr']['rs'])>0){ foreach ($apptable['retarr']['rs'] as $row=>$r){ if (is_numeric($row)){ //echo '<pre>'.print_r($apptable).'</pre>';//exit; $cols=0; foreach ($r as $col=>$c){ if (isset($colarr[$col])){ //echo '<pre>'.print_r($colarr[$col]).'</pre>';//exit; //echo "this is xlcols: ".$xlcols[$cols].$rows; echo " "; //echo "This is col: ".$col; echo " "; //echo "This is r[col]: ".$r[$col]; echo "<br>"; $objPHPExcel->getActiveSheet()->SetCellValue($xlcols[$cols].$rows, $r[$col]); $objPHPExcel->getActiveSheet()->getStyle($xlcols[$cols].$rows, $r[$col])->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); $cols++; } } $rows++; } } } The first section (output column headers) prints column names to an excel spreadsheet. The next part (output data rows) puts the data in an excel spreadsheet. The problem I have is that the data rows don't match the header columns. I think this is because the array $colarr is not after the first foreach loop. I've tried to reset, asort, and sort to move it back to the beginning, but none of those worked. And this $reset_array_keys = array_values($numerically_indexed_array); Any suggestions on what I should do? Output of print_r($colarr[$col]). Array ( [dbcolumn] => tr_ngfg_statement_date [desc] => Ngfg Statement Date [align] => l [format] => [pdfalign] => L [pdfwidth] => [ajaxupdate] => y [ajaxdropdown] => [sort] => y [link] => [options] => [fttype] => none ) 1 Array ( [dbcolumn] => tr_transaction_reconciled_y_or_n [desc] => Reconciled [align] => l [format] => [pdfalign] => L [pdfwidth] => [ajaxupdate] => [ajaxdropdown] => [sort] => y [link] => [options] => [fttype] => none ) 1 Array ( [dbcolumn] => tr_priority_level [desc] => Priority Level [align] => l [format] => [pdfalign] => L [pdfwidth] => [ajaxupdate] => y [ajaxdropdown] => [sort] => y [link] => [options] => [fttype] => none ) 1 Array ( [dbcolumn] => tr_id [desc] => ID [align] => l [format] => [pdfalign] => L [pdfwidth] => [ajaxupdate] => [ajaxdropdown] => [sort] => y [link] => [options] => [fttype] => none ) 1 Array ( [dbcolumn] => tr_decisioned_date [desc] => Decisioned Date [align] => l [format] => [pdfalign] => L [pdfwidth] => [ajaxupdate] => [ajaxdropdown] => [sort] => y [link] => [options] => [fttype] => none )
  4. What are you expecting it to print? Seems like we have similar problems. I'm running into the same sort of thing with printing out to excel.
  5. I'm using PHPExcel to output an excel file. My problem is that it is printing the data backwards. ID Priority 1 low 2 high 3 low But when it prints to excel via this function // output data rows if (isset($apptable['retarr']) && isset($apptable['retarr']['rs']) && count($apptable['retarr']['rs'])>0){ foreach ($apptable['retarr']['rs'] as $row=>$r){ if (is_numeric($row)){ //echo '<pre>'.print_r($r, true).'</pre>';exit; $cols=0; foreach ($r as $col=>$c){ if (isset($colarr[$col])){ //echo '<pre>'.print_r($r, true).'</pre>';exit; $objPHPExcel->getActiveSheet()->SetCellValue($xlcols[$cols].$rows, $r[$col]); $objPHPExcel->getActiveSheet()->getStyle($xlcols[$cols].$rows, $r[$col])->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); $cols++; } } $rows++; } It prints the data in reverse order ID Priority low 1 high 2 low 3 I've tried several troubleshooting techniques. When I echo out $r[$col] from this line I get the right data backwards. It prints low 1 high 2 low 3 in the first cell of my excel sheet. $objPHPExcel->getActiveSheet()->SetCellValue($xlcols[$cols].$rows, $r[$col]); I've tried not resetting $cols=0 and using $cols-- but I get an undefined . This leads me to believe that one of my foreach statements is wrong, but I'm not sure how to get anything useful out of them to see where it might be wrong. I've tried several echo "<pre>"; print_r(*); echo "</pre>"; statements where * is various array variables in my foreach statement. Any ideas on how to fix it? Or what I should try printing to the screen to see which statement is wrong?
  6. Craigslist. But I live in a fairly small metropolitan area, so there aren't a whole lot of freelances locally.
  7. I've been evaluating loggr.net to track users in my web app. So far I like it a lot. I heard about it on the Herding Code podcast. It allows you to post events to their server. Pretty easy to use. Does anybody else use any type of third party logging software that they have used or has anybody else used loggr?
  8. Anything by Billy Corgan of the Smashing Pumpkins. No matter what mood I'm in, he has a song to fit it.
  9. Just to be complete. Here is my code to dsiplay everything properly. function payments_section2($rec_id) { global $edit, $styles, $p; $ret=''; $sql = "SELECT tr_policy_number from transactions where tr_id = '$rec_id';"; $rs = myload($sql); $policy_number = $rs[0]['tr_policy_number']; $sql = "SELECT id, pay_date, pay_date_payment_recieved, pay_amount_recieved, pay_default FROM transactions_payments where pay_policy_number = '$policy_number' order by id;"; $rs = myload($sql); $ret.='<table class="listgrid"> <tr class="listrow"> <th class="listgrid">Monthly Payment</th> <th class="listgrid">Date Payment Recieved</th> <th class="listgrid">Amount Received</th> <th class="listgrid">Defaulted</th> </tr>'; if (count($rs)>0) { foreach ($rs as $r) { $sql = "SELECT pay_date as pay_date".$r['id'].", pay_date_payment_recieved as pay_date_payment_recieved".$r['id'].", pay_amount_recieved as pay_amount_recieved".$r['id'].", pay_default as pay_default".$r['id']." FROM transactions_payments where pay_policy_number = '$policy_number' and id = ".$r['id']." order by id;"; $rdrs = myload($sql); if (count($rdrs)>0){ if (count($rdrs)>0){ $x=$rdrs[0]; } $ret.= '<tr class="listrow"> <td class="listgrid">'.$r['pay_date'].'</td> <td class="listgrid">'.display_field('', $x,'pay_date_payment_recieved'.$r['id'], $styles['osreqdate']).'</td> <td class="listgrid">'.display_field('', $x,'pay_amount_recieved'.$r['id'], $styles['osreqstring']).'</td> <td class="listgrid">'.display_field('', $x,'pay_default'.$r['id'], $styles['osreqstring']).'</td> </tr>'; } //echo "rid:".$r['id'].":dir"; } $ret.='</table>'; } return $ret; } And here is the code that actually updates the records. if ($faction=='update' && $update_permission){ $sql="SELECT COUNT(".$table['key'].") FROM ".$table['name']." WHERE ".$table['key']."=".cleansql($rec_id); $rs=myload($sql); if ($rs[0][0]=='1'){ $vars=''; foreach ($_POST as $k=>$v){ if (isset($tablestructure[$k]) && stristr($tablestructure[$k]['Extra'], 'auto_increment')===false){ // edit for required non-null if ($tablestructure[$k]['Null']=='NO' && $v=='') $fieldeditproblems.=' - '.$k." IS EMPTY. IT CANNOT BE EMPTY.\n"; // edit for datetime fields if (($tablestructure[$k]['Type']=='datetime' || $tablestructure[$k]['Type']=='timestamp') && ($v<>'' && !is_date($v))) $fieldeditproblems.=' - '.$k." DOES NOT APPEAR TO BE A VALID DATE. IT MUST BE A VALID DATE.\n"; // edit for truncated varchars if (preg_match('/(?P<type>\w+)($|\((?P<length>(\d+|(.*)))\))/', $tablestructure[$k]['Type'], $matches) && $matches[1]=='varchar' && $matches['length']<strlen($v)) $fieldeditproblems.=' - '.$k." WILL TRUNCATE DATA. IT ONLY ALLOWS ".$matches['length']." CHARS, YET YOU HAVE ENTERED ".strlen($v).".\n"; $vars.=','.$k.'='.cleansql($v); } elseif (substr($k, 0, 4)=='pay_') { preg_match('/pay_date_payment_recieved(\d+)/', $k, $rdm); if (count($rdm)>0){ $pay_date=''; if (isset($_POST['pay_date'.$rdm[1]])) $pay_date=$_POST['pay_date'.$rdm[1]]; $pay_date_payment_recieved=''; if (isset($_POST['pay_date_payment_recieved'.$rdm[1]])) $pay_date_payment_recieved=$_POST['pay_date_payment_recieved'.$rdm[1]]; $pay_amount_recieved=''; if (isset($_POST['pay_amount_recieved'.$rdm[1]])) $pay_amount_recieved=$_POST['pay_amount_recieved'.$rdm[1]]; $pay_default=''; if (isset($_POST['pay_default'.$rdm[1]])) $pay_default=$_POST['pay_default'.$rdm[1]]; $sql = "UPDATE transactions_payments set pay_date_payment_recieved = '$pay_date_payment_recieved', pay_amount_recieved = '$pay_amount_recieved', pay_default = '$pay_default' where id = '".$rdm[1]."'"; $update_payment_table = myexecute($sql); } } } if ($fieldeditproblems==''){ $vars=substr($vars,1); $sql="UPDATE ".$table['name']." SET ".$vars." WHERE ".$table['key']."=".$rec_id; $updrs=myexecute($sql); $updatestatus='Record saved. '; } else { // we encountered field edit issues, don't even try insert $updatestatus="Record update not performed. The following field validation errors were found:<br><pre>".$fieldeditproblems."</pre>"; } } else { $updatestatus='Record NOT saved, no matching record was found. '; } }
  10. I've narrowed it down a little further. And just had an insight while typing this. My problem is, I'm selecting multiple records with the policy number. That is where I messed up. My underlying table structure is wrong. That is why it doesn't work. Thanks for all your help. I wouldn't have noticed this without thinking throught what both of you had told me.
  11. Thank you. I agree with the HTML statement, but I inherited this system from someone who is much more skilled than I am. It would take too much time to rewrite his code to match how I would do it. The problem with $rec_id is that is for our transactions table, it has nothing to do with this function. I'm trying to create a way to update a new table, transactions_payments. (I know it doesn't make any sense, my former boss was a businessman, who had a little coding and wanted it like this). Each transaction has a start date and an end date and we have to track the payments for every month. You have pointed me in the right direction. I was using the $x variable to display each record as an individual. Elsewhere in my code is this statement elseif (substr($k, 0, 4)=='pay_') { preg_match('/pay_date(\d+)/', $k, $rdm); if (count($rdm)>0){ $pay_date=''; if (isset($_POST['pay_date'.$rdm[1]])) $pay_date=$_POST['pay_date'.$rdm[1]]; echo $pay_date; echo "<br>"; $sql = "UPDATE transactions_payments set pay_date = '$pay_date' where id = '".$rdm[1]."'"; echo $sql; echo "<br>"; $update_payment_table = myexecute($sql); } } } This does the update correctly. But then the display code does not work. I had the display code working yesterday for one field, until I did the update code. Then the display code stopped working. Now I'm not sure how to get the update code to work. I think I can make it work with a bastardized (I hope that's okay to post, if not I'm sorry I will remove it) update button. But I didn't want to go that route. I actually have a version with two pages, one to do the display, and one to do the update. I'm just trying to make it all work on one page. I was hoping there was a "magic" answer, something stupid I had missed. Which there are several stupid things I have missed as has been posted above. Thanks for all the help so far.
  12. I have no good reason for it. None at all.
  13. I'm trying to reuse some code we had written to create an outstanding requirements table. The $x was used to update our secondary table.
  14. here's the whole function as it stands now. And I have attached the output as file. function payments_section2($rec_id) { global $edit, $styles, $p; $ret=''; $sql = "SELECT tr_policy_number from transactions where tr_id = '$rec_id';"; $rs = myload($sql); $policy_number = $rs[0]['tr_policy_number']; $sql = "SELECT id, pay_date, pay_date_payment_recieved, pay_amount_recieved, pay_default FROM transactions_payments where pay_policy_number = '$policy_number' order by id;"; //echo $sql; echo "<br>"; $rs = myload($sql); //echo "<pre>"; print_r($rs); echo "</pre>"; $ret.='<table class="listgrid"> <tr class="listrow"> <th class="listgrid">Monthly Payment</th> <th class="listgrid">Date Payment Recieved</th> <th class="listgrid">Amount Received</th> <th class="listgrid">Defaulted</th> </tr>'; if (count($rs)>0){ foreach ($rs as $r) { //echo "<pre>"; print_r($r); echo "</pre>"; $sql = "SELECT pay_date as pay_date".$r['id'].", pay_date_payment_recieved as pay_date_payment_recieved".$r['id'].", pay_amount_recieved as pay_amount_recieved".$r['id'].", pay_default as pay_default".$r['id']." FROM transactions_payments where pay_policy_number = '$policy_number' order by id;"; //echo $sql; echo "<br>"; $rdrs = myload($sql); $count = count($rdrs); if (count($rdrs)>0){ $ret.= '<tr class="listrow"> <td class="listgrid">'.$r['pay_date'].'</td> <td class="listgrid">'.display_field('', $rdrs[0],'pay_date_payment_recieved'.$r['id'], $styles['osreqdate']).'</td> <td class="listgrid">'.display_field('', $rdrs[0],'pay_amount_recieved'.$r['id'], $styles['osreqstring']).'</td> <td class="listgrid">'.display_field('', $rdrs[0],'pay_default'.$r['id'], $styles['osreqstring']).'</td> </tr>'; } //} } $ret.='</table>'; } return $ret; }
  15. So I've narrowed it down to the array inside the for loop. I need to make an array of all records, but this is not what is happening. It's overwriting the array, which is why I'm getting Aug 2016 outside the loop. I can't seem to get the concat to work though. $x.=$rdrs[$i]; It sorta works, but it adds the same record multiple times. Suggestions?
  16. Here is my output. nside for loop Array ( [0] => Jul-2016 [pay_date310511] => Jul-2016 [1] => 2012-01-12 [pay_date_payment_recieved310511] => 2012-01-12 [2] => 900.00 [pay_amount_recieved310511] => 900.00 [3] => No [pay_default310511] => No ) Inside for loop Array ( [0] => Aug-2016 [pay_date310511] => Aug-2016 [1] => [pay_date_payment_recieved310511] => [2] => [pay_amount_recieved310511] => [3] => [pay_default310511] => ) Outside for loop Array ( [0] => Aug-2016 [pay_date310511] => Aug-2016 [1] => [pay_date_payment_recieved310511] => [2] => [pay_amount_recieved310511] => [3] => [pay_default310511] => ) Inside for loop Array ( [0] => Jul-2016 [pay_date310512] => Jul-2016 [1] => 2012-01-12 [pay_date_payment_recieved310512] => 2012-01-12 [2] => 900.00 [pay_amount_recieved310512] => 900.00 [3] => No [pay_default310512] => No ) Inside for loop Array ( [0] => Aug-2016 [pay_date310512] => Aug-2016 [1] => [pay_date_payment_recieved310512] => [2] => [pay_amount_recieved310512] => [3] => [pay_default310512] => ) Outside for loop Array ( [0] => Aug-2016 [pay_date310512] => Aug-2016 [1] => [pay_date_payment_recieved310512] => [2] => [pay_amount_recieved310512] => [3] => [pay_default310512] =>
  17. I've got a problem I can't figure out and I could use some help. The array $x works fine inside the for loop, when I try to access it outside the for loop, It only contains the first record. myload is a custom function written by my predecessor to load up mysql records into an array. $rdrs = myload($sql); $count = count($rdrs); if (count($rdrs)>0){ for($i=0; $i<$count; $i++) { $x=$rdrs[$i]; //This works displays all records //echo "<pre>"; print_r($x); echo "</pre>"; } } //This doesnt, displays the same record. echo "<pre>"; print_r($x); echo "</pre>";
  18. Yes and no. Inside you're if statement you are posting the checkbox value. What you would want to do is something like this. //calculate costs if (isset($_POST['four100wattreg']) { //checkbox is checked $four100wattreg = 2.39; } else if (!isset($_POST['four100wattreg']) { //checkbox not checked $four100wattreg = 0; } I believe that is correct, but I could be wrong. I didn't test it. I'm sure some of the better programmers on here may have a better solution.
  19. $four100wattreg=2.39; You're using the same variables for the cost as the checkbox. You should rewrite them as $four100wattregcost. Also, this line echo "Your total is: '$sum' <br />" Should be echo "Your total is: ".$sum." <br />" Adding the dots is like concatenating it all into one big string.
  20. I would use javascript to check on client side. <script> function ValidateContactForm() { var name = document.ContactForm.first_name; var last_name = document.ContactForm.last_name; var phone = document.ContactForm.phone; var state = document.ContactForm.state; var email = document.ContactForm.email; var comment = document.ContactForm.comments; if (name.value == "") { window.alert("Please enter your first name."); email.focus(); return false; } if (last_name.value == "") { window.alert("Please enter a your last name."); email.focus(); return false; } if (phone.value == "") { window.alert("Please enter a valid phone number."); email.focus(); return false; } if (state.value == "") { window.alert("Please enter your state."); email.focus(); return false; } if (email.value == "") { window.alert("Please enter a valid e-mail address."); email.focus(); return false; } if (email.value.indexOf("@", 0) < 0) { window.alert("Please enter a valid e-mail address."); email.focus(); return false; } if (email.value.indexOf(".", 0) < 0) { window.alert("Please enter a valid e-mail address."); email.focus(); return false; } if (comments.value == "") { window.alert("Please enter a description or comment."); comment.focus(); return false; } return true; } </script> <form action="" name ='ContactForm' method='post' onsubmit="return ValidateContactForm();"> Something like that should work. It will pop up the error message.
  21. What he's saying is you're form doesn't do anything. You should look up form action= and make the form actually do something. form action = post? maybe?
  22. I copied the code from my production server. Can you explain a little further? It's working, so I'm not sure what I didn't close, but I would like to fix it. Not trying to highjack the thread by the way, just trying to learn.
  23. I was not aware of that. I inherited this system from someone who is much smarter than I am. I'm not even sure what the passwords to our system are. I did browse to the link though, and it worked. Luckily, our passwords were not stored there. Our config files for the website are actually stored in /etc/something/something.
  24. Something like this could work for($x=0; $x<=$items; $x++) { $id=$result[$x]['pol_id']; $thing=$result[$x]['pol_policy_number']; $options.="<OPTION VALUE=\"$id\">".$thing; } ?> Select a case number to see the payout approval. <br> <form action="approval.php" method='post'> <SELECT NAME=pol_policy_number> <?=$options?> </SELECT> <input name="Submit" type="submit" Value="Submit Policy Number"/> </form> <br> You'll have to put the count of an array in $items. And change the Policy information to match your database. As to your second quetions, Just use an include statement like include security.inc Security.inc would consist of the username and password.
×
×
  • 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.