...

View Full Version : Move Placement Of Buttons



bucket
08-25-2009, 02:57 PM
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.


<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);
?>

mlseim
08-25-2009, 03:04 PM
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).

bucket
08-25-2009, 03:37 PM
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.

bucket
08-25-2009, 03:41 PM
http://img195.yfrog.com/img195/2154/deletee.png

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

bucket
08-25-2009, 04:18 PM
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.


<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);
?>

mlseim
08-25-2009, 04:28 PM
<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);
?>

bucket
08-25-2009, 04:52 PM
Your code seems to not be working.

After I delete all the rows, this is what it shows:
http://img17.imageshack.us/img17/6940/deleted.png

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

mlseim
08-25-2009, 05:19 PM
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?


<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);
?>

bucket
08-25-2009, 05:27 PM
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.

mlseim
08-25-2009, 06:25 PM
Placement makes no difference as long as it's within <form> and </form>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum