PHP Simplicity Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Guest posting is allowed. Again!

Author Topic: Please advice how to integrate your example of inserting rows  (Read 3605 times)

0 Members and 1 Guest are viewing this topic.

edhan

  • Newbie
  • *
  • Offline Offline
  • Posts: 4
    • View Profile
Please advice how to integrate your example of inserting rows
« on: February 15, 2005, 04:13:09 AM »

Hi

I tried to use your example of inserting rows limiting 10 per page but can't seem to get it working. Hope you do not mind showing me how.


<?php 

include("database.php"); 
include(
"user.php"); 
checklogin(); 


if(isset(
$_POST['Submit'])) 

    $total $_POST['total']; 
    $td 0
    $i 0

    for($i 1$i <= $total$i++) 
    
        if(isset($_POST["d$i"])) 
        
            mysql_query("DELETE FROM user_list WHERE id=".$_POST["d$i"],$link); 
            $td++; 
        
    

    $msg "$td record(s) deleted!"


$result mysql_query("Select * from user_list",$link); 
$num mysql_num_rows($result); 
$n 0
?> 


Code: [Select]
<h3>List of Records</h3>

<form name="form1" method="post" action="">
  <p>&nbsp;</p>
  <table width="70%" border="1" cellpadding="1" cellspacing="1" bordercolor="#000000">
    <tr bgcolor="#CCCCCC">
      <td width="3%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
      <td width="3%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>ID</strong></font></td>
      <td width="15%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>User</strong></font></td>
      <td width="15%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Password</strong></font></td>
      <td width="20%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Date Joined</strong></font></td>
      <td width="20%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Last Login</strong></font></td>
      <td width="10%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Count</strong></font></td>
    </tr>
    <?php while($row mysql_fetch_array($resultMYSQL_BOTH)){
$n++;
?>

    <tr>
      <td><input type="checkbox" name="d<?php echo $n;?>" value="<?php echo $row['id'];?>"></td>
      <td><a href="newrecord.php?id=<?php echo $row['id']?>"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['id'];?></font></a></td>
      <td><a href="newrecord.php?id=<?php echo $row['name']?>"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['username'];?></font></a></td>
      <td><a href="newrecord.php?id=<?php echo $row['password']?>"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['password'];?></font></a></td>
      <td><a href="newrecord.php?id=<?php echo $row['joined']?>"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['joined'];?></font></a></td>
      <td><a href="newrecord.php?id=<?php echo $row['lastlogin']?>"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['lastlogin'];?></font></a></td>
      <td><a href="newrecord.php?id=<?php echo $row['count']?>"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['logincount'];?></font></a></td>
    </tr>
    <?php

 
}?>

    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="Submit" value="Delete"> <input name="total" type="hidden" id="total" value="<?php echo $n?>"></td>
    </tr>
  </table>
<p>&nbsp;</p></form>
Logged

Saleh

  • Administrator
  • Full Member
  • *****
  • Offline Offline
  • Posts: 222
    • View Profile
    • PHP Simplicity
Re: Please advice how to integrate your example of inserting rows
« Reply #1 on: February 15, 2005, 05:55:45 AM »

what is the query you are using? is it $result mysql_query("Select * from user_list",$link);  ?
what is the php filename ?
Logged

We don't need a reason to help people

edhan

  • Newbie
  • *
  • Offline Offline
  • Posts: 4
    • View Profile
Re: Please advice how to integrate your example of inserting rows
« Reply #2 on: February 15, 2005, 06:35:40 PM »

Hi Saleh

Yes. The query is $result = mysql_query("Select * from user_list",$link);
and the php filename is listrecord.php

Thanks!

Edward
Logged

Saleh

  • Administrator
  • Full Member
  • *****
  • Offline Offline
  • Posts: 222
    • View Profile
    • PHP Simplicity
Re: Please advice how to integrate your example of inserting rows
« Reply #3 on: February 16, 2005, 10:03:34 AM »

I've posted the solution on programmingtalk.com :)
Logged

We don't need a reason to help people

edhan

  • Newbie
  • *
  • Offline Offline
  • Posts: 4
    • View Profile
Re: Please advice how to integrate your example of inserting rows
« Reply #4 on: February 17, 2005, 01:19:46 AM »

Hi Saleh

Still does not show anything when I add your example. Please advice. Thank you and sorry to trouble you.


<?php 

include("database.php"); 
include(
"user.php"); 
checklogin(); 


if(isset(
$_POST['Submit'])) 

    $total $_POST['total']; 
    $td 0
    $i 0

    for($i 1$i <= $total$i++) 
    
        if(isset($_POST["d$i"])) 
        
            mysql_query("DELETE FROM user_list WHERE id=".$_POST["d$i"],$link); 
            $td++; 
        
    

    $msg "$td record(s) deleted!"


$result mysql_query("Select * from user_list",$link); 
$num mysql_num_rows($result); 
$n 0
?> 
<?PHP
//check if the starting row variable was passed in the URL or not
if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) {
  //we give the value of the starting row to 0 because nothing was found in URL
  $startrow 0;
//otherwise we take the value from the URL
} else {
  $startrow = (int)$_GET['startrow'];
}
?>


Code: [Select]
<h3>List of Records</h3>

