Hi,

I have a table (addressbook) with over 2000 names and addresses. I currently have a php script to update it but it firsts lists out all 2000 odd entries on screen and then i have a radip button to choose one of them to update.

This obviously means the page takes forever to load. Is there a way I can have :

a. A page that comes up on screen with say A-F G-M N -S T-Z ?

b. If a user clicks on A-F , then the list of all A-F appears along with the necessary fields ( I can figure out how to do this using LIKE)

c. Can a user update multiple records at one time ? Say there are 2 addresses each of John Smith and Jane Doe and both have moved home. If the user clicked on G-M, then could select both John and Jane's records and update both at the same time ? This is especially helpful if one needs to copy the same data to multiple records (say if J & J shared the same new address or worked at the same company whose tel number has changed)

Need guidance on (a) and (c) above pl.

Thanks. Swati

    Well, just add a line with the links and make them link like so:

    domain.com/update.php?sect=af

    then, do your query... and of course, default to AF

    <?php
    if(empty($_GET['sect']) || !isset($_GET['sect']))
    {
      $_GET['sect'] == 'AF';
    }
    
    switch(strtoupper($_GET['sect']))
    {
      case 'AF':
        $sect = 1;
        break;
      case 'GM':
        $sect = 2;
        break;
      case 'NS':
        $sect=3;
        break;
      case 'TZ':
        $sect=4;
        break;
      default:
        $sect=1;
        break;
    }
    
    $sections = array(
        1=>array('A', 'B', 'C', 'D', 'E', 'F'),
        2=>array('G', 'H', 'I', 'J', 'K', 'L', 'M'),
        3=>array('N', 'O', 'P', 'Q', 'R', 'S'),
        4=>array('T', 'U', 'V', 'W', 'X', 'Y', 'Z')
    );
    
    $query = "SELECT * FROM `table` WHERE (";
    foreach($sections[$sect] as $let)
    {
      $query .= "lastName LIKE '$let%',";
    }
    $query = substr($query, 0, -1); // removes last comma
    $query .= ") ORDER BY lastName ASC";
    
    // and so on...
    ?>

    To select each item to update, just make the checkboxes an array:

    <input type="checkbox" name="edit[]" value="mysql_row_id">

    Then, just make sure that you add those IDs as hidden values in the next form, and then do a simple update:

    UPDATE table SET col=value, col=val, col=val, col=val WHERE id=$id1 OR id=$id2

    Or, you can run two separate update queries, and just call the second ID... but I'm thinking what I have above would work.

    ~Brett

      Hi Brett,

      Thanks for the help. I got a bit of problem doing the multiple choice updates. I already had it in 2 separate scripts so i preferred to leave it as it is and am not able to figure out why the I am not able to select more than 1 record , even while holding down the control key.

      The 1st script has the foll. code (duly snipped)

      
      $result = mysql_query("SELECT * FROM `List`WHERE  `Company` LIKE '$alphabet%' ORDER BY `Company` asc ") or die (mysql_error ());
      
      
      if ($myrow = mysql_fetch_array($result)) {
      
      
        do {
      
      printf("<tr><td>
      <input type= \"radio\" name=\"choice[]\" value=%d><td>
      <font size=2 face=Tahoma color=blue>%s<td>
      </tr>",
       $myrow["Customerid"],
       $myrow["Company"] );
      
      
        } while ($myrow = mysql_fetch_array($result));
      
      } else {
      
      echo "Sorry, no records were found!";	
      }
      ?>
      
         </table>
      
      <input type="submit" name="choice" value="Proceed">
      

      The 2nd script has

      
      <? include("protect.php"); ?>
      
      <?php
      $cid = $_POST["choice"];
      
      

        because..... it's a radio button.

        If you read up on Radio buttons on the w3schools.com website, it tells you that as long as the radio buttons names are the same, only 1 will be chosen. For multiple choices, you need to use a checkbox (or a multiple listbox).

        ~Brett

          Write a Reply...