jmurch Posted May 14, 2009 Share Posted May 14, 2009 I'm using this while to loop thru my array: while ($row = oci_fetch_array($s, OCI_NUM+OCI_RETURN_NULLS)) { It's leaving the last row unprocessed each time. How can I modify the above statement to loop one extra time after the normal count? TIA, Jeff Quote Link to comment https://forums.phpfreaks.com/topic/158124-solved-while-loop-wont-process-last-row-in-array/ Share on other sites More sharing options...
premiso Posted May 14, 2009 Share Posted May 14, 2009 If oci has a row count feature, similar to mysql_num_rows you can just that and a for loop instead. See if that fixes the issue. Quote Link to comment https://forums.phpfreaks.com/topic/158124-solved-while-loop-wont-process-last-row-in-array/#findComment-834079 Share on other sites More sharing options...
Jibberish Posted May 14, 2009 Share Posted May 14, 2009 When oci_fetch_array has nothing left in the results set it will break the while loop (by return FALSE), so I would imagine the results either not in there, or the code inside the while loop isn't processing it correctly. Quote Link to comment https://forums.phpfreaks.com/topic/158124-solved-while-loop-wont-process-last-row-in-array/#findComment-834087 Share on other sites More sharing options...
PFMaBiSmAd Posted May 14, 2009 Share Posted May 14, 2009 It's likely that either your query is not selecting all the rows you think it is or your code is discarding or not using all the results. Post all your code from where the query statement is generated through to the end of your code that is using the results. Quote Link to comment https://forums.phpfreaks.com/topic/158124-solved-while-loop-wont-process-last-row-in-array/#findComment-834089 Share on other sites More sharing options...
nadeemshafi9 Posted May 14, 2009 Share Posted May 14, 2009 maybe its not are your sure it goes throgh the last ones or not ? try echoing in the loop to echo a count for each time it goes throgh teh array , as you are trying to work with nulls and that creates a blank for each null Quote Link to comment https://forums.phpfreaks.com/topic/158124-solved-while-loop-wont-process-last-row-in-array/#findComment-834091 Share on other sites More sharing options...
jmurch Posted May 14, 2009 Author Share Posted May 14, 2009 PFM, Here is the entire while loop. I have confirmed that there is one row left in the array after the while loop thinks it's done: $s = oci_parse($c, "select * from triton.LOOKUP_SERIAL_NBR_V where LOOKUP_SERIAL_NBR_V.parent_serial_number like '%$serial_number'"); oci_execute($s); $parent_row = oci_fetch_array($s, OCI_NUM+OCI_RETURN_NULLS); if($parent_row[0]) { echo "<span class='content_blue_header'>"; echo "<br><b><u>Parent information:</u></b>"; echo "</span>"; echo "<br>"; echo "<br>"; echo "<div class='serial_number_row'>"; echo "<div class='serial_number_title'>Serial number:</div>"; echo "<div class='serial_number_value'>".$parent_row[0]."</div>"; echo "</div>"; $date = $parent_row[1]; $ship_date = date('m-d-Y', strtotime($date)); // //$labor_warranty_date = date('m-d-Y', strtotime($date . ' + 90 DAYS')); // 90 days in the future $parts_warranty_date = date('m-d-Y', strtotime($date . ' + 13 MONTHS')); // 13 months in the future echo "<div class='serial_number_row'>"; echo "<div class='serial_number_title'>Model:</div>"; echo "<div class='serial_number_value'>".$parent_row[2]."</div>"; echo "</div>"; echo "<div class='serial_number_row'>"; echo "<div class='serial_number_title'>Manufacture date:</div>"; echo "<div class='serial_number_value'>".$ship_date."</div>"; echo "</div>"; //echo "<div class='serial_number_row'>"; // echo "<div class='serial_number_title'>Labor warranty good until:</div>"; // echo "<div class='serial_number_value'>".$labor_warranty_date."</b></div>"; //echo "</div>"; echo "<div class='serial_number_row'>"; echo "<div class='serial_number_title'>Parts warranty good until:</div>"; echo "<div class='serial_number_value'>".$parts_warranty_date."</div>"; echo "</div>"; echo "<br>"; echo "<br>"; echo "<div class='serial_number_row'>"; echo "<span class='content_blue_header'><b><u>Child component information:</u></b></span>"; echo "</div>"; echo "<br>"; echo "<br>"; while ($row = oci_fetch_array($s, OCI_NUM+OCI_RETURN_NULLS)) { echo "<div class='serial_number_output_row'>"; echo "<div class='serial_number_row'>"; echo "<div class='serial_number_title'>Component:</div>"; echo "<div class='serial_number_value'>".str_replace(', ,',',',str_replace('|', ', ', $row[5]))."</div>"; echo "</div>"; echo "<div class='serial_number_row'>"; echo "<div class='serial_number_title'>Part number:</div>"; echo "<div class='serial_number_value'>".$row[6]."</div>"; echo "</div>"; echo "<div class='serial_number_row'>"; echo "<div class='serial_number_title'>Serial number:</div>"; echo "<div class='serial_number_value'>".$row[3]."</div>"; echo "</div>"; echo "<div class='serial_number_row'>"; echo "<div class='serial_number_title'>Manufacture date:</div>"; echo "<div class='serial_number_value'>".$row[4]."</div>"; echo "</div>"; $part_number_pic = $row[6].".jpg"; $tn_path = 'http://www2.website.compartner/parts_programs/field_replaceable_parts_lists/parts_images/frp_tn/'.$part_number_pic; $pic_path = 'http://www2.website.com/partner/parts_programs/field_replaceable_parts_lists/parts_images/frp/'.$part_number_pic; echo "<div class='serial_number_row'>"; echo "<div class='serial_number_title'>Image:</div>"; echo "<div class='serial_number_value'><a href='$pic_path' rel='lightbox'><img src='$tn_path' border='0'></a></div>"; echo "</div>"; echo "<!--[if IE]><br style='clear:both;' /><![endif]-->"; if(!empty($row[7])) { echo "<div class='serial_number_row'>"; echo "<div class='serial_number_child_line'>"; echo "<img src='http://www2.website.com/partner/images/parent_child_line.png'>"; echo "</div>"; echo "<div class='serial_number_child_child'>"; echo "<div class='serial_number_row'>"; echo "<div class='serial_number_alternate_title'>Alternative part for ".$row[6]."</div>"; echo "</div>"; echo "<div class='serial_number_row'>"; echo "<div class='serial_number_title'>Component:</div>"; echo "<div class='serial_number_value'>".str_replace(', ,',',',str_replace('|', ', ', $row[8]))."</div>"; echo "</div>"; echo "<div class='serial_number_row'>"; echo "<div class='serial_number_title'>Alt. part number:</div>"; echo "<div class='serial_number_value'>".$row[7]."</div>"; echo "</div>"; echo "<div class='serial_number_row'>"; echo "<div class='serial_number_title'>Reciprocal:</div>"; echo "<div class='serial_number_value'>".$row[9]."</div>"; echo "</div>"; echo "<div class='serial_number_row'>"; echo "<div class='serial_number_title'>Alt. Part Manufacture date:</div>"; echo "<div class='serial_number_value'>".$row[10]."</div>"; echo "</div>"; $part_number_pic = $row[7].".jpg"; $part_number_b_pic = $row[7]."b.jpg"; $tn_path = 'http://www2.website.com/partner/parts_programs/field_replaceable_parts_lists/parts_images/frp_tn/'.$part_number_pic; $tn_path_b = 'http://www2.website.com/partner/parts_programs/field_replaceable_parts_lists/parts_images/frp_tn/'.$part_number_b_pic; $pic_path = 'http://www2.website.com/partner/parts_programs/field_replaceable_parts_lists/parts_images/frp/'.$part_number_pic; echo "<div class='serial_number_row'>"; echo "<div class='serial_number_title'>Image:</div>"; echo "<div class='serial_number_value'><a href='$pic_path' rel='lightbox'><img src='$tn_path' border='0'></a></div>"; echo "</div>"; echo "</div>"; echo "</div>"; echo "<!--[if IE]><br style='clear:both;' /><![endif]-->"; } echo "<br style='clear:both;' />"; echo "</div>"; } oci_free_statement($s); } else { echo "<div class='serial_number_row'><font size='3' color='red'>Serial number not found.</font></div>"; } Quote Link to comment https://forums.phpfreaks.com/topic/158124-solved-while-loop-wont-process-last-row-in-array/#findComment-834094 Share on other sites More sharing options...
premiso Posted May 14, 2009 Share Posted May 14, 2009 $parent_row = oci_fetch_array($s, OCI_NUM+OCI_RETURN_NULLS); That is why you are coming up a row short. You call it outside the loop so it iterates one before it ever hits the loop. Quote Link to comment https://forums.phpfreaks.com/topic/158124-solved-while-loop-wont-process-last-row-in-array/#findComment-834102 Share on other sites More sharing options...
jmurch Posted May 14, 2009 Author Share Posted May 14, 2009 There are two loops. The first is just to get the 'parent info' and then the second to get the 'child' info. Which loop are you referring to? Jeff Quote Link to comment https://forums.phpfreaks.com/topic/158124-solved-while-loop-wont-process-last-row-in-array/#findComment-834142 Share on other sites More sharing options...
PFMaBiSmAd Posted May 14, 2009 Share Posted May 14, 2009 There are two loops. Not in the code you posted. Quote Link to comment https://forums.phpfreaks.com/topic/158124-solved-while-loop-wont-process-last-row-in-array/#findComment-834146 Share on other sites More sharing options...
jmurch Posted May 14, 2009 Author Share Posted May 14, 2009 OK thanks. There was supposed to be two loops. The intent was that I would populate an array, loop it to get row 1 for the parent info, then loop a new one to get all the child rows. Jeff Quote Link to comment https://forums.phpfreaks.com/topic/158124-solved-while-loop-wont-process-last-row-in-array/#findComment-834152 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.