-
Posts
67 -
Joined
-
Last visited
-
Days Won
1
Everything posted by SLSCoder
-
"update process is writing two separate characters": That's curious. I'll have to figure that out. I'm thinking when it's written into the db it gets escaped. It should show up as 2 lines yes? I'll find it and fix it. Thanks. "- the percent sign??": Sorry, I meant the HEX response looks like HTML codes without the percent sign. dechex(ord('%')); Thanks for that. I looked for how to do this for over 2 hours and never did find it.
-
gizmola thank you. I don't write each record to html on the server or use in line <?php ... ?> tags. I pass the whole thing (with more than just the recordset) to the client and write the html in Javascript. When I look at the example record having a line feed in the database (HeidiSQL) I see \n in the text: ie: "We chartered a \n fishing trip". No \r or \r\n exist in any records, only \n. It's a Linux server and no records are saved with \r in them. I tried your HEX suggestion. I get long numbers but don't understand what they indicate. The response I got for that record was this: text: we chartered a \n fishing trip. hex: 7765206368617274657265642061205C6E2066697368696E6720747269702E When I use this: $sql = "SELECT REPLACE(TextField, '\n', '<br>') AS TextField FROM mytable WHERE ID = 2"; The line feed breaks the line in php (I see in view-source) which makes me think mysql doesn't see it. Php runs it anyway and MySql ignores it. I break sql lines in PHP all the time just so I can read the sql. Mysql ignores them. I tried a double slash to escape it in php. It seemed to ignore that too and gave me the same result: ie: "We chartered a \n fishing trip". That's what I see in the browser. I changed the value in javascript val = val.replaceAll("\n", "<br>") and that didn't work either. I see in the database: we chartered a \n fishing trip I see in the browser: we chartered a \n fishing trip Now I'm confused
-
Am I missing something? If I understand your solution clearly, you're asking me why I don't want to loop through records to fix any values that include line breaks. My answer to that would obviously be that I think to fix the values in the query would be significantly more efficient than to loop through and fix each record after the query. If you don't want to answer my question please just say so. I'm beginning to think that asking questions on this forum is a bad idea.
-
I'm creating a sql statement in php: The value of TextField is "We chartered a \n fishing trip". $sql = "SELECT REPLACE(TextField, '\n', '<br>') AS TextField FROM mytable WHERE ID = 2"; I've tried every combination I can think of like 2 backslashes, 3, 4 . . . I tried using chr(92) instead of the backslash. I can't make it work. How can I get it to return the field (ex. TextField) with a br tag in it instead of a line feed?
-
PHP 8.1 How can I stop warning messages from displaying?
SLSCoder replied to SLSCoder's topic in PHP Coding Help
In view of this very ugly thread I've started using your solution every time I read a data array field. I actually use $arMine["NoField"]??'' with no spaces. It works well. It's a little messy (and it's gonna take forever to fix them all) but you guys win. Thanks Kicken -
PHP 8.1 How can I stop warning messages from displaying?
SLSCoder replied to SLSCoder's topic in PHP Coding Help
Thanks. I've got every one of your problems here covered. Your illusions about my code are unfounded and incorrect. This conversation is over. This forum did not help me - again. Thank you for your time. -
PHP 8.1 How can I stop warning messages from displaying?
SLSCoder replied to SLSCoder's topic in PHP Coding Help
I fear PHP has lost site of its objective. PHP is famous because it's EASY - less so anymore with every new version. More code is not generally a better solution. This looks like bloatware to me: if(isset($arMine["NoField"])) . That would be hundreds of cases many of which are html input field values. This is a *little* better: $arMine["NoField"] ?? '' Thanks. I may even use this. ginerjm: Thanks for your responses. If I *want* warnings I would have no problem displaying them. If I'm in production and my users encounter a bug I've gotta fix it. So if I need warnings I just turn them on. I need to be ABLE to shut them off and always could. It doesn't work anymore. I don't know why. I've explained what I did. 'ALL php code' - as I stated above, all my files require_once a session file which handles that and a lot of other stuff for every page in the app. If I upgrade PHP it's a BIG move. PHP demolishes my code with every single new version (in the old days upgrades were better not destructive). That to say it happens first on a dev site and once re-debugged can be used in production. Of course debugging may well include the need to see warnings. webdeveloper123: Thanks for your response. I don't want the warnings to EVER show up unless I want them. That because I don't want to have to write code to cover every single case where I use a (maybe non-existent) field value in a data array. -
PHP 8.1 How can I stop warning messages from displaying?
SLSCoder replied to SLSCoder's topic in PHP Coding Help
OK, thanks anyway. -
PHP 8.1 How can I stop warning messages from displaying?
SLSCoder replied to SLSCoder's topic in PHP Coding Help
I know but it's just a pain in pretty near every interface. I store db fields in the same array as page functionality fields - sometimes. A given field (usually a functionality field) may or may not be in the array. If not, I just want an empty string. The solve is if(isset($arMine["NoField"])) ... For the field that threw the error I needed to debug I did that so it's fixed. In general ... not really. I'd rather lose the warnings. Is there no way to actually stop warnings from displaying? -
I'm running PHP 8.1 in Apache2 on a Debian server. I need PHP to display error messages but not warning messages. I've got 2 config files, cli & fpm. I'm not sure which one Apache2 is using. Both have error_reporting set like this: error_reporting = E_ALL & ~E_WARNING & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT Moreover, every time a page loads session code loads with it. At the top of my page: SessionHandler.php is this: error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT); I've also tried changing it to this: error_reporting(E_ALL & ^ E_WARNING & ^ E_NOTICE & ^ E_DEPRECATED & ^ E_STRICT); Still the warning messages display. I've got a habit of trying to display values in associative arrays where the key doesn't exist. PHP throws a warning up for doing this: Warning: Undefined array key "ScpFeatureBundleID" How can I get rid of this warning without stopping errors from displaying?
-
Why can't I access the fonts directory from PHP?
SLSCoder replied to SLSCoder's topic in PHP Coding Help
Thanks. open_basedir is not set. It's remmed out. I saw that on stackoverflow. You were right /var/log Nothing in there. I wonder why it wouldn't access /usr/share. -
Why can't I access the fonts directory from PHP?
SLSCoder replied to SLSCoder's topic in PHP Coding Help
OK, I moved the fonts to /var/www/fonts/truetype and set ownership & group to www-data. The permissions look right. JpGraph seems to be happy now. Funny though, the JpGraph default path was /usr/share/fonts/truetype which is what sent me down that trail. I just didn't realize that you can't access any folder on the server from a PHP website. It's fixed now. Thanks. -
Why can't I access the fonts directory from PHP?
SLSCoder replied to SLSCoder's topic in PHP Coding Help
It's my box. It's a standard debian apache 2 installation. All the sites are in /var/www/ Where are the PHP error logs? What does "bundle it into your application's codebase" mean? Multiple sites; multiple PHP apps will need access to the fonts. -
Why can't I access the fonts directory from PHP?
SLSCoder replied to SLSCoder's topic in PHP Coding Help
Then is it impossible to access folders outside the domain root from the website like /usr/share/ ? I'm accessing multiple folders in /var/www/ for things like PHPWord, JpGraph, etc. They're accessible to all the domains I run. In fact, the app that needs the fonts is JpGraph. <?php echo "Root: {$_SERVER['DOCUMENT_ROOT']}<br>"; if(file_exists("/usr/share/fonts/truetype/verdana.ttf")) echo "file exists<br>"; else echo "file does NOT exist<br>"; $file = file_get_contents("/usr/share/fonts/truetype/verdana.ttf"); if($file === false) echo "no file<br>"; else echo $file . "<br>"; -
Why can't I access the fonts directory from PHP?
SLSCoder replied to SLSCoder's topic in PHP Coding Help
It is not part of the domain. I don't see why that'd matter. Root: /var/www/dev.aecperformance.com file does NOT exist no file -
Why can't I access the fonts directory from PHP?
SLSCoder replied to SLSCoder's topic in PHP Coding Help
Thanks. I can't believe I didn't see that! It didn't work though. So, now my code is: if(file_exists("/usr/share/fonts/truetype/verdana.ttf")) echo "file exists<br>"; else echo "file does NOT exist<br>"; $file = file_get_contents("/usr/share/fonts/truetype/verdana.ttf"); if($file === false) echo "no file<br>"; else echo $file . "<br>"; The response is still: file does NOT exist no file Also, when I showed errors none appeared. -
I'm trying to access a font file: usr/share/fonts/truetype/verdana.ttf As you can see the file does exist and owner, group and public have permissions to read it. It is owned by root not www-data but I can't see how that's a problem if public has read permissions. My code: if(file_exists("usr/share/fonts/truetype/verdana.ttf")) echo "file exists<br>"; else echo "file does NOT exist<br>"; $file = file_get_contents("usr/share/fonts/truetype/verdana.ttf"); if($file === false) echo "no file<br>"; else echo $file . "<br>"; returns: file does NOT exist no file How can I make my fonts in usr/share/fonts/truetype/ accessible to PHP?
-
How can I generate charts in php server-side?
SLSCoder replied to SLSCoder's topic in Other Libraries
I can't believe it. What did you google? I tried a few things. The last was this: php charts -javascript -jquery I don't suppose you could come up with an open-source version for commercial use?? Thanks. Also, how can I code my own charts? I'd be interested in that. If you could point me in a direction that would help. -
How can I generate charts (bar, line pie, donut) in php that will create files (jpg, png, svg, ...) or base64 on the server? Does a library exist (preferably open source) that can do it? If not is there a service that I can connect to via cURL? I'm trying to export reports from php in various formats (PHPWord, PHPSpreadsheet, PHPPresentation, mPDF, HTML) that will include charts. The html must be basic html (no scripting) and runnable without an internet connection; just a report.
-
gizmola, again thanks for your response. I am looking for ways to speed the app up so this is clearly something I'm going to have to study and implement. I'll look into Redis and learn what it will take to use it and where in my app it will help. Thanks again.
-
I'm almost scared to ask this because I kind of expect you guys to chew me to bits - lol - but I have to try and find out. I have to be able to reasonably handle 50,000 records total (1 = Count + AvgX + AvgY) from this set of queries. I can't think of a better way to do it and it works fine with a few records (13 surveys total in the initial tests) but I'm concerned about it being efficient enough with more records. I'm wondering if putting it all into a stored proc would speed it up. I don't like stored procs. I prefer the code to be in my server side language (PHP in this case). If I have to change the database server stored procs make the job bigger, I have to rewrite all that code. The records are the Total count, Total X Avg, Total Y Avg and the Counts and the X and Y averages for each cell. The WHERE clauses are pretty straight forward; generally just a filter for answers.QuestionID and maybe a few other answers table fields. The FILTER can include combinations of any fields from the surveys and/or answers table. The FILTER params come from a client side form so must be protected from sql injection - thus PDO. $arParams is an array of the FILTER params. Here, I'm building a cross tab report for 2 params (ie QuestionID: 134 and QuestionID 78) in numeric ranges given: Min1 to Max1 by Interval1, Min2 to Max2 by Interval2. I know this is pretty complicated. If it's too much don't worry about it. Like I said, this code works, it's just an awful lot of queries so I suspect with a lot of records it'll be slow. //Get Total Count and Total X and Y averages try { $sql = "SELECT COUNT(DISTINCT surveys.RecordID) AS Cnt FROM answers INNER JOIN surveys ON answers.SurveyID = surveys.RecordID WHERE surveys.RecordID IN (SELECT SurveyID FROM answers WHERE " . $Where1 . ") AND surveys.RecordID IN (SELECT SurveyID FROM answers WHERE " . $Where2 . ")"; if(!empty($Filter)) $sql .= " AND " . $Filter; $ar = $this->executePDOQuery($sql, $arParams); $Total = $ar[0]["Cnt"]; $sql = "SELECT AVG(" . $DataFld1 . ") AS Avg FROM answers INNER JOIN surveys ON answers.SurveyID = surveys.RecordID WHERE " . $Where1 . " AND surveys.RecordID IN (SELECT SurveyID FROM answers WHERE " . $Where2 . ")"; if(!empty($Filter)) $sql .= " AND " . $Filter; $ar = $this->executePDOQuery($sql, $arParams); if(is_numeric($ar[0]["Avg"])) $TotalXAvg = round($ar[0]["Avg"], 1); else $TotalXAvg = ""; $sql = "SELECT AVG(" . $DataFld2 . ") AS Avg FROM answers INNER JOIN surveys ON answers.SurveyID = surveys.RecordID WHERE surveys.RecordID IN (SELECT SurveyID FROM answers WHERE " . $Where1 . ") AND " . $Where2; if(!empty($Filter)) $sql .= " AND " . $Filter; $ar = $this->executePDOQuery($sql, $arParams); if(is_numeric($ar[0]["Avg"])) $TotalYAvg = round($ar[0]["Avg"], 1); else $TotalYAvg = ""; } catch(Exception $exp) { throw new Exception("Error in daRptStatsAnly.getCmp1n1Data 2: " . $exp->getMessage() . "<br>" . $sql); } //Get First X & First & Count and XAvg and YAvg try { $sqlA1 = "SELECT COUNT(DISTINCT surveys.RecordID) AS Cnt FROM answers INNER JOIN surveys ON answers.SurveyID = surveys.RecordID WHERE surveys.RecordID IN (SELECT SurveyID FROM answers WHERE " . $Where1 ." AND " . $DataFld1 . " < " . $CurMax1 . ")"; $sqlA = $sqlA1 . " AND surveys.RecordID IN (SELECT SurveyID FROM answers WHERE " . $Where2 . " AND " . $DataFld2 . " < " . $CurMax2 . ")"; if(!empty($Filter)) $sqlA .= " AND " . $Filter; $ar = $this->executePDOQuery($sqlA, $arParams); $arRec = []; $arRec["Cnt"] = $ar[0]["Cnt"]; if($arRec["Cnt"] > $MaxCnt) $MaxCnt = $arRec["Cnt"]; $sqlB1 = "SELECT AVG(" . $DataFld1 . ") AS Avg FROM answers INNER JOIN surveys ON answers.SurveyID = surveys.RecordID WHERE " . $Where1 . " AND " . $DataFld1 . " < " . $CurMax1; $sqlB = $sqlB1 . " AND surveys.RecordID IN (SELECT SurveyID FROM answers WHERE " . $Where2 . " AND " . $DataFld2 . " < " . $CurMax2 . ")"; if(!empty($Filter)) $sqlB .= " AND " . $Filter; $ar = $this->executePDOQuery($sqlB, $arParams); if(is_numeric($ar[0]["Avg"])) { $arRec["XAvg"] = round($ar[0]["Avg"], 1); if($arRec["XAvg"] > $MaxXAvg) $MaxXAvg = $arRec["XAvg"]; } else $arRec["XAvg"] = "n/a"; $sqlC1 = "SELECT AVG(" . $DataFld2 . ") AS Avg FROM answers INNER JOIN surveys ON answers.SurveyID = surveys.RecordID WHERE surveys.RecordID IN (SELECT SurveyID FROM answers WHERE " . $Where1 ." AND " . $DataFld1 . " < " . $CurMax1 . ")"; $sqlC = $sqlC1 . " AND " . $Where2 . " AND " . $DataFld2 . " < " . $CurMax2; if(!empty($Filter)) $sqlC .= " AND " . $Filter; $ar = $this->executePDOQuery($sqlC, $arParams); if(is_numeric($ar[0]["Avg"])) { $arRec["YAvg"] = round($ar[0]["Avg"], 1); if($arRec["YAvg"] > $MaxYAvg) $MaxYAvg = $arRec["YAvg"]; } else $arRec["YAvg"] = "n/a"; } catch(Exception $exp) { throw new Exception("Error in daRptStatsAnly.getCmp1n1Data 2: " . $exp->getMessage() . "<br>" . $sql); } $arData[$idxX] = []; $arData[$idxX][$idxY] = $arRec; $YLabels[$idxY] = $CurMin2 . " to < " . $CurMax2; $XLabels[$idxX] = $CurMin1 . " to < " . $CurMax1; //Get First X and Remaining Y Count and Averages while($CurMax2 <= $Max2) { $idxY++; $CurMin2 = $CurMax2; $CurMax2 = $CurMin2 + $Interval2; try { $sqlA = $sqlA1 . " AND surveys.RecordID IN (SELECT SurveyID FROM answers WHERE " . $Where2 . " AND " . $DataFld2 . " >= " . $CurMin2 . " AND " . $DataFld2 . " < " . $CurMax2 . ")"; if(!empty($Filter)) $sqlA .= " AND " . $Filter; $ar = $this->executePDOQuery($sqlA, $arParams); $arRec = []; $arRec["Cnt"] = $ar[0]["Cnt"]; if($arRec["Cnt"] > $MaxCnt) $MaxCnt = $arRec["Cnt"]; $sqlB = $sqlB1 . " AND surveys.RecordID IN (" . $Where2 . " AND " . $DataFld2 . " >= " . $CurMin2 . " AND " . $DataFld2 . " < " . $CurMax2 . ")"; if(!empty($Filter)) $sqlB .= " AND " . $Filter; $ar = $this->executePDOQuery($sqlB, $arParams); if(is_numeric($ar[0]["Avg"])) { $arRec["XAvg"] = round($ar[0]["XAvg"], 1); if($arRec["XAvg"] > $MaxXAvg) $MaxXAvg = $arRec["XAvg"]; } else $arRec["XAvg"] = "n/a"; $sqlC = $sqlC1 . " AND " . $DataFld2 . " >= " . $CurMin2 . " AND " . $DataFld2 . " < " . $CurMax2 ; if(!empty($Filter)) $sqlC .= " AND " . $Filter; $ar = $this->executePDOQuery($sqlC, $arParams); if(is_numeric($ar[0]["Avg"])) { $arRec["YAvg"] = round($ar[0]["Avg"], 1); if($arRec["YAvg"] > $MaxYAvg) $MaxYAvg = $arRec["YAvg"]; } else $arRec["YAvg"] = "n/a"; } catch(Exception $exp) { throw new Exception("Error in daRptStatsAnly.getCmp1n1Data 2: " . $exp->getMessage() . "<br>" . $sql); } $arData[$idxX][$idxY] = $arRec; $YLabels[$idxY] = $CurMin2 . " to < " . $CurMax2; } $Max2 = round($Max2); if($CurMax2 > $Max2) $YLabels[$idxY] = $CurMin2 . " to " . $Max2; //Get remaining X Counts & for each, First X and Y Average while($CurMax1 <= $Max1) { $CurMin2 = $Min2; $CurMax2 = $CurMin2 + $Interval2; $CurMin1 = $CurMax1; $CurMax1 = $CurMin1 + $Interval1; $idxX++; $idxY = 0; $arData[$idxX] = []; try { $sqlA1 = "SELECT COUNT(DISTINCT surveys.RecordID) AS Cnt FROM answers INNER JOIN surveys ON answers.SurveyID = surveys.RecordID WHERE surveys.RecordID IN (SELECT SurveyID FROM answers WHERE " . $Where1 . " AND " . $DataFld1 . " >= " . $CurMin1 ." AND " . $DataFld1 . " < " . $CurMax1 . ")"; $sqlA = $sqlA1 . " AND surveys.RecordID IN (SELECT SurveyID FROM answers WHERE " . $Where2 . " AND " . $DataFld2 . " < " . $CurMax2 . ")"; if(!empty($Filter)) $sqlA .= " AND " . $Filter; $ar = $this->executePDOQuery($sqlA, $arParams); $arRec = []; $arRec["Cnt"] = $ar[0]["Cnt"]; if($arRec["Cnt"] > $MaxCnt) $MaxCnt = $arRec["Cnt"]; $sqlB1 = "SELECT AVG(" . $DataFld1 . ") AS Avg FROM answers INNER JOIN surveys ON answers.SurveyID = surveys.RecordID WHERE " . $Where1 . " AND " . $DataFld1 . " >= " . $CurMin1 ." AND " . $DataFld1 . " < " . $CurMax1; $sqlB = $sqlB1 . " AND surveys.RecordID IN (SELECT SurveyID FROM answers WHERE " . $Where2 . " AND " . $DataFld2 . " < " . $CurMax2 . ")"; if(!empty($Filter)) $sqlB .= " AND " . $Filter; $ar = $this->executePDOQuery($sqlB, $arParams); if(is_numeric($ar[0]["Avg"])) { $arRec["XAvg"] = round($ar[0]["Avg"], 1); if($arRec["XAvg"] > $MaxXAvg) $MaxXAvg = $arRec["XAvg"]; } else $arRec["XAvg"] = "n/a"; $sqlC1 = "SELECT AVG(" . $DataFld2 . ") AS Avg FROM answers INNER JOIN surveys ON answers.SurveyID = surveys.RecordID WHERE surveys.RecordID IN (SELECT SurveyID FROM answers WHERE " . $Where1 . " AND " . $DataFld1 . " >= " . $CurMin1 ." AND " . $DataFld1 . " < " . $CurMax1 . ")"; $sqlC = $sqlC1 . " AND " . $Where2 . " AND " . $DataFld2 . " < " . $CurMax2 ; if(!empty($Filter)) $sqlC .= " AND " . $Filter; $ar = $this->executePDOQuery($sqlC, $arParams); if(is_numeric($ar[0]["Avg"])) { $arRec["YAvg"] = round($ar[0]["Avg"], 1); if($arRec["YAvg"] > $MaxYAvg) $MaxYAvg = $arRec["YAvg"]; } else $arRec["YAvg"] = "n/a"; } catch(Exception $exp) { throw new Exception("Error in daRptStatsAnly.getCmp2NumData: " . $exp->getMessage() . "<br>" . $sql); } $arData[$idxX][$idxY] = $arRec; //Get Counts & Averages for Remaining Y while($CurMax2 <= $Max2) { $idxY++; $CurMin2 = $CurMax2; $CurMax2 = $CurMin2 + $Interval2; try { $sqlA = $sqlA1 . " AND surveys.RecordID IN (SELECT SurveyID FROM answers WHERE " . $Where2 . " AND " . $DataFld2 . " >= " . $CurMin2 . " AND " . $DataFld2 . " < " . $CurMax2 . ")"; if(!empty($Filter)) $sqlA .= " AND " . $Filter; $ar = $this->executePDOQuery($sqlA, $arParams); $arRec = []; $arRec["Cnt"] = $ar[0]["Cnt"]; if($arRec["Cnt"] > $MaxCnt) $MaxCnt = $arRec["Cnt"]; $sqlB = $sqlB1 . " AND surveys.RecordID IN (SELECT SurveyID FROM answers WHERE " . $Where2 . " AND " . $DataFld2 . " >= " . $CurMin2 . " AND " . $DataFld2 . " < " . $CurMax2 . ")"; if(!empty($Filter)) $sqlB .= " AND " . $Filter; $ar = $this->executePDOQuery($sqlB, $arParams); if(is_numeric($ar[0]["Avg"])) { $arRec["XAvg"] = round($ar[0]["Avg"], 1); if($arRec["XAvg"] > $MaxXAvg) $MaxXAvg = $arRec["XAvg"]; } else $arRec["XAvg"] = "n/a"; $sqlC = $sqlC1 . " AND " . $Where2 . " AND " . $DataFld2 . " >= " . $CurMin2 . " AND " . $DataFld2 . " < " . $CurMax2; if(!empty($Filter)) $sqlC .= " AND " . $Filter; $ar = $this->executePDOQuery($sqlC, $arParams); if(is_numeric($ar[0]["Avg"])) { $arRec["YAvg"] = round($ar[0]["Avg"], 1); if($arRec["YAvg"] > $MaxYAvg) $MaxYAvg = $arRec["YAvg"]; } else $arRec["YAvg"] = "n/a"; } catch(Exception $exp) { throw new Exception("Error in daRptStatsAnly.getCmp2NumData: " . $exp->getMessage() . "<br>" . $sql); } $arData[$idxX][$idxY] = $arRec; } }
-
gizmola thanks for your response. If I understand memcached correctly it won't help me. The data is constantly changing, it's not static at all.
-
OK thanks. I'll make that a preference as well.