edwardoit Posted February 28, 2008 Share Posted February 28, 2008 question: i have stored list of arrays on my variable $array_list[] = $array which has 0 and 1. how can i retrieve arrays only the 1's a noob need helps here.. thanks.. Link to comment https://forums.phpfreaks.com/topic/93492-array-prob-help/ Share on other sites More sharing options...
trq Posted February 28, 2008 Share Posted February 28, 2008 You'll need to be allot clearer in the explination of your problem. Maybe show us the array contents. Link to comment https://forums.phpfreaks.com/topic/93492-array-prob-help/#findComment-478974 Share on other sites More sharing options...
edwardoit Posted February 28, 2008 Author Share Posted February 28, 2008 here some example.. while ($search = mysql_fetch_assoc($result)) { <tr><td>some results</td></tr> #somewhere at the end i put this so i could gather some data from query... $inlist[] = $zero; } foreach ($inlist as $currentvalue) { echo "<tr><td colspan = \"14\">$currentvalue</td></tr>"; i got: 0 1 1 1 0 0 0 how could i display only the 1's and not display 0's. Link to comment https://forums.phpfreaks.com/topic/93492-array-prob-help/#findComment-478983 Share on other sites More sharing options...
trq Posted February 28, 2008 Share Posted February 28, 2008 <?php foreach ($inlist as $currentvalue) { if ($currentvalue == 1) { echo "<tr><td colspan = \"14\">$currentvalue</td></tr>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/93492-array-prob-help/#findComment-478986 Share on other sites More sharing options...
spikeon Posted February 28, 2008 Share Posted February 28, 2008 not sure what your trying to do but if($currentvalue == "1"){ echo "$currentvalue";} Link to comment https://forums.phpfreaks.com/topic/93492-array-prob-help/#findComment-478987 Share on other sites More sharing options...
edwardoit Posted February 28, 2008 Author Share Posted February 28, 2008 wow thanks for that!!! u made me bow to you!... Link to comment https://forums.phpfreaks.com/topic/93492-array-prob-help/#findComment-478988 Share on other sites More sharing options...
edwardoit Posted February 29, 2008 Author Share Posted February 29, 2008 another related question... this only displays one column, how can i add another column.... like... if ($currentvalue == 1) { echo "<tr><td colspan = \"14\"> $name </td> <td>$age</td> <td> $currentvalue </td> </tr>"; } Link to comment https://forums.phpfreaks.com/topic/93492-array-prob-help/#findComment-479641 Share on other sites More sharing options...
spikeon Posted February 29, 2008 Share Posted February 29, 2008 while ($search = mysql_fetch_assoc($result)) { <tr><td>some results</td></tr> #somewhere at the end i put this so i could gather some data from query... if(isset($inlist[$ctr][num]) ctr++; $inlist[$ctr][num] = $zero; $inlist[$ctr][age] = $hero; $inlist[$ctr][name] = $nero; } foreach ($inlist as $list) { if($list[num] == 1){ echo "<tr><td colspan = \"14\"> $list[name] </td> <td>$list[age]</td> <td> $list[num] </td> </tr>"; } } i am NOT second best ANYmore Link to comment https://forums.phpfreaks.com/topic/93492-array-prob-help/#findComment-479678 Share on other sites More sharing options...
edwardoit Posted February 29, 2008 Author Share Posted February 29, 2008 on this part... if(isset($inlist[$ctr][num]) ctr++; $inlist[$ctr][num] = $zero; $inlist[$ctr][age] = $hero; $inlist[$ctr][name] = $nero; displays: Parse error: syntax error, unexpected T_STRING in /var/www/test/list.php on line blah... is it the opeing and closing() ? or what? i dont know... please keep in touch... i still ned ur help.. Link to comment https://forums.phpfreaks.com/topic/93492-array-prob-help/#findComment-479686 Share on other sites More sharing options...
spikeon Posted February 29, 2008 Share Posted February 29, 2008 if(isset($inlist[$ctr][num])) ctr++; <-- thats the fix sorry Link to comment https://forums.phpfreaks.com/topic/93492-array-prob-help/#findComment-479713 Share on other sites More sharing options...
edwardoit Posted February 29, 2008 Author Share Posted February 29, 2008 if(isset($inlist[$ctr][num])) ctr++; <-- thats the fix the final touch... add $ to ctr++ so it would be $ctr++ if(isset($inlist[$ctr][num])) $ctr++; <-- thats the fix bravo to that! excellent! Link to comment https://forums.phpfreaks.com/topic/93492-array-prob-help/#findComment-479743 Share on other sites More sharing options...
edwardoit Posted February 29, 2008 Author Share Posted February 29, 2008 if i print(count($list)); why its only 3??? Link to comment https://forums.phpfreaks.com/topic/93492-array-prob-help/#findComment-479752 Share on other sites More sharing options...
trq Posted February 29, 2008 Share Posted February 29, 2008 $list isn't defined in any code you have posted so far. Link to comment https://forums.phpfreaks.com/topic/93492-array-prob-help/#findComment-479774 Share on other sites More sharing options...
edwardoit Posted February 29, 2008 Author Share Posted February 29, 2008 i just want to happen is count all the result of foreach ($inlist as $list) { if($list[num] == 1){ echo "<tr><td colspan = \"14\"> $list[name] </td> <td>$list[age]</td> <td> $list[num] </td> </tr>"; } } i want to know how to count all ther esult. patience for the me please... im still learning Link to comment https://forums.phpfreaks.com/topic/93492-array-prob-help/#findComment-479780 Share on other sites More sharing options...
spikeon Posted February 29, 2008 Share Posted February 29, 2008 ok, list is only three because list is just one of the values of inlist use print(count($inlist)) Link to comment https://forums.phpfreaks.com/topic/93492-array-prob-help/#findComment-479783 Share on other sites More sharing options...
edwardoit Posted February 29, 2008 Author Share Posted February 29, 2008 it only counts the number of fields... the 3 variables in the array... but i have a lot of results more than 20...??? if i use print(count($inlist)) i got 3 if i use print(count($list)) i got 1 ??? ??? ??? ??? ??? Link to comment https://forums.phpfreaks.com/topic/93492-array-prob-help/#findComment-479786 Share on other sites More sharing options...
spikeon Posted February 29, 2008 Share Posted February 29, 2008 oh, down and Dirtay.... using previous code, WE CAN DO IT Link to comment https://forums.phpfreaks.com/topic/93492-array-prob-help/#findComment-479799 Share on other sites More sharing options...
spikeon Posted February 29, 2008 Share Posted February 29, 2008 wanna know how many there are? use $ctr that right, its been sitting there counting your array and you didn't even KNOW it Link to comment https://forums.phpfreaks.com/topic/93492-array-prob-help/#findComment-479800 Share on other sites More sharing options...
edwardoit Posted February 29, 2008 Author Share Posted February 29, 2008 wallah!!! got it! Link to comment https://forums.phpfreaks.com/topic/93492-array-prob-help/#findComment-479804 Share on other sites More sharing options...
spikeon Posted February 29, 2008 Share Posted February 29, 2008 if u need any more help, my AIM is mikf0002 Link to comment https://forums.phpfreaks.com/topic/93492-array-prob-help/#findComment-479806 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.