Avihai Posted January 15, 2008 Share Posted January 15, 2008 Hello, 1) I have a script that pulls out information from a db table. 2) In the table I have 10 fields and the script pulls all the data from a certain field. 3) Some fields contain information and some don't. 4) All the gathered information is inserted into array. My problem is when I output the result. To the fields that are empty I get "Undefined offset:" and the fields that do contain information I can see the result via echo. The question: How to I say in php to echo nothing when the fields is empty instead of printing the error? Thanks, Avihai Quote Link to comment https://forums.phpfreaks.com/topic/86211-solved-empty-array-results/ Share on other sites More sharing options...
p2grace Posted January 15, 2008 Share Posted January 15, 2008 Can you post some code, this should be possible. More than likely the array keys aren't being generated because there's no content being assigned to them. I need to see the code to instruct you how to fix the problem. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/86211-solved-empty-array-results/#findComment-440323 Share on other sites More sharing options...
trq Posted January 15, 2008 Share Posted January 15, 2008 isset will more than likely help you out. Otherwise, post some code. Quote Link to comment https://forums.phpfreaks.com/topic/86211-solved-empty-array-results/#findComment-440324 Share on other sites More sharing options...
Avihai Posted January 15, 2008 Author Share Posted January 15, 2008 $dr = array(); while ($row = mysql_fetch_assoc($sql)) { $dr = $row['name']; $drex = explode("|", $dr); echo $drex[1]; } Quote Link to comment https://forums.phpfreaks.com/topic/86211-solved-empty-array-results/#findComment-440329 Share on other sites More sharing options...
darkfreaks Posted January 15, 2008 Share Posted January 15, 2008 <?php $dr = array(); while ($row = mysql_fetch_assoc($sql)) { $dr = $row['name']; $drex = explode("|", $dr); if(isset($row['name'])){ echo $drex[1]; } elseif(!isset($row ['name'])){ // error here } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86211-solved-empty-array-results/#findComment-440339 Share on other sites More sharing options...
Avihai Posted January 15, 2008 Author Share Posted January 15, 2008 Thanks for the fast answer :-) darkfreaks ... I had to change what you've posted to: if(isset($drex[1])){ echo $drex[1]; } elseif(!isset($drex[1])){ echo "nothing"; } I was playing around with isset before but I got it wrong ... thanks for clearing the issue. Blessings, Avihai Quote Link to comment https://forums.phpfreaks.com/topic/86211-solved-empty-array-results/#findComment-440385 Share on other sites More sharing options...
p2grace Posted January 15, 2008 Share Posted January 15, 2008 If your question has been solved please hit "Topic Solved" Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/86211-solved-empty-array-results/#findComment-440386 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.