Php render 唔到TABLE

ordering.php
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. </head>
  5. <body>

  6. <script src="jquery-1.7_2.js"></script>

  7. <script>
  8. $(document).ready(function() {
  9.      openDatabase();     
  10.          queryData();
  11. });
  12. </script>


  13. <?php

  14. session_start();

  15. echo 'Welcome to ordering system<br />';
  16. echo $_SESSION['favcolor']; // green
  17. echo $_SESSION['animal'];   // cat
  18. $_SESSION['time'] = time();
  19. echo date('Y-m-d H:i:s', $_SESSION['time']);


  20. ?>
  21. </br>
  22. <form action="main.php" method="POST">
  23. <input type="Text" Value="Username" NAME="username">
  24. <input type="submit" />
  25. </form>



  26. <?php
  27. function openDatabase()
  28. {
  29.         $dbhost = '192.168.0.105:3306';
  30.         $dbuser = 'admin';
  31.         $dbpass = 'password';

  32.         $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die;

  33.         $dbname = 'edica';
  34.         mysql_select_db($dbname);
  35. }


  36. function queryData()
  37. {
  38.    $query = sprintf ("SELECT * from in_record");
  39.    $result = mysql_query($query);

  40.    if (!$result)
  41.         die('Database error');               
  42.      

  43.         //var Pin;
  44.         $Pin[] = array();
  45.         $Time[] = array();
  46.         $Ref_No[] = array();
  47.        
  48.        
  49.          
  50.         while ($row = mysql_fetch_assoc($result))
  51.         {
  52.             
  53.                 $Pin[] = $row['PIN_NO'];
  54.                 $Time[] = $row['In_Time'];
  55.                 $Ref_No[] = $row['Ref_No'];
  56.         }
  57.                  
  58.      
  59.          $_SESSION('Pin1') = $Pin;
  60.          $_SESSION('Time1') = $Time;
  61.          $_SESSION('Ref_No1') = $Ref_No;
  62.    
  63. }

  64. ?>

  65.   
  66. </body>
  67. </html>
複製代碼
main.php
  1. <html>
  2. <body>
  3. <?php

  4. $User = $_POST['username'];
  5. echo 'hello ';
  6. echo $User;

  7. ?>
  8. <?php
  9.    $Pin[] = $_SESSION['Pin1'];
  10.    $Time[] = $_SESSION['Time1'];
  11.    $Ref_No[] = $_SESSION['Ref_No1'];
  12.    $s = $Pin.size();
  13.    echo ('<table>');
  14.    echo ('<tr><th>Pin No</th>');
  15.    echo ('    <th>In Time</th>');
  16.    echo ('    <th>Ref No</th></tr>');
  17.    for ($i = 0; $i <= $s; $i++)
  18.    {
  19.      echo ('<tr><td>' . $Pin[$i] . '</td>');
  20.          echo ('    <td>' . $Time[$i] . '</td>');
  21.          echo ('    <td>' . $Ref_No[$i] . '</td></tr>');
  22.          
  23.          
  24.    }
  25.    echo ('</table>');
  26. ?>   

  27. </body>
  28. </html>
複製代碼
請大大多多指教.
THANKS

ordering.phpmain.php請大大多多指教.
THANKS
luckiejacky 發表於 2012-5-24 20:52

你係js 度就咁call php function? =.=

TOP

請問應該點CALL呢?
THANK YOU SO MUCH

TOP

Sorry Client side script Vs Server Side Script,
So it doesn't work. Do I use AJAX instead?

TOP

Sorry Client side script Vs Server Side Script,
So it doesn't work. Do I use AJAX instead?
luckiejacky 發表於 2012-5-24 21:14


根本唔關事,
你client side(js) 點call到server side(php)既function姐
反正都係onready function既話, 你ordering.php直接最後
<?php
     openDatabase();     
         queryData();
?>

TOP

Sorry Client side script Vs Server Side Script,
So it doesn't work. Do I use AJAX instead?
luckiejacky 發表於 2012-5-24 21:14

學野一步步黎.. ajax唔係咁用..
你遲d 掂到json 時,你大把機會學..

你整走jquery佢..
call返兩個function先..睇下仲有咩error..再問我地

TOP

樓主concept有d亂bor..

同意搞清concept先再玩ajax

TOP

本帖最後由 luckiejacky 於 2012-5-28 17:19 編輯

Dear men, women, boys and girls, :),
<?php


function openDatabase()
{
        $dbhost = "192.168.0.105:3306";
        $dbuser = "admin";
        $dbpass = "password";

        $conn = mysql_connect($dbhost, $dbuser, $dbpass);
        if ( ! $conn ) {
                die ( "Couldn't connect to MySQL: " . mysql_error() );
    }
       
   


       
        return;
}


function queryData()
{
    $dbname = 'edica';
        mysql_select_db($dbname, $conn);
       
        $query = sprintf("select * from in_record");
    $result = mysql_query($query);

   if (!$result)
        die('Database error');               
     

        //var Pin;
        $Pin[] = array();
        $Time[] = array();
        $Ref_No[] = array();
       
       
         
        while ($row = mysql_fetch_assoc($result))
        {
            
                $Pin[] = $row['PIN_NO'];
                $Time[] = $row['In_Time'];
                $Ref_No[] = $row['Ref_No'];
        }
                 
     
/*         $_SESSION['Pin1'] = $Pin;
         $_SESSION['Time1'] = $Time;
         $_SESSION['Ref_No1'] = $Ref_No;*/

I have 2 questions in this source code
1) the result i get is
Welcome to ordering system
2012-05-28 06:33:49Database error

2) When I add $_SESSION['Pin1'] = $Pin1
The page was unable to pass the web server

What is the problem?
Thanks
Jack

TOP

Push....Thanks

TOP

$query = sprintf("select * from in_record");
replace it by
$query = "select * from in_record";

TOP