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.. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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>"; } } ?> Quote Link to comment 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";} Quote Link to comment 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!... Quote Link to comment 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>"; } Quote Link to comment 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 Quote Link to comment 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.. Quote Link to comment 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 Quote Link to comment 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! Quote Link to comment 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??? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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)) Quote Link to comment 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 ??? ??? ??? ??? ??? Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
edwardoit Posted February 29, 2008 Author Share Posted February 29, 2008 wallah!!! got it! Quote Link to comment 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 Quote Link to comment 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.