Jump to content

Recommended Posts

Hello =] Hopefully this is more self explanatory, because it is hard to explain.

 

Fist off, let me give a visual of what I have:

screen.jpg

 

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!

Link to comment
https://forums.phpfreaks.com/topic/53747-solved-formatting-help/
Share on other sites

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.

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>';

?>

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.