how to print the output data from php to html?

Discussion in 'PHP' started by mark103, Apr 5, 2013.

  1. #1
    Hi guys,

    I need your help have stored the information in mysql database where I can print the output data in my php using with this following code:

    
    <?php
    session_start();
      define('DB_HOST', 'localhost');
      define('DB_USER', 'mydbusername');
      define('DB_PASSWORD', 'mydbpassword');
      define('DB_DATABASE', 'mydbname');
    
           
    
      $errmsg_arr = array();
      $errflag = false;
      $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
        
      if(!$link)
      {
        die('Failed to connect to server: ' . mysql_error());
      }
    
    
      $db = mysql_select_db(DB_DATABASE);
    
      if(!$db)
      {
        die("Unable to select database");
      }
    
    
      if($errflag)
      {
        $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
    
        echo implode('<br />',$errmsg_arr);
    
      }
    
      else
    
      {
        $qrytable1="SELECT id, channels FROM tvguide";
        $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error());
    
         
        while ($row = mysql_fetch_array($result1))
        {
          echo "</br>";
          echo "<td>".$row['channels']."</td>";
          echo "</br>";
        }
      }
    ?>
    
    
    Code (markup):
    There is a problem, I can't be able to print the output data in html.

    here is the code:

    
    <html>
    <body>
    
    <style type="text/css">
    
    #channel1 {
    font-family:Arial;
    font-size:29px;
    font-style:normal;
    font-weight:bold;
    color:f5fdfd;
    text-decoration:none;
    text-transform:none;
    position:absolute;
    visibility:hidden;
    overflow:hidden;
    left:194px; top:345px; width:176px; height:50px;
    z-index:0;
    }
    
    #channel2 {
    font-family:Arial;
    font-size:29px;
    font-style:normal;
    font-weight:bold;
    color:f5fdfd;
    text-decoration:none;
    text-transform:none;
    position:absolute;
    visibility:hidden;
    overflow:hidden;
    left:194px; top:345px; width:176px; height:50px;
    z-index:0;
    }
    
    #channel3 {
    font-family:Arial;
    font-size:29px;
    font-style:normal;
    font-weight:bold;
    color:f5fdfd;
    text-decoration:none;
    text-transform:none;
    position:absolute;
    visibility:hidden;
    overflow:hidden;
    left:194px; top:345px; width:176px; height:50px;
    z-index:0;
    }
    
    #channel4 {
    font-family:Arial;
    font-size:29px;
    font-style:normal;
    font-weight:bold;
    color:f5fdfd;
    text-decoration:none;
    text-transform:none;
    position:absolute;
    visibility:hidden;
    overflow:hidden;
    left:194px; top:345px; width:176px; height:50px;
    z-index:0;
    }
    
    #channel5 {
    font-family:Arial;
    font-size:29px;
    font-style:normal;
    font-weight:bold;
    color:f5fdfd;
    text-decoration:none;
    text-transform:none;
    position:absolute;
    visibility:hidden;
    overflow:hidden;
    left:194px; top:345px; width:176px; height:50px;
    z-index:0;
    }
    
    #channel6 {
    font-family:Arial;
    font-size:29px;
    font-style:normal;
    font-weight:bold;
    color:f5fdfd;
    text-decoration:none;
    text-transform:none;
    position:absolute;
    visibility:hidden;
    overflow:hidden;
    left:194px; top:345px; width:176px; height:50px;
    z-index:0;
    }
    
    <span id="channel1"></span>
    
    <span id="channel2"></span>
    
    <span id="channel3"></span>
    
    <span id="channel4"></span>
    
    <span id="channel5"></span>
    
    <span id="channel6"></span>
    
    function ajaxpage(str)
    {
    if (str == "")
    {
    document.getElementById("channel1").innerHTML = "";
    document.getElementById("channel2").innerHTML = "";
    document.getElementById("channel3").innerHTML = "";
    document.getElementById("channel4").innerHTML = "";
    document.getElementById("channel5").innerHTML = "";
    document.getElementById("channel6").innerHTML = "";
    return;
    }
    
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("channel1").innerHTML=xmlhttp.responseText;
    }
    }
    xmlhttp.open("GET","tvguide.php?q="+str,true);
    xmlhttp.send();
    }
    </script>
    <form action="tvguide.php" method="post">
    </body>
    </html>
    
    Code (markup):
    do you know how i can print the output data to html from php using with ajax?

    any advice would be much appriecated.

    thanks in advance
     
    mark103, Apr 5, 2013 IP
  2. YoGem

    YoGem Active Member

    Messages:
    676
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    90
    #2
    Here is what you can do with Ajax:

    <div id="content">
        <p>Please Wait</p>
    </div>
    <script>
        $('#content').load('yourphpfile.php');
    </script>
    HTML:
    This simple script will replace your Please Wait, with the content of the content you want to show on screen.
     
    YoGem, Apr 5, 2013 IP
  3. kutchbhi

    kutchbhi Active Member

    Messages:
    130
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    70
    #3
    btw yogem is using jquery. So you will need to download that to make the above work.
     
    kutchbhi, Apr 7, 2013 IP