seany123 Posted June 17, 2009 Share Posted June 17, 2009 i need a little help.. i have this code... <form method='post'> <tr> <td width='15%'>Gang Name:</td> <td width='35%'> <input type='text' name='name' value='<?=$gang['name']?>' maxlength='20' size='16'></td> <td width='15%'>Gang Tag:</td> <td width='35%'> <input type='text' name='tag' value='<?=$gang['tag']?>' maxlength='3' size='4'></td> </tr> <tr> <td>Money Tax:</td> <td colspan='3'> <select name='tax'> <option value='0'>0%</option> <option value='1'>1%</option><option value='2'>2%</option><option value='3'>3%</option><option value='4'>4%</option><option value='5'>5%</option><option value='6'>6%</option><option value='7'>7%</option><option value='8'>8%</option><option value='9'>9%</option><option value='10'>10%</option><option value='11'>11%</option><option value='12'>12%</option><option value='13'>13%</option><option value='14'>14%</option><option value='15'>15%</option><option value='16'>16%</option><option value='17'>17%</option><option value='18'>18%</option><option value='19'>19%</option><option value='20'>20%</option><option value='21'>21%</option><option value='22'>22%</option><option value='23'>23%</option><option value='24'>24%</option><option value='25'>25%</option><option value='26'>26%</option><option value='27'>27%</option><option value='28'>28%</option><option value='29'>29%</option><option value='30'>30%</option><option value='31'>31%</option><option value='32'>32%</option><option value='33'>33%</option><option value='34'>34%</option><option value='35'>35%</option><option value='36'>36%</option><option value='37'>37%</option><option value='38'>38%</option><option value='39'>39%</option><option value='40'>40%</option><option value='41'>41%</option><option value='42'>42%</option><option value='43'>43%</option><option value='44'>44%</option><option value='45'>45%</option><option value='46'>46%</option><option value='47'>47%</option><option value='48'>48%</option><option value='49'>49%</option><option value='50'>50%</option> </select> </td> </tr> <tr> <td>Description:<br /></td> <td colspan='3'><textarea name='description' cols='79' rows='7'></textarea></td> </tr> <tr> <td>Announcement:<br /></td> <td colspan='3'> <textarea name='announcement' cols='79' rows='7'></textarea></td> </tr> <tr> <td colspan='4' align='center'><input type='submit' name='update' value='Update'></td> </tr> </form> firstly, how do I set the "money tax" drop down menu so it corresponds with my database... basically i want it so if($gang['tax'] == 0) then select 0%.... and so on... can anyone help me with this first? Link to comment https://forums.phpfreaks.com/topic/162590-solved-help-please/ Share on other sites More sharing options...
MatthewJ Posted June 17, 2009 Share Posted June 17, 2009 you would need to add <?php if($gang['tax'] == 0) { echo 'SELECTED'; } ?> within each option. Changing the == to the right number. Link to comment https://forums.phpfreaks.com/topic/162590-solved-help-please/#findComment-858113 Share on other sites More sharing options...
seany123 Posted June 17, 2009 Author Share Posted June 17, 2009 can you do one for me as an example then ill do the rest? so i know how its done? Link to comment https://forums.phpfreaks.com/topic/162590-solved-help-please/#findComment-858116 Share on other sites More sharing options...
MatthewJ Posted June 17, 2009 Share Posted June 17, 2009 <option value='0' <?php if($gang['tax'] == 0) { echo 'SELECTED'; } ?>>0%</option> Link to comment https://forums.phpfreaks.com/topic/162590-solved-help-please/#findComment-858118 Share on other sites More sharing options...
xphoid Posted June 17, 2009 Share Posted June 17, 2009 A simple loop would work well for this: <select name='tax'> <?php for($i=0; $i<51; $i++): ?> <option value='<?php echo $i; ?>'<?php if($i == $gang['tax']) { echo ' selected'; } ?>><?php echo $i; ?>%</option> <?php endfor; ?> </select> Link to comment https://forums.phpfreaks.com/topic/162590-solved-help-please/#findComment-858119 Share on other sites More sharing options...
MatthewJ Posted June 17, 2009 Share Posted June 17, 2009 A simple loop would work well for this: <select name='tax'> <?php for($i=0; $i<51; $i++): ?> <option value='<?php echo $i; ?>'<?php if($i == $gang['tax']) { echo ' selected'; } ?>><?php echo $i; ?>%</option> <?php endfor; ?> </select> Agreed! Link to comment https://forums.phpfreaks.com/topic/162590-solved-help-please/#findComment-858121 Share on other sites More sharing options...
seany123 Posted June 17, 2009 Author Share Posted June 17, 2009 thats brilliant... that little code to replace the amount i had now when using php with that would this work?? <?php if ($_POST['update']) { if ($_POST['tax'] != $gang['tax']) { //UPDATE $GANG['TAX'] QUERY HERE. } } ?> Link to comment https://forums.phpfreaks.com/topic/162590-solved-help-please/#findComment-858139 Share on other sites More sharing options...
seany123 Posted June 17, 2009 Author Share Posted June 17, 2009 FIXED. Link to comment https://forums.phpfreaks.com/topic/162590-solved-help-please/#findComment-858157 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.