savagenoob Posted February 10, 2012 Share Posted February 10, 2012 I have this code: $data = array_combine($data4, $addfinal); foreach( $data as $key => $value){ ?> <tr> <td><?php echo $key;?></td><td><?php echo $value; ?></td><td></td><td>Safeco</td><td><a href="ajax/map.php?address=<?php echo urlencode($value);?>">Map It</a></td> </tr> <?php } That uses an array that looks like this (but longer): Array ( [business Name 1] => Business Address 1 [business Name 2] => Business Address 2 [business Name 3] => Business Address 3) But it skips every other array entry? Any ideas? So its displaying Business Name 1, Business Name 3, etc. Quote Link to comment https://forums.phpfreaks.com/topic/256840-array-foreach-skipping-every-other-entry/ Share on other sites More sharing options...
silkfire Posted February 10, 2012 Share Posted February 10, 2012 Can you print_r $data after the foreach is finished? Quote Link to comment https://forums.phpfreaks.com/topic/256840-array-foreach-skipping-every-other-entry/#findComment-1316721 Share on other sites More sharing options...
savagenoob Posted February 10, 2012 Author Share Posted February 10, 2012 Yeah, it looks as it should. Quote Link to comment https://forums.phpfreaks.com/topic/256840-array-foreach-skipping-every-other-entry/#findComment-1316725 Share on other sites More sharing options...
PFMaBiSmAd Posted February 10, 2012 Share Posted February 10, 2012 Does the 'view source' of the page have all the data? I suspect that your key or value contains html that is breaking the html of the table. Quote Link to comment https://forums.phpfreaks.com/topic/256840-array-foreach-skipping-every-other-entry/#findComment-1316729 Share on other sites More sharing options...
scootstah Posted February 10, 2012 Share Posted February 10, 2012 Does the 'view source' of the page have all the data? I suspect that your key or value contains html that is breaking the html of the table. To test that theory, what does this give you? foreach($data as $key => $value) { echo 'Key: ' . htmlspecialchars($key) . ' Value: ' . htmlspecialchars($value) . '<br />'; } Quote Link to comment https://forums.phpfreaks.com/topic/256840-array-foreach-skipping-every-other-entry/#findComment-1316732 Share on other sites More sharing options...
savagenoob Posted February 10, 2012 Author Share Posted February 10, 2012 Thats where its a bit complicated. I cant view source, I am using jQuery ajax with a jQuery paginator/search table. I am stripping tags on the table rows as they display I just omitted for ease of read. Quote Link to comment https://forums.phpfreaks.com/topic/256840-array-foreach-skipping-every-other-entry/#findComment-1316734 Share on other sites More sharing options...
savagenoob Posted February 10, 2012 Author Share Posted February 10, 2012 And I do strip_tags() on all the data and values prior to the foreach loop... Quote Link to comment https://forums.phpfreaks.com/topic/256840-array-foreach-skipping-every-other-entry/#findComment-1316740 Share on other sites More sharing options...
kicken Posted February 10, 2012 Share Posted February 10, 2012 Thats where its a bit complicated. I cant view source, I am using jQuery ajax with a jQuery paginator/search table. I am stripping tags on the table rows as they display I just omitted for ease of read. Use dev tools like firebug, chrome dev tools, or fiddler2 to view the ajax transaction that takes place and inspect the data being returned by your script to see if it is missing the rows or if the data is just malformed somehow. Quote Link to comment https://forums.phpfreaks.com/topic/256840-array-foreach-skipping-every-other-entry/#findComment-1316747 Share on other sites More sharing options...
savagenoob Posted February 10, 2012 Author Share Posted February 10, 2012 damn, thats wierd, the ajax is returning all the data correctly. Now what? Quote Link to comment https://forums.phpfreaks.com/topic/256840-array-foreach-skipping-every-other-entry/#findComment-1316752 Share on other sites More sharing options...
kicken Posted February 10, 2012 Share Posted February 10, 2012 damn, thats wierd, the ajax is returning all the data correctly. Now what? Sounds like now it's time to start debugging your JS code to see what it is doing. If it comes back from PHP ok then something in your JS must be causing it to skip rows. If your using a pre-packaged script to do things read the docs and make sure it is setup properly. If it's your own code start tossing in some console.log statements to find out what it is doing. Quote Link to comment https://forums.phpfreaks.com/topic/256840-array-foreach-skipping-every-other-entry/#findComment-1316776 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.