php - Undefined Offset: 2 (lines 22, 28, 29) -
the following code shows error
"undefined offset: 2" on lines 22, 28, , 29
$sql = "select email commercialemails dripid = 1 , sent='a'"; if ($resultsd1 = mysqli_query($conn, $sql )) { $affectedrows = mysqli_num_rows($resultsd1); while ($row = mysqli_fetch_row($resultsd1)){ $results = $row[0]; global $results; } } $broken = explode(' ', $results); $hi = 0; $hello = 0; a: /**line 22 **/ if (substr($broken[$hi], -4) == "com," && $broken[$hi] == "qwert"){ $hey[$hi] = $broken[$hi]; $hello++; } if(substr($broken[$hi], -4) !== "com,"){ // line 28 $hey[$hi] = $broken[$hi]; //line 29 } $hi++; if ($hi == $affectedrows){ if (!isset($hey)){ echo "there no emails"; } else { foreach( $hey $key => $value){ echo $value; } echo $hey; } }else{ goto a; }
i not sure trying achieve, code working try way:
$sql = "select email commercialemails dripid = 1 , sent='a'"; $results = array(); $hey = array(); if ($resultsd1 = mysqli_query($conn, $sql )) { $affectedrows = mysqli_num_rows($resultsd1); while ($row = mysqli_fetch_row($resultsd1)){ $results[] = $row; if(substr($row[0], -4) !== "com,"){ $hey[] = $row[0]; } } } if (count($hey)==0){ echo "there no emails"; } else { foreach( $hey $value){ echo $value; } echo $hey; }
as can see removed many of variables don't need them until can explain goals.
and i've removed weird condition if
:
if (substr($broken[$hi], -4) == "com," && $broken[$hi] == "qwert"){ $hey[$hi] = $broken[$hi]; $hello++; }
because there no such value of $broken[$hi]
can equal 'qwert'
, have 'com'
substring inside. codition false , can delete it.
try explain goals. hope can you.
Comments
Post a Comment