cfircoo
cfircoo

Reputation: 439

PHP function is not showing the HTML data

I am trying to print data from dataBASE with SQL and PHP. all worked fine the issue is when I am trying to to warp all thing to function it not working and the table is not showing.

with out the function loadClient it work fine.

please help...

$("#loadbtn").click(function(){
    var s = '                       
    <?php
    loadClients()

    function loadClients(){
        $link = mysql_connect($db_host,$db_user,$db_pass);
        if(!$link) die ('Could not connect to database: '.mysql_error());
        mysql_select_db($db_name,$link);
        mysql_query("SET NAMES 'utf8'");

        echo '<table id="clienttable" border="1" cellspacing="0" cellpadding="0" width="100%">';
        echo '<tr>';

        echo '<td width="80px">שם פרטי</td>';
        echo '<td>שם משפחה</td>';
        echo '<td>טלפון</td>';
        echo '<td>אימייל</td>';
        echo '<td>עיר</td>';
        echo '<td width="120px">שעת רישום</td>';
        echo '<td>מספרי תמונות</td>';
        echo '<td>שמור</td>';
        echo '</tr>';

        $loadQuery="SELECT * FROM `claients` WHERE `eventreg_pictures` is null";
        $result=mysql_query($loadQuery);
        while($row= mysql_fetch_array($result)){
            $client= $row;
            $clients[]=$client;

            echo '<tr>';
            echo '<form id="loadForm" method="post" action="admin.php">'; 

            echo '<td><input type="text" id="lfname" name="lfname" value="'.$client[1].'"/></td>';
            echo '<td><input type="text" id="llname" name="llname" value="'.$client[2].'"/></td>';
            echo '<td><input type="text" id="lphone" name="lphone" value="'.$client[3].'"/></td>';
            echo '<td><input type="text" id="lemail" name="lemail" value="'.$client[4].'"/></td>';
            echo '<td><input type="text" id="lcity" name="lcity" value="'.$client[5].'"/></td>';
            echo '<td>'.$client[7].' ';
            echo '<td><input type="text" id="lphotos" name="lphotos"/></td>';
            echo '<td><input type="submit" id="savebtn" name="savebtn" value-"שמור"/></td>';
            echo '</form>';
            echo '</tr>';

            }
        echo '</table>';
    }
?>';

Upvotes: 2

Views: 278

Answers (1)

Rohan Kumar
Rohan Kumar

Reputation: 40639

You should use $.ajax() like

Javascript

$("#loadbtn").click(function(){
   $.ajax({
     type: "POST",
     url: 'page.php',
     success: function(d){alert(d);},
   });
});

PHP

$link = mysql_connect($db_host,$db_user,$db_pass);
if(!$link) die ('Could not connect to database: '.mysql_error());
mysql_select_db($db_name,$link);
mysql_query("SET NAMES 'utf8'");
echo '<table id="clienttable" border="1" cellspacing="0" cellpadding="0" width="100%">';
 echo '<tr>';

 echo '<td width="80px">שם פרטי</td>';
 echo '<td>שם משפחה</td>';
 echo '<td>טלפון</td>';
 echo '<td>אימייל</td>';
 echo '<td>עיר</td>';
 echo '<td width="120px">שעת רישום</td>';
 echo '<td>מספרי תמונות</td>';
 echo '<td>שמור</td>';
 echo '</tr>';
 $loadQuery="SELECT * FROM `claients` WHERE `eventreg_pictures` is null";
 $result=mysql_query($loadQuery);
 while($row= mysql_fetch_array($result)){
    $client= $row;
    $clients[]=$client;
    echo '<tr>';
    echo '<form id="loadForm" method="post" action="admin.php">'; 

    echo '<td><input type="text" id="lfname" name="lfname" value="'.$client[1].'"/></td>';
    echo '<td><input type="text" id="llname" name="llname" value="'.$client[2].'"/></td>';
    echo '<td><input type="text" id="lphone" name="lphone" value="'.$client[3].'"/></td>';
    echo '<td><input type="text" id="lemail" name="lemail" value="'.$client[4].'"/></td>';
    echo '<td><input type="text" id="lcity" name="lcity" value="'.$client[5].'"/></td>';
    echo '<td>'.$client[7].' ';
    echo '<td><input type="text" id="lphotos" name="lphotos"/></td>';
    echo '<td><input type="submit" id="savebtn" name="savebtn" value-"שמור"/></td>';
    echo '</form>';
    echo '</tr>';

}
echo '</table>';
}

Upvotes: 1

Related Questions