Re: Notice

From: Date: Thu, 27 Mar 2014 12:25:20 +0000
Subject: Re: Notice
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-323112@lists.php.net to get a copy of this message
Thanks! That looks like a good place to start! T. On Mar 27, 2014, at 9:17 AM, Ricardo R Bonfim <ricobonfim@gmail.com> wrote: > Well, i'm not totally sure that you can't catch a notice on php, but > even if possible, it wouldn't be a good choice from my point of view.. > > A good approach would be test if the $data array really has the $loci > position set before trying to use it.. > something like: > if ( isset($data[$ids][$loci]) ) { > $alelleY = $data[$ids][$loci]['alelleY']; > $alelleX = $data[$ids][$loci]['alelleX']; > } > And then you could choose your best approach to deal with this.. > You could raise and exception in an else statement, or you could just > set the $alelleY and X variables with something like 'Not found' > > Altough it's possible to mix javascript with php, I can't imagine why > would you show the errors with javascript... unless of course, if > you're using ajax for this.. > > 2014-03-27 8:36 GMT-03:00 Tiago Hori <tiago.hori@gmail.com>: >> Hi Ricardo, >> >> Thanks! >> >> I figured it out last night the entries on the database were incomplete, so that makes >> perfect sense with what you are saying. Ir also occurred to me that this is something that may >> happen in the real application, so here is my next question: is there a way an can catch those >> errors and use say javascript to display them? >> >> Thanks! >> >> T. >> >> On Mar 27, 2014, at 12:14 AM, Ricardo R Bonfim <ricobonfim@gmail.com> wrote: >> >>> Hi Tiago, >>> >>> *Notice*: Undefined index: in >>> */Applications/MAMP/htdocs/catcnew/snppitv1.php* on line *62* >>> *Notice*: Undefined index: in >>> */Applications/MAMP/htdocs/catcnew/snppitv1.php* on line *63* >>> >>> These two, as I think, were raised because of lines below. You tried >>> to access $data array on $loci position, what i'm guessing that is >>> probably inexistent on this array. I suggest you to see what values do >>> you have on $snp array and compare to $row[6] to see if they match >>> each other. >>> $alelleY = $data[$ids][$loci]['alelleY']; >>> $alelleX = $data[$ids][$loci]['alelleX']; >>> >>> >>> *Notice*: Array to string conversion in >>> */Applications/MAMP/htdocs/catcnew/snppitv1.php* on line *66* >>> >>> The last notice is certainly raised because you are trying to use an >>> array as a string on the line below. $role is an array, right? You >>> could use explode function to turn each value from $role into a string >>> separated by comma for example. >>> $body .= "$ids\t$role\t" . substr($content, 0, -1) . >>> "\n"; >>> >>> Good luck >>> >>> 2014-03-26 20:30 GMT-03:00 Tiago Hori <tiago.hori@gmail.com>: >>>> Hi Everyone, >>>> >>>> I am at loss so I am hoping your wisdom can help me. >>>> >>>> I originally had a script that first got a list of terms to be searched >>>> from the file uploaded in the first part. This list is stored in the array >>>> $snp. Every item in $snp occurs once for every entry i have in the table. >>>> The goal is to allow the user to select a set in the file uploaded and get >>>> every entry for a given project, which is entered via POST. >>>> >>>> I had originally wrote this in way that it made 3 or 4 calls to the >>>> database and it was way to slow, so I tried to make one call to the >>>> database and put everything in a multidimensional array. >>>> >>>> Now, what I have below seems to work, but I get 3notices for every >>>> iteration of the foreach($rows as $ids) and I can't figure out for the life >>>> of me why. >>>> >>>> *Notice*: Undefined index: in >>>> */Applications/MAMP/htdocs/catcnew/snppitv1.php* on line *62* >>>> >>>> *Notice*: Undefined index: in >>>> */Applications/MAMP/htdocs/catcnew/snppitv1.php* on line *63* >>>> >>>> *Notice*: Array to string conversion in >>>> */Applications/MAMP/htdocs/catcnew/snppitv1.php* on line *66* >>>> >>>> >>>> I guess I would like to know what it is going on out of curiosity and if it >>>> can cause a problem down the road. Also, any suggestions on improvement are >>>> always welcome. >>>> >>>> if(isset($_FILES['snps'])) >>>> { >>>> $dir = 'uploads'; >>>> $header = "role\t"; >>>> $filename = $_FILES['snps']['name']; >>>> if (file_exists("$dir/$filename")) >>>> { >>>> die ("A file with this name already exists in the database <br >>>> />"); >>>> } >>>> else >>>> { >>>> move_uploaded_file($_FILES['snps']['tmp_name'], >>>> "$dir/$filename"); >>>> echo "Uploaded file '$filename' <br />"; >>>> $fh = fopen("$dir/$filename", 'r') or >>>> die("File does not exist or you lack permission to open it"); >>>> } >>>> while (!feof($fh)) >>>> { >>>> >>>> $line = fgets($fh); >>>> $snp[] = trim(preg_replace('/\n/', '', $line)); >>>> >>>> } >>>> foreach ($snp as $loci) >>>> { >>>> $header .= $loci . "\t" . $loci . "\t"; >>>> } >>>> >>>> } >>>> >>>> if(isset($_POST['project'])) >>>> { >>>> $project = sanitizeStrings($_POST['project']); >>>> $body = ""; >>>> >>>> $query = "SELECT * FROM genotyped WHERE >>>> projectid='$project'"; >>>> $result = queryMysql($query); >>>> if(mysqli_num_rows($result)) >>>> { >>>> $data = array(); >>>> while($row = mysqli_fetch_row($result)) >>>> { >>>> >>>> $rows[] = $row[2]; >>>> $role[$row[2]] = $row[3]; >>>> $data[$row[2]][$row[6]]['alelleY'] = $row[7]; >>>> $data[$row[2]][$row[6]]['alelleX'] = $row[8]; >>>> } >>>> $rows = array_unique($rows); >>>> foreach($rows as $ids) >>>> { >>>> $col2 = $role[$ids]; >>>> $alelleX = $alelleY = $content = ""; >>>> foreach($snp as $loci) >>>> { >>>> $alelleY = $data[$ids][$loci]['alelleY']; >>>> $alelleX = $data[$ids][$loci]['alelleX']; >>>> $content .= "$alelleY\t$alelleX\t"; >>>> } >>>> $body .= "$ids\t$role\t" . substr($content, 0, -1) . >>>> "\n"; >>>> } >>>> } >>>> } >>>> >>>> unlink("$dir/$filename"); >>>> >>>> >>>> ?> >>>> >>>> T. >>>> >>>> >>>> -- >>>> "Education is not to be used to promote obscurantism." - Theodonius >>>> Dobzhansky. >>>> >>>> "Gracias a la vida que me ha dado tanto >>>> Me ha dado el sonido y el abecedario >>>> Con él, las palabras que pienso y declaro >>>> Madre, amigo, hermano >>>> Y luz alumbrando la ruta del alma del que estoy amando >>>> >>>> Gracias a la vida que me ha dado tanto >>>> Me ha dado la marcha de mis pies cansados >>>> Con ellos anduve ciudades y charcos >>>> Playas y desiertos, montañas y llanos >>>> Y la casa tuya, tu calle y tu patio" >>>> >>>> Violeta Parra - Gracias a la Vida >>>> >>>> Tiago S. F. Hori. PhD. >>>> Ocean Science Center-Memorial University of Newfoundland >>> >>> >>> >>> -- >>> ____________________________________________________ >>> Ricardo R Bonfim >> > > > > -- > ____________________________________________________ > Ricardo R Bonfim

« previous php.general (#323112) next »