pocobueno1388 Posted May 31, 2007 Share Posted May 31, 2007 Hello =] Hopefully this is more self explanatory, because it is hard to explain. Fist off, let me give a visual of what I have: Now, there are items on the left, then there are 4 options of what you can do with that item. As you can see they can select all 4 options for ONE item...this is not good, because they should only be able to do one thing with it. My code to generate this form is obviously backwards, the problem is I don't know how to format it right. I want it to only allow you to select ONE option per column...not one option per row. Here is the part of my code generating the form: <?php print '<form action="'.$_SERVER['PHP_SELF'].'?view=quickstock" method="post">'; print '<table cellspacing=25> <th>Item</th> <th>Shop</th> <th>Storage Box</th> <th>Donate</th> <th>Discard</th> <tr align="center">'; while ($row = mysql_fetch_assoc($display_item)){ echo '<td>'.$row['name'].'<br>'.$row['id'].'</td>'; echo '<td><input type="radio" name=shop[] value="'.$row['id'].'"></td>'; echo '<td><input type="radio" name=storage[] value="'.$row['id'].'"></td>'; echo '<td><input type="radio" name=donate[] value="'.$row['id'].'"></td>'; echo '<td><input type="radio" name=discard[] value="'.$row['id'].'"></td>'; echo '<tr align="center">'; } print '</table>'; print '<input type="submit" name="go" value="Quick Stock!"> </form>'; ?> It would be great if someone could point me in the right direction in outputting the correct code...I just can't think of a way to do it =/ Any help is greatly appreciated, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/53747-solved-formatting-help/ Share on other sites More sharing options...
per1os Posted May 31, 2007 Share Posted May 31, 2007 This is more JavaScript/HTML oriented as PHP does not have anything to do with it. The < label tag in html may help, unsure. But yea wrong forum to put this in even though the output is generated with PHP, it is the html that is messing up. Quote Link to comment https://forums.phpfreaks.com/topic/53747-solved-formatting-help/#findComment-265625 Share on other sites More sharing options...
pocobueno1388 Posted May 31, 2007 Author Share Posted May 31, 2007 But PHP does have something to do with it, haha....I want to manipulate the PHP to output what I want 0_o ...I guess you could look at it as and HTML or PHP problem, but it really is both. I thought someone would be able to catch the mistake pretty fast here...but if a moderator feels this should be on a different board, then go ahead and move it, but I honestly feel that someone over there won't be able to help me because of lack of knowledge of PHP. Quote Link to comment https://forums.phpfreaks.com/topic/53747-solved-formatting-help/#findComment-265631 Share on other sites More sharing options...
chigley Posted May 31, 2007 Share Posted May 31, 2007 Instead of naming the lines of options under "Shop" etc. name them under item. <?php print '<form action="'.$_SERVER['PHP_SELF'].'?view=quickstock" method="post">'; print '<table cellspacing=25> <th>Item</th> <th>Shop</th> <th>Storage Box</th> <th>Donate</th> <th>Discard</th> <tr align="center">'; while ($row = mysql_fetch_assoc($display_item)){ echo '<td>'.$row['name'].'<br>'.$row['id'].'</td>'; echo '<td><input type="radio" name="'.$row['id'].'" value="shop"></td>'; echo '<td><input type="radio" name="'.$row['id'].'" value="storage"></td>'; echo '<td><input type="radio" name="'.$row['id'].'" value="donate"></td>'; echo '<td><input type="radio" name="'.$row['id'].'" value="discard"></td>'; echo '<tr align="center">'; } print '</table>'; print '<input type="submit" name="go" value="Quick Stock!"> </form>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/53747-solved-formatting-help/#findComment-265636 Share on other sites More sharing options...
per1os Posted May 31, 2007 Share Posted May 31, 2007 Well since you feel that way, I guess maybe I will give you some more food to digest. You can use Javascript, but is not necessary if this is setup right. Instead of using the array with different names I would go about it like this: <?php print '<form action="'.$_SERVER['PHP_SELF'].'?view=quickstock" method="post">'; print '<table cellspacing=25> <th>Item</th> <th>Shop</th> <th>Storage Box</th> <th>Donate</th> <th>Discard</th> <tr align="center">'; $i=0; while ($row = mysql_fetch_assoc($display_item)){ echo '<td>'.$row['name'].'<br>'.$row['id'].'</td>'; echo '<td><input type="radio" name=radio' . $i . ' value="shop:'.$row['id'].'"></td>'; echo '<td><input type="radio" name=radio' . $i . ' value="storage:'.$row['id'].'"></td>'; echo '<td><input type="radio" name=radio' . $i . ' value="donate:'.$row['id'].'"></td>'; echo '<td><input type="radio" name=radio' . $i . ' value="discard:'.$row['id'].'"></td>'; echo '<tr align="center">'; $i++; } print '</table>'; print '<input type="submit" name="go" value="Quick Stock!"> </form>'; ?> Than on the receiving page just loop through the post data looking for the "radio" in the key IE: <?php foreach ($_POST as $key => $val) { if (eregi("radio", $key)) { list($what, $id) = split(":", $val); $radios[$id] = $what; } } echo '<pre>',print_r($radios),'</pre>'; ?> I am sure there is a friendlier way to do it with javascript, but this way should get you your desired results. Quote Link to comment https://forums.phpfreaks.com/topic/53747-solved-formatting-help/#findComment-265640 Share on other sites More sharing options...
pocobueno1388 Posted May 31, 2007 Author Share Posted May 31, 2007 Frost - Beautiful, thank you very much =D Quote Link to comment https://forums.phpfreaks.com/topic/53747-solved-formatting-help/#findComment-265647 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.