www.webdeveloper.com
Results 1 to 2 of 2

Thread: Show data with link

  1. #1
    Join Date
    Dec 2011
    Posts
    39

    Show data with link

    Dear Experts,

    I have following codes

    PHP Code:
    $sql "SELECT * from contacts order by name" ;
    $select mysqli_query($con,$sql);
    $row=mysqli_num_rows($select);
    //echo ($row);
    while($row mysqli_fetch_array($select))
    {
        echo 
    "<tr>";
        echo 
    "<td> <a href='edit.php?id=".$row['id']."'>
        <img border=noborder src=images/pencil.png title=Display></a></td>"
    ;
        echo 
    "<td align='left'> " $row["name"].  "</td>";
        echo 
    "<td> " $row["moba"]. "</td>";
        echo 
    "<td> " $row["city"]. "</td>";
        echo 
    "<td> " $row["country"] . "</td>";
        echo 
    "</tr>";
    }
    ?>        </tbody>
           </table> 
    and Edit.php has this data

    PHP Code:
    <?php
        
    require_once("connect.php");
            
    $sno =$_GET['id']; 
            
    $query ="SELECT * FROM contacts WHERE id = $sno ";
            
    $result=mysqli_query($con$query);
            
            if (
    $result){
                
                      while (
    $row mysqli_fetch_array($result))
                      {
                   echo 
    $row['name']."<br>";
                      echo 
    $row['moba'];
                      }
                     }else{
                  echo 
    "no data found";
              }
    ?>
    I press a link then related data must appear in related textboxes against selected id like shown in image

    http://i41.tinypic.com/2qdmo3m.jpg

    Please help

  2. #2
    Join Date
    Nov 2013
    Posts
    33
    you could create an array
    PHP Code:
    $inputs = array();
    if (
    $result){ 
         while (
    $row mysqli_fetch_array($result)) {
            
    $inputs['name'] = $row['name'];
            
    $inputs['moba'] = $row['moba']; 
        } 
    }else{ 
        echo 
    "no data found"

    then use the array in your input fields

    PHP Code:
    <form>
        <input type="text" name="name" value="<?php echo isset($inputs['name']) ? $inputs['name'] : '' ?>" >
        <input type="text" name="moba" value="<?php echo isset($inputs['moba']) ? $inputs['moba'] : '' ?>" >
    </form>
    or your could set session vars

    PHP Code:
    session_start();
    if (
    $result){ 
         while (
    $row mysqli_fetch_array($result)) {
            
    $_SESSION['name'] = $row['name'];
            
    $_SESSION['moba'] = $row['moba']; 
        } 
    }else{ 
        echo 
    "no data found"

    then use the set session vars like so.

    PHP Code:
    <form>
        <input type="text" name="name" value="<?php echo isset($_SESSION['name']) ? $_SESSION['name'] : '' ?>" >
        <input type="text" name="moba" value="<?php echo isset($_SESSION['moba']) ? $_SESSION['moba'] : '' ?>" >
    </form>
    this should give you an idea on how to do what you need.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles