PHP get values from another page

后端 未结 2 1813
天命终不由人
天命终不由人 2021-01-25 17:51

I have this page admin_inquiry.php(page1) which has a dynamic table that shows rows of records.I want to get the values from 2 columns, ContactNo, and message. The contactno col

2条回答
  •  日久生厌
    2021-01-25 18:12

    If you are still having problems solving this, in your table include a html form

    UPDATE including pagination

    first solution, create a file and call it contact.php

    query('SELECT * FROM contactdetails');
    
    //creating pagination
    $nav_counter = basename($_SERVER['SCRIPT_FILENAME']); //getting name of the current page
    $current_page = $nav_counter;
    $nav_counter = rtrim($nav_counter, ".php"); //getting the name of the current page and removing the extension
    
    //creating pagination pages
    $next_page = $nav_counter + 1;
    $prev_page = $nav_counter - 1;
    
    //getting row count, we are going to use it to limit our query and to create pagination
    $row_count = $contacts->rowCount();
    
    //number of records to show per page
    $num_records = 5;
    
    //getting the last page
    $last_page = ($row_count / $num_records) - 1;
        if(!is_int($last_page)){
        $last_page = (int)$last_page + 1;
      }
    
    //displaying records 
    $start = 0;
    $limit = $num_records; //number of records to show
    
    if ($current_page !== 'admin_inquiry.php'){
        $start = ($limit * $nav_counter);
    }
    
    //getting number of rows left in the table
    $rows_left = $db->query("SELECT * FROM contactdetails ORDER BY ID limit $start,$limit");
    $num_rows = $rows_left->rowCount();
    
    //if records left in the table is less than the number of records to show $num_records
    if ($num_rows < $num_records) {
        $limit = $num_rows; //limit is equal to the number of records left in the table
    }
    
    //getting number of records from the table
    $contacts = $db->query("SELECT * FROM contactdetails ORDER BY ID limit $start,$limit");
    
    //displaying pagination and creating pages if they don't exists
     $pages = array();
    for ($counter = 1; $counter <= $last_page; $counter++) { 
     $pages[] = $counter;
    }
    //storing pages in array and creating a page if it doesn't exist
    foreach ($pages as $num) {
    $page = $num.'.php';
    if(file_exists($page)== false && $num <= $last_page){
        copy('admin_inquiry.php', $page);
     }
    } 
    ?>
    

    create a pagination.php file

    
    

    create a css file admin.css

    table {
    width: 100%;
    margin: 0 auto;
    }
    table, td, th {
    border: 1px solid black;
     }
    
    th {
    height: 50px;
    }
    #div{
    width: 40%;
    margin: 0 auto;
    }
    .pagenav a{
    display: inline;
    width: 100px;
    padding: 10px;
    height: 100px;
    border-radius: 50px;
    font-size: 20px;
    color: #fff;
    line-height: 50px;
    text-align: center;
    text-decoration: none;
    background-color: #0186ba;
      }
    .pagenav a:hover{
    background-color: #fff;
    border: 1px solid #000;
    color: #000;
    }
    .hide {
    display: none !important;
    }
    p{
    text-align: center;
    }
    

    admin_iquiry.php file

     
     
     
     
       
       
     
     
     
    ID Contact No. Message

    admin_sms.php

    
    

    html code

    Message for:

    enter image description here

    Second solution using $_GET

    
    
    
    
        
        
    
    
    
    foreach ($contacts as $value) : ?> //use id of the contact no and in the next page use that id to query data related to that id
    ID Contact No. Message
    Send Sms

    admin_sms.php

    query("SELECT * FROM contactdetails WHERE ID = $id");
     foreach ($results as  $value) {
           $contactNo = $value['ContactNO'];
          $message = $value['Message'];
         }
       }
    
     ?>
    

    in your html

    Message for:

    enter image description here

提交回复
热议问题