gary_rip Posted February 24, 2009 Share Posted February 24, 2009 I'm not even sure i have the right title for this thread but... Here is my code <?php echo '<table border="1">'; echo '<tr>'; echo '<td>'.$match4[1].'</td>'; echo '<td><a href="http://www.awebsite.com/'.$match3[1].'" target="_blank">'.$match2[1].'</a></td>'; ?> I'm making a table from the data in the arrays, but i want to loop it so that every $match[X] jumps up a number and creates another row on the table. Sorry for the rubbish explanation... it doesn't help when i don't know the correct terminology! Quote Link to comment https://forums.phpfreaks.com/topic/146745-solved-multiple-array-with-5-values-in-each/ Share on other sites More sharing options...
premiso Posted February 24, 2009 Share Posted February 24, 2009 You need to loop through the results, for an array I would suggest foreach or even a for loop. Right now you are just manually writing them. Quote Link to comment https://forums.phpfreaks.com/topic/146745-solved-multiple-array-with-5-values-in-each/#findComment-770418 Share on other sites More sharing options...
premiso Posted February 24, 2009 Share Posted February 24, 2009 $cnt = count($match); for ($i=0; $i < $match; $i++) { echo '<td>'.$match4[$i].'</td>'; echo '<td><a href="http://www.awebsite.com/'.$match3[$i].'" target="_blank">'.$match2[$i].'</a></td>'; } Damnit, sorry for the double post. I thought I clicked the edit button =\ Quote Link to comment https://forums.phpfreaks.com/topic/146745-solved-multiple-array-with-5-values-in-each/#findComment-770420 Share on other sites More sharing options...
gary_rip Posted February 24, 2009 Author Share Posted February 24, 2009 Thanks for your help... but... When i use the code that you have posted nothing is echo'ed from thr array. Its like the inserted code does not run - looking at the source its not even creating the table tags. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/146745-solved-multiple-array-with-5-values-in-each/#findComment-770454 Share on other sites More sharing options...
premiso Posted February 24, 2009 Share Posted February 24, 2009 for ($i=0; $i < $cnt; $i++) { Sorry, meant for that to be $cnt Quote Link to comment https://forums.phpfreaks.com/topic/146745-solved-multiple-array-with-5-values-in-each/#findComment-770463 Share on other sites More sharing options...
gary_rip Posted February 24, 2009 Author Share Posted February 24, 2009 Is this bit correct then? as i cant see where $match comes from... <?php $cnt = count($match); ?> Quote Link to comment https://forums.phpfreaks.com/topic/146745-solved-multiple-array-with-5-values-in-each/#findComment-770469 Share on other sites More sharing options...
premiso Posted February 24, 2009 Share Posted February 24, 2009 as i cant see where $match comes from... You may need it to be $match1, given your initial post I thought that there was also a $match, but that is probably a wrong assumption. Change it to $match1 and see if that works. Quote Link to comment https://forums.phpfreaks.com/topic/146745-solved-multiple-array-with-5-values-in-each/#findComment-770475 Share on other sites More sharing options...
gary_rip Posted February 24, 2009 Author Share Posted February 24, 2009 changed it to $match1 and its now outputting the first row of the table but its not looping to create the next 4 rows... Quote Link to comment https://forums.phpfreaks.com/topic/146745-solved-multiple-array-with-5-values-in-each/#findComment-770481 Share on other sites More sharing options...
premiso Posted February 24, 2009 Share Posted February 24, 2009 $cnt = count($match1); for ($i=0; $i < $cnt; $i++) { echo '<tr><td>'.$match4[$i].'</td>'; echo '<td><a href="http://www.awebsite.com/'.$match3[$i].'" target="_blank">'.$match2[$i].'</a></td></tr>'; } By outputting the first row, I will take it as it is working, it just needs to separate the data into rows. That should, hopefully work. You are giving me some vague feedback, by the way can you post how your arrays are populated/setup? If the above does not work that is, it would help diagnosing the issue. Quote Link to comment https://forums.phpfreaks.com/topic/146745-solved-multiple-array-with-5-values-in-each/#findComment-770485 Share on other sites More sharing options...
gary_rip Posted February 25, 2009 Author Share Posted February 25, 2009 Sorry for being vague, but you gave me all the answers that i needed to get my origional question resolved! Its just that as you correctly stated it was a problem with my array was populated... i was using preg_match and not preg_match_all RESOLVED! Quote Link to comment https://forums.phpfreaks.com/topic/146745-solved-multiple-array-with-5-values-in-each/#findComment-770939 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.