Ternary operator error with include () function [closed] - ternary-operator

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
include ( $_GET['p'] == 'home') ? 'pages/home.php' : NULL;
gives the error:
Notice: Undefined index: p in /var/www/index.php on line 38
Warning:
require(): Filename cannot be empty in /var/www/index.php on line 38
Fatal error: require(): Failed opening required ''
(include_path='.:/usr/share/php:/usr/share/pear') in
/var/www/index.php on line 38
I understand the undefined index, but why am I getting the other errors? This line:
include ( !isset($_GET['p'])) ? 'pages/home.php': NULL;
works fine. Note that the first code will work fine in an if statement (apart from the undefined index, which I understand)

include expects a string that represents the path to the file that is to be included. So NULL will get converted to string that results in an empty string. And consequently including a file referenced by an empty string results in a warning.
Simply use an if instead:
if (!isset($_GET['p'])) {
include 'pages/home.php';
}

Please don't do that! Try something like this instead:
(isset($_GET['p']) && $_GET['p'] === 'home') ? include 'pages/home.php' : '';

Related

React/Node/Express/Webpack -A valid React element (or null) must be returned

link to source code: https://github.com/manster829/MernStackT
I keep getting the error message: Uncaught Error: BugTable.render(): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.
I have no idea why, I thought this might have something to do with ES6 or my syntax, but I can't get it. Anyone have any ideas? Thanks :)
This is kind of silly but you need to move you ( next to your return statement, otherwise you actually return undefined and break out of the function. When you don't have anything next to a return statement javascript assumes you mean to simply return ...
Try this in BugTable.js:
return (
<div>The list of bugs as a table would come here.</div>
);

syntax error, unexpected '&&' (T_BOOLEAN_AND), expecting ')' in opencart when clicking on customer

No idea what it means as am not a developer. I do have access to a HTML editor (DW) so could change if told what to do.
I get this error when I click on customer in my admin Opencart.
Parse error: syntax error, unexpected '&&' (T_BOOLEAN_AND), expecting ')' in /var/sites/p/proteinporridgewales.co.uk/public_html/cart/admin/controller/customer/customer.php on line 1105
Thanks in advance
Its a mistake in opencart 2.2.0.0. THey have updated their master repository. You can also do this directly. Here is the solved line 1105 of admin/controller/customer/customer.php
Replace with this line
} elseif (($custom_field['type'] == 'text' && !empty($custom_field['validation']) && $custom_field['location'] == 'address') && !filter_var($this->request->post['custom_field'][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) {
You can visit this for more details.
parentheses in the wrong place ... change
!empty($custom_field['validation'] && $custom_field['location'] == 'address'))
to
!empty($custom_field['validation']) && $custom_field['location'] == 'address')
I have figure out the problem, it is the problem with the "else if" part on error line 1105, which I have removed, just have lived the if statement leaving the closing brackets.
so that I have get rid of the error and can able to see the customer page.

Illegal string offset 'handler' in PHP [duplicate]

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
Please how can I correct this error:
Warning: Illegal string offset 'handler' in /home/***************/public_html/whois/phpwhois/whois.gtld.php on line 95
on the following code:
function parse($data, $query)
{
$this->Query = array();
$this->SUBVERSION = sprintf("%s-%s", $query["handler"], $this->HANDLER_VERSION);
$this->result = generic_parser_b($data["rawdata"], $this->REG_FIELDS, 'dmy');
Please check if $query is a string if it is then the code will not work. Make sure you pass $enquiry as an array or fire an exception.

NaN Node.Js Callback Issue

I've been fumbling around with this issue for what has seemed like weeks,
and I cannot get the issue resolved.
I spent days trying to get to where I can be able to call the actual function outside of the original .js file.
All I want to be able to do in node.js is create a function that will be able to generate a random number within a specific parameters such as (1-10 or 1-100), and relay it back to the console or a variable specified by the user.
This is the current code that I have:
server.js
var myModule = require("./my_module.js");
console.log("your random number is" + myModule.hello(10)); //<-- the 10 represents the TOP number that will generate, if you look in the proceeding file, it adds a 1 to it as required by the code
my_module.js
function hello(foo) {
return Math.floor((Math.random()*foo)+1);
}
module.exports.hello = hello;
The issue that underlines here is i get a NaN, ( not a number ) from the console.
I realize that this means somewhere in translation, the number may be turning into a string and not being able to be read by the mathFloor string.
You can use the jQuery method isNumeric to validate whether they gave you a number. http://api.jquery.com/jQuery.isNumeric/
To make sure it is still a number and you didn't inadvertently make it a string, use parseInt() or parseFloat().
function hello(foo) {
return Math.floor((Math.random()*parseInt(foo))+1);
}
While Erik's answer solves the problem, it won't tell you where the string is coming from. You can use console.trace to make your debugging life easier.
function hello(foo) {
var result = Math.floor((Math.random()*parseInt(foo))+1);
if (isNaN(result)) {
console.trace("result is NaN")
}
return result;
}
> hello("a")
Trace: NaN
at hello (repl:4:9)
at repl:1:2
at REPLServer.self.eval (repl.js:109:21)
at Interface.<anonymous> (repl.js:248:12)
at Interface.EventEmitter.emit (events.js:96:17)
at Interface._onLine (readline.js:200:10)
at Interface._line (readline.js:518:8)
at Interface._ttyWrite (readline.js:736:14)
at ReadStream.onkeypress (readline.js:97:10)
at ReadStream.EventEmitter.emit (events.js:126:20)
at emitKey (readline.js:1058:12)
at ReadStream.onData (readline.js:807:7)
NaN
>
By looking at the stack trace you will be able to find the code that provided a non-Number parameter.

Looking for resources for ICD-9 codes [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
We have been asked by a client to incorporate ICD-9 codes into a system.
I'm looking for a good resource to get a complete listing of codes and descriptions that will end up in a SQL database.
Unfortunately a web service is out of the question as a fair amount of the time folks will be off line using the application.
I've found http://icd9cm.chrisendres.com/ and http://www.icd9data.com/ but neither offer downloads/exports of the data that I could find.
I also found http://www.cms.hhs.gov/MinimumDataSets20/07_RAVENSoftware.asp which has a database of the ICD-9 codes but they are not in the correct format and I'm not 100% sure how to properly convert (It shows the code 5566 which is really 556.6 but I can't find a rule as to how/when to convert the code to include a decimal)
I'm tagging this with medical and data since I'm not 100% sure where it should really be tagged...any help there would also be appreciated.
Just wanted to chime in on how to correct the code decimal places. First, there are four broad points to consider:
Standard codes have Decimal place XXX.XX
Some Codes Do not have trailing decimal places
V Codes also follow the XXX.XX format --> V54.31
E Codes follow XXXX.X --> E850.9
Thus the general logic of how to fix the errors is
If first character = E:
If 5th character = '':
Ignore
Else replace XXXXX with XXXX.X
Else If 4th-5th Char is not '': (XXXX or XXXXX)
replace XXXXX with XXX + . + remainder (XXX.XX or XXX.X)
(All remaining are XXX)
I implemented this with two SQL Update statements:
Number 1, for Non E-codes:
USE MainDb;
UPDATE "dbo"."icd9cm_diagnosis_codes"
SET "DIAGNOSIS CODE" = SUBSTRING("DIAGNOSIS CODE",1,3)+'.'+SUBSTRING("DIAGNOSIS CODE",4,5)
FROM "dbo"."icd9cm_diagnosis_codes"
WHERE
SUBSTRING("DIAGNOSIS CODE",4,5) != ''
AND
LEFT("DIAGNOSIS CODE",1) != 'E'
Number 2 - For E Codes:
UPDATE "dbo"."icd9cm_diagnosis_codes"
SET "DIAGNOSIS CODE" = SUBSTRING("DIAGNOSIS CODE",1,4)+'.'+SUBSTRING("DIAGNOSIS CODE",5,5)
FROM "dbo"."icd9_Diagnosis_table"
WHERE
LEFT("DIAGNOSIS CODE",1) = 'E'
AND
SUBSTRING("DIAGNOSIS CODE",5,5) != ''
Seemed to do the trick for me (Using SQL Server 2008).
I ran into this same issue a while back and ended up building my own solution from scratch. Recently, I put up an open API for the codes for others to use: http://aqua.io/codes/icd9/documentation
You can just download all codes in JSON (http://api.aqua.io/codes/beta/icd9.json) or pull an individual code (http://api.aqua.io/codes/beta/icd9/250-1.json). Pulling a single code not only gives you the ICD-10 "crosswalk" (equivalents), but also some extra goodies, like relevant Wikipedia links.
I finally found the following:
"The field for the ICD-9-CM Principal and Other Diagnosis Codes is six characters in length, with the decimal point implied between the third and fourth digit for all diagnosis codes other than the V codes. The decimal is implied for V codes between the second and third digit."
So I was able to get a hold of a complete ICD-9 list and reformat as required.
You might find that the ICD-9 codes follow the following format:
All codes are 6 characters long
The decimal point comes between the 3rd and 4th characters
If the code starts with a V character the decimal point comes between the 2nd and 3rd characters
Check this out: http://en.wikipedia.org/wiki/List_of_ICD-9_codes
I struggled with this issue myself for a long time as well. The best resource I have been able to find for these are the zip files here:
https://www.cms.gov/ICD9ProviderDiagnosticCodes/06_codes.asp
It's unfortunate because they (oddly) are missing the decimal places, but as several other posters have pointed out, adding them is fairly easy since the rules are known. I was able to use a regular expression based "find and replace" in my text editor to add them. One thing to watch out for if you go that route is that you can end up with codes that have a trailing "." but no zero after it. That's not valid, so you might need to go through and do another find/replace to clean those up.
The annoying thing about the data files in the link above is that there is no relationship to categories. Which you might need depending on your application. I ended up taking one of the RTF-based category files I found online and re-formatting it to get the ranges of each category. That was still doable in a text editor with some creative regular expressions.
I was able to use the helpful answers here an create a groovy script to decimalize the code and combine long and short descriptions into a tab separated list. In case this helps anyone, I'm including my code here:
import org.apache.log4j.BasicConfigurator
import org.apache.log4j.Level
import org.apache.log4j.Logger
import java.util.regex.Matcher
import java.util.regex.Pattern
Logger log = Logger.getRootLogger()
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.INFO);
Map shortDescMap = [:]
new File('CMS31_DESC_SHORT_DX.txt').eachLine {String l ->
int split = l.indexOf(' ')
String code = l[0..split].trim()
String desc = l[split+1..-1].trim()
shortDescMap.put(code, desc)
}
int shortLenCheck = 40 // arbitrary lengths, but provide some sanity checking...
int longLenCheck = 300
File longDescFile = new File('CMS31_DESC_LONG_DX.txt')
Map cmsRows = [:]
Pattern p = Pattern.compile(/^(\w*)\s+(.*)$/)
new File('parsedICD9.csv').withWriter { out ->
out.write('ICD9 Code\tShort Description\tLong Description\n')
longDescFile.eachLine {String row ->
Matcher m = row =~ p
if (m.matches()) {
String code = m.group(1)
String shortDescription = shortDescMap.get(code)
String longDescription = m.group(2)
if(shortDescription.size() > shortLenCheck){
log.info("Not short? $shortDescription")
}
if(longDescription.size() > longLenCheck){
log.info("${longDescription.size()} == Too long? $longDescription")
}
log.debug("Match 1:${code} -- 2:${longDescription} -- orig:$row")
if (code.startsWith('V')) {
if (code.size() > 3) {
code = code[0..2] + '.' + code[3..-1]
}
log.info("Code: $code")
} else if (code.startsWith('E')) {
if (code.size() > 4) {
code = code[0..3] + '.' + code[4..-1]
}
log.info("Code: $code")
} else if (code.size() > 3) {
code = code[0..2] + '.' + code[3..-1]
}
if (code) {
cmsRows.put(code, ['longDesc': longDescription])
}
out.write("$code\t$shortDescription\t$longDescription\n")
} else {
log.warn "No match for row: $row"
}
}
}
I hope this helps someone.
Sean

Resources