Click here to Skip to main content
11,704,315 members (51,461 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript PHP
Hi i have the following coding.

<input type="button" id="sample" value="click" onclick="sam_click()"/>

<script type="text/javascript">
function sam_click(clicked)
{
	var x="<?php ex(); ?>";
	alert(x);
	return false;
}
</script>

<?php
function ex()
{
$con=mysql_connect("localhost","root","");
mysql_select_db("my_db");
$res=mysql_query("call PrcEmployeeDisplay(777)");
$num=mysql_num_rows($res);
echo($num);
}
?>

Here when button is clicked it will call javascript function and that function will call php function. This works fine. i. e. Database is connected and retrieved the result and dispalying the number of rows in alert box. But i need to display the selected results in html table how to do this? pls help me.
Posted 15-Nov-12 17:20pm
Comments
Sergey Alexandrovich Kryukov at 16-Nov-12 0:06am
   
Whatever you do, you are not calling PHP function, which can exist only on server side, from Javascript code executing on client side...
--SA
Red Chocolate at 16-Nov-12 0:46am
   
Thats ok but how to display my results in table?
skydger at 16-Nov-12 1:46am
   
You should create html template to fill it while fetching query data. Please refer php documentation about it. http://php.net/manual/en/book.mssql.php
Sergey Alexandrovich Kryukov at 16-Nov-12 11:42am
   
I don't see how it can be OK. Your question is about the call which cannot exist, even if the functionality may resemble it, as with Ajax (which is actually a key, in case of JavaScript).
--SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Instead of this statement

var x="<?php ex(); ??>";

use a Jquery $.get to make a AJAX call to the server to do the operation and in the callback function to the get, use the statements
alert(x);
    return false;
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 785
1 OriginalGriff 520
2 Maciej Los 395
3 Andy Lanng 284
4 CPallini 275
0 OriginalGriff 8,784
1 Sergey Alexandrovich Kryukov 7,843
2 CPallini 5,107
3 Maciej Los 4,726
4 Mika Wendelius 3,606


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 28 Jan 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100