Monkuar Posted March 1, 2012 Share Posted March 1, 2012 Okay, I did this awhile ago but I did not do it appropiately, I used basic HTML AND it took forever. I have 70 Icons, (They are all a Star icon). If my user has donated $$ to the site, he will get his field name "max_stars" incremented to the appropiate value, (1-70) to his account, so he can have access to any of the stars and selects them in his profile settings menu to be activated and shown on his account Profile. $i=1; while($i<=70) { echo "<input type="radio" id="s1" value="1" name="star">IMG TO STAR HERE"; $i++; } Okay, so I want to loop through all 70 icons, each icon is named 1-70.png and each one has to correspond to there correct #, so it shows all 70 and each image, 1.png, 2.png/etc, correct incrimination. I made the above code so far, but would like your help if you can help, I need to do all 70, but the radio boxes can only be enable to correspond to what the user's max_star field is in the table. So let's say user has max_stars set to 5. That means only 1-5.png stars will have the radio box enabled, so they can click it, but still showing the other 65 as DISABLED, base don there max_star db field. Then I would have to check if it's selected or not once they have updated there profile. If somone can get me going here it would be great (I have the code to update there profile/etc, I just need help on showing the data in the loop) if not I would have to do this with 70 stupid radio input boxes and use 70 if else statements, it's just so annoying, I want to take advantage of PHP's foreach/looping. . Quote Link to comment https://forums.phpfreaks.com/topic/258024-php-loopstar-menu-help/ Share on other sites More sharing options...
dragon_sa Posted March 1, 2012 Share Posted March 1, 2012 something like this maybe $uservalue=5; $i=1; while($i<=70) { if ($i<=$uservalue) { echo "<input type="radio" id="s1" value="$i" name="star">IMG TO STAR HERE"; } else { echo "<input type="radio" id="s1" value="$i" name="star" disabled>IMG TO STAR HERE"; } $i++; } Quote Link to comment https://forums.phpfreaks.com/topic/258024-php-loopstar-menu-help/#findComment-1322608 Share on other sites More sharing options...
Monkuar Posted March 1, 2012 Author Share Posted March 1, 2012 code works great! <?php $uservalue=5; $i=1; while($i<=70) { if ($i<=$uservalue) { echo '<input type="radio" id="s1" value="$i" name="star"><img src=img/icons/'.$i.'.png><br>'; } else { echo '<input type="radio" id="s1" value="$i" name="star" disabled><img src=img/icons/'.$i.'.png><br>'; } $i++; } ?> Now I need help, how do I display them in 7columns? I wanna do 10 for each one, here is my current screenshot: Some are cut off, but yea Quote Link to comment https://forums.phpfreaks.com/topic/258024-php-loopstar-menu-help/#findComment-1322611 Share on other sites More sharing options...
dragon_sa Posted March 1, 2012 Share Posted March 1, 2012 maybe <style type="text/css"> <!-- .column { position: relative; float: left; width: 30px; } --> </style> <?php $uservalue=5; $i=1; while($i<=70) { if (in_array($i, array('1', '11', '21', '31', '41', '51', '61')) { echo "<div class=\"column\">"; } if ($i<=$uservalue) { echo '<input type="radio" id="s1" value="$i" name="star"><img src=img/icons/'.$i.'.png><br>'; } else { echo '<input type="radio" id="s1" value="$i" name="star" disabled><img src=img/icons/'.$i.'.png><br>'; } if (in_array($i, array('10', '20', '30', '40', '50', '60', '70')) { echo "</div>"; } $i++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/258024-php-loopstar-menu-help/#findComment-1322612 Share on other sites More sharing options...
Monkuar Posted March 1, 2012 Author Share Posted March 1, 2012 maybe <style type="text/css"> <!-- .column { position: relative; float: left; width: 30px; } --> </style> <?php $uservalue=5; $i=1; while($i<=70) { if (in_array($i, array('1', '11', '21', '31', '41', '51', '61')) { echo "<div class=\"column\">"; } if ($i<=$uservalue) { echo '<input type="radio" id="s1" value="$i" name="star"><img src=img/icons/'.$i.'.png><br>'; } else { echo '<input type="radio" id="s1" value="$i" name="star" disabled><img src=img/icons/'.$i.'.png><br>'; } if (in_array($i, array('10', '20', '30', '40', '50', '60', '70')) { echo "</div>"; } $i++; } ?> I'll try that if I can't get this one to work $numCols = 6; $numPerCol = ceil(70 / $numCols); echo "<table><tr>"; for($col = 1; $col <= $numCols; $col++) { echo "<td><ul>"; for($row = 0; $row < $numPerCol; $row++) { $resultRow = 70; if ($i<=$uservalue) { echo $row; echo '<input type="radio" id="s1" value="$i" name="star"><img src=img/icons/'.$row.'.png><br>'; } else { echo '<input type="radio" id="s1" value="$i" name="star" disabled><img src=img/icons/'.$row.'.png><br>'; } } echo "</ul></td>"; } echo "</tr></table>"; Okay, I coded this but problem is: I need it to display 1 through 70 on all of them, any help? Dragon_SA i'll try yours if I cant get this to work, I also would need something to make the input radio box "selected" dependable on what they choose, it will be stored in the "stars" column any idea on that also? Quote Link to comment https://forums.phpfreaks.com/topic/258024-php-loopstar-menu-help/#findComment-1322613 Share on other sites More sharing options...
dragon_sa Posted March 1, 2012 Share Posted March 1, 2012 maybe <style type="text/css"> <!-- .column { position: relative; float: left; width: 30px; } --> </style> <?php $selected=3; $uservalue=5; $i=1; while($i<=70) { if (in_array($i, array('1', '11', '21', '31', '41', '51', '61'))) { echo "<div class=\"column\">"; } if ($i == $selected) { echo "<input type=\"radio\" id=\"s1\" value=\"$\i" name=\"sta\r" selected><img src=\"img/icons/$i.png\"><br>"; } if ($i<=$uservalue && $i != $selected) { echo "<input type=\"radio\" id=\"s1\" value=\"$i\" name=\"star\"><img src=\"img/icons/$i.png\"><br>"; } else { echo "<input type=\"radio\" id=\"s1\" value=\"$i\" name=\"star\" disabled><img src=\"img/icons/$i.png\"><br>"; } if (in_array($i, array('10', '20', '30', '40', '50', '60', '70'))) { echo "</div>"; } $i++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/258024-php-loopstar-menu-help/#findComment-1322614 Share on other sites More sharing options...
Monkuar Posted March 1, 2012 Author Share Posted March 1, 2012 maybe <style type="text/css"> <!-- .column { position: relative; float: left; width: 30px; } --> </style> <?php $selected=3; $uservalue=5; $i=1; while($i<=70) { if (in_array($i, array('1', '11', '21', '31', '41', '51', '61')) { echo "<div class=\"column\">"; } if ($i == $selected) { echo '<input type="radio" id="s1" value="$i" name="star" selected><img src=img/icons/'.$i.'.png><br>'; } if ($i<=$uservalue && $i != $selected) { echo '<input type="radio" id="s1" value="$i" name="star"><img src=img/icons/'.$i.'.png><br>'; } else { echo '<input type="radio" id="s1" value="$i" name="star" disabled><img src=img/icons/'.$i.'.png><br>'; } if (in_array($i, array('10', '20', '30', '40', '50', '60', '70')) { echo "</div>"; } $i++; } ?> syntax error, unexpected '{' in C:\wamp\www\s.php on line 1544 1544 if (in_array($i, array('1', '11', '21', '31', '41', '51', '61')) { echo "<div class=\"column\">"; } is it those {'s? how it causing a error lol Quote Link to comment https://forums.phpfreaks.com/topic/258024-php-loopstar-menu-help/#findComment-1322615 Share on other sites More sharing options...
dragon_sa Posted March 1, 2012 Share Posted March 1, 2012 missing a bracket sorry, should be if (in_array($i, array('1', '11', '21', '31', '41', '51', '61'))) { echo "<div class=\"column\">"; } if (in_array($i, array('10', '20', '30', '40', '50', '60', '70'))) { echo "</div>"; } Quote Link to comment https://forums.phpfreaks.com/topic/258024-php-loopstar-menu-help/#findComment-1322617 Share on other sites More sharing options...
Monkuar Posted March 1, 2012 Author Share Posted March 1, 2012 Lol, saw those Maybe Can it look more like my screenshot I had? I removed the break's but it's going side by side hmmmm Quote Link to comment https://forums.phpfreaks.com/topic/258024-php-loopstar-menu-help/#findComment-1322619 Share on other sites More sharing options...
dragon_sa Posted March 1, 2012 Share Posted March 1, 2012 set the width to 50px will give you more space in the div or if (in_array($i, array('1', '11', '21', '31', '41', '51', '61')) { echo "<td><ul>"; } if (in_array($i, array('10', '20', '30', '40', '50', '60', '70'))) { echo "</ul></td>"; } with the table tag above and end table below outside the while loop Quote Link to comment https://forums.phpfreaks.com/topic/258024-php-loopstar-menu-help/#findComment-1322621 Share on other sites More sharing options...
Monkuar Posted March 1, 2012 Author Share Posted March 1, 2012 set the width to 50px will give you more space in the div or if (in_array($i, array('1', '11', '21', '31', '41', '51', '61')) { echo "<td><ul>"; } if (in_array($i, array('10', '20', '30', '40', '50', '60', '70'))) { echo "</ul></td>"; } with the table tag above and end table below outside the while loop Topic Solved!!! THANKS! Quote Link to comment https://forums.phpfreaks.com/topic/258024-php-loopstar-menu-help/#findComment-1322623 Share on other sites More sharing options...
dragon_sa Posted March 1, 2012 Share Posted March 1, 2012 also the value selected should be checked not selected sorry if ($i == $selected) { echo "<input type=\"radio\" id=\"s1\" value=\"$i\" name=\"star\" checked><img src=\"img/icons/$i.png\"><br>"; } Quote Link to comment https://forums.phpfreaks.com/topic/258024-php-loopstar-menu-help/#findComment-1322624 Share on other sites More sharing options...
Monkuar Posted March 1, 2012 Author Share Posted March 1, 2012 also the value selected should be checked not selected sorry if ($i == $selected) { echo "<input type=\"radio\" id=\"s1\" value=\"$i\" name=\"star\" checked><img src=\"img/icons/$i.png\"><br>"; } LOL yea I changed that, here is final result ty <3 Quote Link to comment https://forums.phpfreaks.com/topic/258024-php-loopstar-menu-help/#findComment-1322627 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.