www.webdeveloper.com
Results 1 to 4 of 4

Thread: Show table data in div

  1. #1
    Join Date
    Dec 2011
    Posts
    39

    Show table data in div

    Dear Experts

    I have following data

    PHP Code:
    <?php 
        
    if(isset($_get['submit']))
        {
            
    // Connection variables 
            
    $host="localhost"
            
    $username="root"
            
    $password=""
            
    $db_name="asia";  
            
            
    // Connect to database 
            
    $con=mysqli_connect("$host""$username""$password"); 
            
            
    // Connect result 
            
    if(!$con){ 
                die(
    'Error Connecting to Database: ' mysqli_error()); 
            
    //die '<script type="text/javascript">alert("Error Connecting to Database"). mysqli_error($con);</script>';  
            

            else 
            { 
                echo 
    "<script type=\"text/javascript\">alert(\"Connected\")" mysqli_error($con) . ";</script>";  
            } 
            
            
    // Database Selection 
            
    $sel =mysqli_select_db($con,"$db_name"); 
            
            
    // Database Selection result 
            
    if(!$sel){ 
            die(
    'Error selecting Database: ' mysqli_error()); 
            } 
            else 
            { 
            
    //echo "Database Selected" . mysqli_error($con); 
            
    echo "<script type=\"text/javascript\">alert(\"Database Selected\")" mysqli_error($con) . ";</script>";  
            } 
            
    //$result = mysqli_query("select sno,packing,weight from test");   
              
    $result $con->query("select sno,packing,weight from test");  
              
             if(!
    $result){ 
              echo 
    'select query error or data not found'
              } 
              else 
              { 
              echo 
    'data found'

        }
        
                    }
          
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>BROWSE DATA</title>
    <style type="text/css">
        
        html {
        overflow:auto;
        }
        
        body {
        background-color:#FFFFFF;
        margin:0 auto;
        }
        
            
        #mypopup2
        {
        float: left;
        width: 250px; height: 350px;
        background: #90bade; 
        border: 1px solid #069;
        text-align:center;
        padding:2px;
        margin-top:150px;
        margin-left:50px;
        overflow:auto;
        }
        
        
        #header
        {
        background-color:#3399FF;
        background-position:left center;
        line-height:25px;
        font-size:22px;
        color:#FFFF33;
        font-weight:600;
        border-bottom:1px solid #6699CC;
        padding:10px;
        }
        
        .design12 {
        background-image:url(Images/disk.png);
        background-position:left center;
        background-repeat:no-repeat;
        background-color:#FF9;
        border:1px solid #88de85;
        -webkit-border-radius:7px;
        -moz-border-radius:7px;
        font-size:15px;
        font-weight:700;
        font-family:verdana;
        color:#0d5f83;
        width:100px;
        cursor:hand;
        padding:9px;
        }
        
        .design13 {
        background-image:url(Images/reload_16.png);
        background-position:left center;
        background-repeat:no-repeat;
        background-color:#CF9;
        border:1px solid #88de85;
        -webkit-border-radius:7px;
        -moz-border-radius:7px;
        font-size:15px;
        font-family:verdana;
        font-weight:700;
        color:#0d5f83;
        width:100px;
        cursor:hand;
        padding:9px;
        }
        
        
        .txt
        {
        width:150px;
        font-family:Arial, Helvetica, sans-serif;
        font-size:14px;
        font-weight:300;
        }
        
        td
        {color:#6600CC;}
        
        </style>
    </head>
    <body>
    <div id="mypopup2" >
      <div id="header"><img src="Images/book_open.png" align="left">Brows Data</div>
      <div style="margin-top:10px;">
        
        <form name="form1" method="get" action="#">
          
          <table border="1" cellpadding="1" cellspacing="1" bgcolor="silver" align="center" width="95%" >
            <th width="20%">Code</th>
              <th width="50%">Product</th>
              <th width="20%">Weight</th>
          </table>
          
          <div style="margin-top:125px;text-align:center;margin-top:100px;">
            <input type="submit" name="submit" value="Brow" class="design12">
            <input type="submit" name="button2" value="Clear" class="design13">
          </div>
          
        </form>
        
      </div>
    </div>
    </body>
    </html>
    When I run these codes it show following php file

    http://i40.tinypic.com/9jd5s6.jpg

    I want to display table data into above div under table columns

    Please help
    Attached Images Attached Images
    Last edited by tqmd1; 11-12-2013 at 01:17 AM. Reason: edit

  2. #2
    Join Date
    Oct 2013
    Location
    delhi
    Posts
    2
    <table border="1" cellpadding="1" cellspacing="1" bgcolor="silver" align="center" width="95%" >
    <th width="20%">Code</th>
    <th width="50%">Product</th>
    <th width="20%">Weight</th>
    <?php
    foreach($result as $resultkey =>$resultvalue)
    {

    ?>
    <tr>
    <td><?php echo $resultvalue['code']; ?></td>
    <td><?php echo $resultvalue['product']; ?></td>
    <td><?php echo $resultvalue['weight']; ?></td>


    </tr
    <?php
    }
    ?>
    </table>
    visit site: www.acetrum.com

  3. #3
    Join Date
    Dec 2011
    Posts
    39
    Dear Sir,

    After adding your codes, I have modified php as

    PHP Code:
    <?php 
        
    if(isset($_GET['submit']))
        {
            
    // Connection variables 
            
    $result="";
            
    $host="localhost"
            
    $username="root"
            
    $password=""
            
    $db_name="asia";  
            
            
    // Connect to database 
            
    $con=mysqli_connect("$host""$username""$password"); 
            
            
    // Connect result 
            
    if(!$con){ 
                die(
    'Error Connecting to Database: ' mysqli_error()); 
            
    //die '<script type="text/javascript">alert("Error Connecting to Database"). mysqli_error($con);</script>';  
            

            else 
            { 
                echo 
    "<script type=\"text/javascript\">alert(\"Connected\")" mysqli_error($con) . ";</script>";  
            } 
            
            
    // Database Selection 
            
    $sel =mysqli_select_db($con,"$db_name"); 
            
            
    // Database Selection result 
            
    if(!$sel){ 
            die(
    'Error selecting Database: ' mysqli_connect_error()); 
            } 
            else 
            { 
            
    //echo "Database Selected" . mysqli_error($con); 
            
    echo "<script type=\"text/javascript\">alert(\"Database Selected\")" mysqli_error($con) . ";</script>";  
            } 
            
    //$result = mysqli_query("select sno,packing,weight from test");   
              
    $result $con->query("select sno,packing,weight from test");  
              
             if(!
    $result){ 
              echo 
    'select query error or data not found'
              } 
              else 
              { 
              echo 
    'data found'
          }
          }
          
    ?>



    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>BROWSE DATA </title>

        <style type="text/css">
        
        html {
        overflow:auto;
        }
        
        body {
        background-color:#FFFFFF;
        margin:0 auto;
        }
        
            
        #mypopup2
        {
        float: left;
        width: 250px; height: 350px;
        background: #90bade; 
        border: 1px solid #069;
        text-align:center;
        padding:2px;
        margin-top:150px;
        margin-left:50px;
        overflow:auto;
        }
        
        
        #header
        {
        background-color:#3399FF;
        background-position:left center;
        line-height:25px;
        font-size:22px;
        color:#FFFF33;
        font-weight:600;
        border-bottom:1px solid #6699CC;
        padding:10px;
        }
        
        .design12 {
        background-image:url(Images/disk.png);
        background-position:left center;
        background-repeat:no-repeat;
        background-color:#FF9;
        border:1px solid #88de85;
        -webkit-border-radius:7px;
        -moz-border-radius:7px;
        font-size:15px;
        font-weight:700;
        font-family:verdana;
        color:#0d5f83;
        width:100px;
        cursor:hand;
        padding:9px;
        }
        
        .design13 {
        background-image:url(Images/reload_16.png);
        background-position:left center;
        background-repeat:no-repeat;
        background-color:#CF9;
        border:1px solid #88de85;
        -webkit-border-radius:7px;
        -moz-border-radius:7px;
        font-size:15px;
        font-family:verdana;
        font-weight:700;
        color:#0d5f83;
        width:100px;
        cursor:hand;
        padding:9px;
        }
        
        
        .txt
        {
        width:150px;
        font-family:Arial, Helvetica, sans-serif;
        font-size:14px;
        font-weight:300;
        }
        
        td
        {color:#6600CC;}
        
        </style>
        </head>
        
        <body>

        <div id="mypopup2" >
        <div id="header"><img src="Images/book_open.png" align="left">Brows Data</div>
        <div style="margin-top:10px;">
        <form name="form1" method="get" action="#">
        
    <table border="1" cellpadding="1" cellspacing="1" bgcolor="silver" align="center" width="95%" >
    <th width="20%">Code</th>
    <th width="50%">packing</th>
    <th width="20%">Weight</th>
    <?php 
    foreach($result as $resultkey =>$resultvalue)
    {

    ?>
    <tr>
    <td><?php echo $resultvalue['sno']; ?></td>
    <td><?php echo $resultvalue['packing']; ?></td>
    <td><?php echo $resultvalue['weight']; ?></td>


    </tr
    <?php
    }
    ?>
    </table>     

     <div style="margin-top:125px;text-align:center;margin-top:100px;"><input type="submit" name="submit" value="Brow" class="design12">
        <input type="submit" name="button2" value="Clear" class="design13"></div>
        </form>
        </div>
        </div>
    </body>
    </html>
    Now, on this line
    PHP Code:
    foreach($result as $resultkey =>$resultvalue
    it show this error message
    Notice: Undefined variable: result in C:\wamp\www\data_find_with_button_acetrum_.php on line 156


    I think your codes runs when php file runs, so this time variable $result is not exists there.

    If we run your codes after press brow button then i think there will not be any error.

    It is my openion but you think better.

    Please modify.

    my skype id tqmd_mehmood

    Thanks

  4. #4
    Join Date
    Oct 2013
    Location
    delhi
    Posts
    2
    try............................................................
    <?php
    // Connection variables
    $result="";
    $host="localhost";
    $username="root";
    $password="";
    $db_name="asia";

    // Connect to database
    $con=mysqli_connect("$host", "$username", "$password");

    // Connect result
    if(isset($_GET['submit']))
    {

    if(!$con){
    die('Error Connecting to Database: ' . mysqli_error());
    //die '<script type="text/javascript">alert("Error Connecting to Database"). mysqli_error($con);</script>';
    }
    else
    {
    echo "<script type=\"text/javascript\">alert(\"Connected\")" . mysqli_error($con) . ";</script>";
    }

    // Database Selection
    $sel =mysqli_select_db($con,"$db_name");

    // Database Selection result
    if(!$sel){
    die('Error selecting Database: ' . mysqli_connect_error());
    }
    else
    {
    //echo "Database Selected" . mysqli_error($con);
    echo "<script type=\"text/javascript\">alert(\"Database Selected\")" . mysqli_error($con) . ";</script>";
    }
    //$result = mysqli_query($con, "select sno,packing,weight from test");
    $result = $con->query("select sno,packing,weight from test");



    if(!$result){
    echo 'select query error or data not found';
    }
    else
    {
    echo 'data found';
    }
    }
    ?>



    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>BROWSE DATA </title>

    <style type="text/css">

    html {
    overflow:auto;
    }

    body {
    background-color:#FFFFFF;
    margin:0 auto;
    }


    #mypopup2
    {
    float: left;
    width: 250px; height: 350px;
    background: #90bade;
    border: 1px solid #069;
    text-align:center;
    padding:2px;
    margin-top:150px;
    margin-left:50px;
    overflow:auto;
    }


    #header
    {
    background-color:#3399FF;
    background-position:left center;
    line-height:25px;
    font-size:22px;
    color:#FFFF33;
    font-weight:600;
    border-bottom:1px solid #6699CC;
    padding:10px;
    }

    .design12 {
    background-image:url(Images/disk.png);
    background-position:left center;
    background-repeat:no-repeat;
    background-color:#FF9;
    border:1px solid #88de85;
    -webkit-border-radius:7px;
    -moz-border-radius:7px;
    font-size:15px;
    font-weight:700;
    font-family:verdana;
    color:#0d5f83;
    width:100px;
    cursor:hand;
    padding:9px;
    }

    .design13 {
    background-image:url(Images/reload_16.png);
    background-position:left center;
    background-repeat:no-repeat;
    background-color:#CF9;
    border:1px solid #88de85;
    -webkit-border-radius:7px;
    -moz-border-radius:7px;
    font-size:15px;
    font-family:verdana;
    font-weight:700;
    color:#0d5f83;
    width:100px;
    cursor:hand;
    padding:9px;
    }


    .txt
    {
    width:150px;
    font-family:Arial, Helvetica, sans-serif;
    font-size:14px;
    font-weight:300;
    }

    td
    {color:#6600CC;}

    </style>
    </head>

    <body>

    <div id="mypopup2" >
    <div id="header"><img src="Images/book_open.png" align="left">Brows Data</div>
    <div style="margin-top:10px;">
    <form name="form1" method="get" action="#">

    <table border="1" cellpadding="1" cellspacing="1" bgcolor="silver" align="center" width="95%" >
    <th width="20%">Code</th>
    <th width="50%">packing</th>
    <th width="20%">Weight</th>
    <?php
    if(isset($_GET['submit']))
    {
    while ($row = mysqli_fetch_assoc($result)) {


    ?>
    <tr>
    <td><?php echo $row['sno']; ?></td>
    <td><?php echo $row['packing']; ?></td>
    <td><?php echo $row['weight']; ?></td>


    </tr>
    <?php
    }
    }
    ?>
    </table>

    <div style="margin-top:125px;text-align:center;margin-top:100px;"><input type="submit" name="submit" value="Brow" class="design12">
    <input type="submit" name="button2" value="Clear" class="design13"></div>
    </form>
    </div>
    </div>
    </body>
    </html>

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