<form name="form1" method="post" action="">
  <p>&nbsp;</p>
  <table width="70%" border="1" cellpadding="1" cellspacing="1" bordercolor="#000000">
    <tr bgcolor="#CCCCCC">
      <td width="3%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
      <td width="3%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>ID</strong></font></td>
      <td width="15%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>User</strong></font></td>
      <td width="15%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Password</strong></font></td>
      <td width="20%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Date Joined</strong></font></td>
      <td width="20%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Last Login</strong></font></td>
      <td width="10%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Count</strong></font></td>
    </tr>
<?PHP
//this part goes after the checking of the $_GET var
$fetch = mysql_query("SELECT username, password, joined, lastlogin, logincount FROM user_list LIMIT $startrow, 10")or
die(mysql_error());
?>
    <tr>
      <td><input type="checkbox" name="d<?php echo $n;?>" value="<?php echo $row['id'];?>"></td>
      <td><a href="newrecord.php?id=<?php echo $row['id']?>"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['id'];?></font></a></td>
      <td><a href="newrecord.php?id=<?php echo $row['name']?>"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['username'];?></font></a></td>
      <td><a href="newrecord.php?id=<?php echo $row['password']?>"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['password'];?></font></a></td>
      <td><a href="newrecord.php?id=<?php echo $row['joined']?>"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['joined'];?></font></a></td>
      <td><a href="newrecord.php?id=<?php echo $row['lastlogin']?>"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['lastlogin'];?></font></a></td>
      <td><a href="newrecord.php?id=<?php echo $row['count']?>"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['logincount'];?></font></a></td>
    </tr>
<?PHP
//now this is the link..
echo '<a href="listrecord.php?startrow='.($startrow+10).'">Next</a>';
?>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="Submit" value="Delete"> <input name="total" type="hidden" id="total" value="<?php echo $n?>"></td>
    </tr>
  </table>
<p>&nbsp;</p></form>
Logged

Saleh

  • Administrator
  • Full Member
  • *****
  • Offline Offline
  • Posts: 222
    • View Profile
    • PHP Simplicity
Re: Please advice how to integrate your example of inserting rows
« Reply #5 on: February 17, 2005, 04:10:39 AM »

Code: [Select]
<?php

include("database.php");
include(
"user.php");
checklogin();


if(isset(
$_POST['Submit']))
{
    
$total $_POST['total'];
    
$td 0;
    
$i 0;

    for(
$i 1$i <= $total$i++)
    {
        if(isset(
$_POST["d$i"]))
        {
            
mysql_query("DELETE FROM user_list WHERE id=".$_POST["d$i"],$link);
            
$td++;
        }
    }

    
$msg "$td record(s) deleted!";
}

//check if the starting row variable was passed in the URL or not
if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) {
  
//we give the value of the starting row to 0 because nothing was found in URL
  
$startrow 0;
//otherwise we take the value from the URL
} else {
  
$startrow = (int)$_GET['startrow'];
}

//this part goes after the checking of the $_GET var
$fetch mysql_query("SELECT username, password, joined, lastlogin, logincount FROM user_list LIMIT $startrow, 10")or
die(
mysql_error());

$num mysql_num_rows($fetch);
$n 0;
?>


<h3>List of Records</h3>

<form name="form1" method="post" action="">
  <p>&nbsp;</p>
  <table width="70%" border="1" cellpadding="1" cellspacing="1" bordercolor="#000000">
    <tr bgcolor="#CCCCCC">
      <td width="3%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
      <td width="3%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>ID</strong></font></td>
      <td width="15%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>User</strong></font></td>
      <td width="15%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Password</strong></font></td>
      <td width="20%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Date Joined</strong></font></td>
      <td width="20%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Last Login</strong></font></td>
      <td width="10%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Count</strong></font></td>
    </tr>
<?php
  
while ($row mysql_fetch_array($fetch)) {
?>

    <tr>
      <td><input type="checkbox" name="d<?php echo $n;?>" value="<?php echo $row['id'];?>"></td>
      <td><a href="newrecord.php?id=<?php echo $row['id']?>"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['id'];?></font></a></td>
      <td><a href="newrecord.php?id=<?php echo $row['name']?>"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['username'];?></font></a></td>
      <td><a href="newrecord.php?id=<?php echo $row['password']?>"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['password'];?></font></a></td>
      <td><a href="newrecord.php?id=<?php echo $row['joined']?>"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['joined'];?></font></a></td>
      <td><a href="newrecord.php?id=<?php echo $row['lastlogin']?>"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['lastlogin'];?></font></a></td>
      <td><a href="newrecord.php?id=<?php echo $row['count']?>"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['logincount'];?></font></a></td>
    </tr>
<?PHP
}
?>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="Submit" value="Delete"> <input name="total" type="hidden" id="total" value="<?php echo $n?>"></td>
    </tr>
  </table>
<p>&nbsp;</p></form>
<?php
//now this is the link..
echo '<a href="listrecord.php?startrow='.($startrow+10).'">Next</a>';
?>
try this :)
« Last Edit: February 17, 2005, 04:18:58 AM by Saleh »
Logged

We don't need a reason to help people

edhan

  • Newbie
  • *
  • Offline Offline
  • Posts: 4
    • View Profile
Re: Please advice how to integrate your example of inserting rows
« Reply #6 on: February 17, 2005, 08:08:19 AM »

Hi Saleh

Thanks a million! It is working except that I have to figure out how to detect the end of file as this method, even it is already showing end of record (1500), you still can press next and nothing is showing thereafter since it is already having no record.

If you have a way to detect end of record and let me know it will be great!

Thanks again!

Regards
Edward
Logged
 

+ Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.
Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What is the answer to one plus one? (in numbers):