Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    697
    Thanks
    8
    Thanked 17 Times in 16 Posts

    Move Placement Of Buttons

    I currently have this code and want to move the placement of the buttons on the bottom to the top of the list:

    This php script basically lists all the members in a database and allows you to delete them.

    PHP Code:
    <script type="text/javascript">
       function checkall(chek)
       {
          for (i = 0; i < chek.length; i++)
          chek[i].checked = true;
       }
    </script>
    <?php

    require("inc/config.php");
    if (isset(
    $_POST['del'])) 
    {

        for (
    $count 0;$count<count($_POST[delchk]);$count++)
       {
               
    $delete $_POST[delchk][$count];
               
    $query "DELETE FROM persons WHERE id = '$delete'";
               
    $result mysql_query($query);
               if (!
    $result
       {
                die(
    "Error deleting persons! Query: $query<br />Error: ".mysql_error());
            }
        }
    }
    $result mysql_query("SELECT * FROM persons");
    echo 
    "<form name = 'myform' action='' method='post'>";
    while(
    $row mysql_fetch_array($result))
      {
      echo 
    "First Name: " $row['FirstName'] . "";
      echo 
    "<br>";
      echo 
    "Last Name: " $row['LastName'] . "";
      echo 
    "<br>";
      echo 
    "<a target=frame2 href='" ."profile.php?user1="$row['FirstName'] ."'>Profile</a>";
      echo 
    "<br>";
      echo 
    "Date: " $row['AddedDate'] . "";
      echo 
    "<br>";
      echo 
    "IP Address: " $row['Ip'] . "";
      echo 
    "<br>";
      echo 
    '<input type="checkbox" id="delchk" name="delchk[]" value="'.$row['id'].'" />';  
      echo 
    "<br>";
      echo 
    "***********************************************";
      echo 
    "<br>";
      }
    echo 
    "</table><input type='submit' name = 'del' value='Delete Selected'><input type='button' onclick='checkall(document.myform.delchk);' value='Select All'></form>";
    mysql_close($con);
    ?>
    Last edited by bucket; 08-25-2009 at 02:03 PM.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Do you have a thing where all of the buttons are piled-up below the list?
    Can you make a screenshot of this so we can see it?

    I'm suspicious about the closing </table> tag ...
    I don't see an opening <table> tag.
    In fact, there's no purpose for using a table?

    I wonder if that misplaced tag is messing-up your list (as it's displayed).

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    697
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Oh Ok, so the upated version would be without the </table>.

    But how do I do it so I can move the placement of the buttons.

  • #4
    Regular Coder
    Join Date
    Sep 2008
    Posts
    697
    Thanks
    8
    Thanked 17 Times in 16 Posts


    I selected one of the check boxes so you can see what I mean.

  • #5
    Regular Coder
    Join Date
    Sep 2008
    Posts
    697
    Thanks
    8
    Thanked 17 Times in 16 Posts
    I think I got it:

    Here is the code:

    I added a Unselect Button also.

    Now what I need is that if there are no members it says 'No Members Registered'.

    Like an else statement.

    PHP Code:
    <script type="text/javascript">
       function checkall(chek)
       {
          for (i = 0; i < chek.length; i++)
          chek[i].checked = true;
       }
    </script>

    <script type="text/javascript">
       function uncheckall(chek)
       {
          for (i = 0; i < chek.length; i++)
          chek[i].checked = false;
       }
    </script>

    <?php

    echo "<input type='button' onclick='checkall(document.myform.delchk);' value='Select All'>";
    echo 
    "<input type='button' onclick='uncheckall(document.myform.delchk);' value='UnSelect All'>";
    require(
    "inc/config.php");
    if (isset(
    $_POST['del'])) 
    {

        for (
    $count 0;$count<count($_POST[delchk]);$count++)
       {
               
    $delete $_POST[delchk][$count];
               
    $query "DELETE FROM persons WHERE id = '$delete'";
               
    $result mysql_query($query);
               if (!
    $result
       {
                die(
    "Error deleting persons! Query: $query<br />Error: ".mysql_error());
            }
        }
    }
    $result mysql_query("SELECT * FROM persons");
    echo 
    "<form name = 'myform' action='' method='post'>";
    while(
    $row mysql_fetch_array($result))
      {
      echo 
    "First Name: " $row['FirstName'] . "";
      echo 
    "<br>";
      echo 
    "Last Name: " $row['LastName'] . "";
      echo 
    "<br>";
      echo 
    "<a target=frame2 href='" ."profile.php?user1="$row['FirstName'] ."'>Profile</a>";
      echo 
    "<br>";
      echo 
    "Date: " $row['AddedDate'] . "";
      echo 
    "<br>";
      echo 
    "IP Address: " $row['Ip'] . "";
      echo 
    "<br>";
      echo 
    'Select to delete: <input type="checkbox" id="delchk" name="delchk[]" value="'.$row['id'].'" />';  
      echo 
    "<br>";
      echo 
    "***********************************************";
      echo 
    "<br>";
      }
    echo 
    "<input type='submit' name = 'del' value='Delete Selected'></form>";
    mysql_close($con);
    ?>

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    PHP Code:
    <script type="text/javascript">
       function checkall(chek)
       {
          for (i = 0; i < chek.length; i++)
          chek[i].checked = true;
       }
    </script>

    <script type="text/javascript">
       function uncheckall(chek)
       {
          for (i = 0; i < chek.length; i++)
          chek[i].checked = false;
       }
    </script>

    <?php

    echo "<input type='button' onclick='checkall(document.myform.delchk);' value='Select All'>";
    echo 
    "<input type='button' onclick='uncheckall(document.myform.delchk);' value='UnSelect All'>";
    require(
    "inc/config.php");
    if (isset(
    $_POST['del'])) 
    {

        for (
    $count 0;$count<count($_POST[delchk]);$count++)
       {
               
    $delete $_POST[delchk][$count];
               
    $query "DELETE FROM persons WHERE id = '$delete'";
               
    $result mysql_query($query);
               if (!
    $result
       {
                die(
    "Error deleting persons! Query: $query<br />Error: ".mysql_error());
            }
        }
    }
    $result mysql_query("SELECT * FROM persons");

    // Check how many rows it found
    if(mysql_num_rows($result) > 0){

    echo 
    "<form name = 'myform' action='' method='post'>";
    while(
    $row mysql_fetch_array($result))
      {
      echo 
    "First Name: " $row['FirstName'] . "";
      echo 
    "<br>";
      echo 
    "Last Name: " $row['LastName'] . "";
      echo 
    "<br>";
      echo 
    "<a target=frame2 href='" ."profile.php?user1="$row['FirstName'] ."'>Profile</a>";
      echo 
    "<br>";
      echo 
    "Date: " $row['AddedDate'] . "";
      echo 
    "<br>";
      echo 
    "IP Address: " $row['Ip'] . "";
      echo 
    "<br>";
      echo 
    'Select to delete: <input type="checkbox" id="delchk" name="delchk[]" value="'.$row['id'].'" />';  
      echo 
    "<br>";
      echo 
    "***********************************************";
      echo 
    "<br>";
      }
    echo 
    "<input type='submit' name = 'del' value='Delete Selected'></form>";
    }

    else{
    // No rows were found ...
    echo "No entries were found";
    }

    mysql_close($con);
    ?>

  • #7
    Regular Coder
    Join Date
    Sep 2008
    Posts
    697
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Your code seems to not be working.

    After I delete all the rows, this is what it shows:


    Instead I want the buttons gone and to show a message like "No Registered Members".

  • #8
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    It's hard to script without testing ...

    It seems like it might be detecting some rows even though
    you deleted them ... hmmm. Someone else might know why
    that is happening. I'm not a MySQL expert.

    But for the situation with the buttons ...
    I guess you just move things like this?
    PHP Code:
    <script type="text/javascript">
       function checkall(chek)
       {
          for (i = 0; i < chek.length; i++)
          chek[i].checked = true;
       }
    </script>

    <script type="text/javascript">
       function uncheckall(chek)
       {
          for (i = 0; i < chek.length; i++)
          chek[i].checked = false;
       }
    </script>

    <?php

    require("inc/config.php");
    if (isset(
    $_POST['del'])) 
    {

        for (
    $count 0;$count<count($_POST[delchk]);$count++)
       {
               
    $delete $_POST[delchk][$count];
               
    $query "DELETE FROM persons WHERE id = '$delete'";
               
    $result mysql_query($query);
               if (!
    $result
       {
                die(
    "Error deleting persons! Query: $query<br />Error: ".mysql_error());
            }
        }
    }
    $result mysql_query("SELECT * FROM persons");

    // Check how many rows it found
    if(mysql_num_rows($result) > 0){

    echo 
    "<input type='button' onclick='checkall(document.myform.delchk);' value='Select All'>";
    echo 
    "<input type='button' onclick='uncheckall(document.myform.delchk);' value='UnSelect All'>";

    echo 
    "<form name = 'myform' action='' method='post'>";
    while(
    $row mysql_fetch_array($result))
      {
      echo 
    "First Name: " $row['FirstName'] . "";
      echo 
    "<br>";
      echo 
    "Last Name: " $row['LastName'] . "";
      echo 
    "<br>";
      echo 
    "<a target=frame2 href='" ."profile.php?user1="$row['FirstName'] ."'>Profile</a>";
      echo 
    "<br>";
      echo 
    "Date: " $row['AddedDate'] . "";
      echo 
    "<br>";
      echo 
    "IP Address: " $row['Ip'] . "";
      echo 
    "<br>";
      echo 
    'Select to delete: <input type="checkbox" id="delchk" name="delchk[]" value="'.$row['id'].'" />';  
      echo 
    "<br>";
      echo 
    "***********************************************";
      echo 
    "<br>";
      }
    echo 
    "<input type='submit' name = 'del' value='Delete Selected'></form>";
    }

    else{
    // No rows were found ...
    echo "No entries were found";
    }

    mysql_close($con);
    ?>

  • #9
    Regular Coder
    Join Date
    Sep 2008
    Posts
    697
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Thank you very much. Also am I able to move the placement of the 'Delete Selected' button?

    I would like to move it to the top with Select All and Unselect All.

  • #10
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Placement makes no difference as long as it's within <form> and </form>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •