Jump to content

Recommended Posts

Hi,

 

I am a first timer here and I hope to enjoy the forum in the long run. 

 

I have a question regarding mass deletion and pagination or paging.

 

I have the following code/method which displays the search result and I want, within the search result, to allow staff or members with appropriate access to be able to delete (multiple records via checklist) records from the database. 

 

The methods are under index.php and here is the code below:

<?php
require_once('__globals.php');
// php libs
require_once('../includes/__lib_utils.php');
require_once('__lib_dbutils.php');

getDB();
global $link;

// init required fields to zero-length string;
$method=param('method'); // would like to use a switch statment here, but strings not supported
//$fld_val=urlencode( param('fld_val') );
$title="";
$sql="";

echo "<!--$method-->";

if ( $method == "" ) { // default method
    // show search box
    $title="search";
    require_once('_dsp_header.php');
    require_once('_dsp_search.php');
    require_once('_dsp_footer.php');
    
}
elseif ( $method=="search_contentGroup" ) {    
    // show search box
    $title="search";
    require_once('_dsp_header.php');
    require_once('_dsp_search_contentGroup.php');
    require_once('_dsp_footer.php');
    
}

elseif ( $method=="results" ) {    
    $lname=param("last_name");
$fname=param("first_name");
$company=param("company");
    $title="Search by User for '$lname' results";        
    $sql="select id, first_name, last_name, company from name where last_name like '%" . $lname . "%' AND first_name like '%" . $fname . "%' order by company, last_name";
    $result = mssql_query($sql, $link);
    require_once('_dsp_header.php');
    require_once('_dsp_results.php');
    require_once('_dsp_footer.php');
      
} 
elseif ( $method=="results_contentGroup" ) {    
    $contentGroup=param("content_group");
    $title="Search by Content Group for '$contentGroup' results";    
    $sql="select id, first_name, last_name, company from name where id in (select nameId from userContentGroup where contentGroupId in (select id from contentGroup where name like '%" . $contentGroup . "%')) order by company, last_name";
    $result = mssql_query($sql, $link);
    require_once('_dsp_header.php');
    require_once('_dsp_results.php');
    require_once('_dsp_footer.php');
      
} 

elseif ( $method=="show" ) {    
    $title="user info";
    $id=param("id");
    $sql="select id, first_name, last_name, company, email, password from name where id='" . $id . "'";
    $result = mssql_query($sql, $link);
    if (mssql_num_rows($result)==1) {
        // get all content groups
        $acg = mssql_query("select id,name from contentGroup order by name", $link);

        // get existing content groups
        $ecg = mssql_query("select contentGroupId from usercontentGroup where nameId='" . $id ."'", $link);
        $earr=array();
        $cnt=0;
        while($ecgr = mssql_fetch_row($ecg)) {
            $earr[$cnt]=$ecgr[0];
            $cnt++;
        }

        while($row = mssql_fetch_row($result)) {
            // get existing content groups too
            require_once('_dsp_header.php');
            require_once('_dsp_show.php');
            require_once('_dsp_footer.php');
        }
    } else {
        echo "id not found: '$id'";
    }
}    
elseif ( $method=="update" ) {    
    $id=param("id");
    $contentGroupId=param("contentGroup");
    $password=param("password");

    // delete existing first
    $sql="delete from userContentGroup where nameId='" . $id . "'";
    $result = mssql_query($sql, $link);
    $ucnt=0;
    
    for ($i=0; $i<count( $contentGroupId ); $i++ ) {
        $sql="insert into userContentGroup (nameId, contentGroupId) values ('$id', '$contentGroupId[$i]' )";
        echo $sql;
        $result = mssql_query($sql, $link);
    
        if (mssql_rows_affected($link)==1) {
            $ucnt++;
        }
    }        
    if ( count( $contentGroupId ) != $ucnt ) {
        $msg=urlencode("not all values updated");
    }  
    
    // update password
    if ( strlen(trim($password)) > 0 ) {
        $sql="update name set password = '$password' where id='" . $id . "'";
        $result = mssql_query($sql, $link);
        if ( mssql_rows_affected($link)!=1 ) {
            $msg = $msg . "<br>Password NOT updated";
        }    
    }    
        

    header("Location: index.php?method=show&id=$id&msg=$msg");    
} else {
    $title="method not found / supported";
    require_once('_dsp_header.php');
    echo "method not found / supported";
    require_once('_dsp_footer.php');
}
?>

 

I hope I'm making sense and thank you very much for your help.  I have also attached the files in case you wanted to see them. 

 

[move]Thank you for your help[/move]

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/62694-mass-deletionpaging/
Share on other sites

Your question is a little general, and that's a lot of code for someone to comb through. Try and specify a little more so it's easier for us to answer the question.

With mass deletion, use the id's of the items selected and use those as conditions for a delete query. I'm sure there's an alternative to "where `id`=x or `id`=y or ...", but I don't really know what it is at the moment.

If you need paging, the only data you need to start off with is how many to display per page, and how many there are total. Beyond that, it's a little bit of tedious work to put everything together. Look into MySQL LIMIT statements to select only the data for that page.

Link to comment
https://forums.phpfreaks.com/topic/62694-mass-deletionpaging/#findComment-312107
Share on other sites

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.