get data from HTML table dynamically generated - javascript

i'm new to Html , php , javascript. I'm using a table generated from mysql query:
<?php
session_start ();
require_once ('auth.php');
require_once ('connection.php');
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table id="example">
<?php
$result = $mysqli->query ( "Select name ,date from table" );
while ( $row = $result->fetch_assoc () ) {
echo "<tr>".
"<td>" . $row ['name'] . "</td>
<td>" . $row ['date'] . "</td>
</tr>";
}
$result->free ();
?>
</table>
</body>
</html>
Now i want to select a row , redirect to another page transferring data from the selected row to the new page. Thanks for your help

Try this:
<?php
session_start ();
require_once ('auth.php');
require_once ('connection.php');
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table id="example">
<?php
$result = $mysqli->query ( "Select name ,date from table" );
while ( $row = $result->fetch_assoc () ) {
$url = "second.php?name={$row ['name']}&date={$row ['date']}";
echo "<tr>".
"<td>" . $row ['name'] . "</td>
<td>" . $row ['date'] . "</td>
</tr>";
}
$result->free ();
?>
</table>
</body>
</html>
Where second.php is the action page where you can get the passed parameters name and date using $_GET['name'], $_GET['date'] respectively.

I would additionally select the id (if the table has any) or any other unique key. Then in the output you can add a link to something like display.php?id=X with X being the unique key from this row.
Then, in the display.php you can just use the query "SELECT name, date FROM table WHERE id = " . intval($_GET['id']) . " to select the single row and display it just like you did on the other page.

Related

Automatically show data based on dropdown selection

Basically, I have a table with two column: 'Kode Barang' (Item ID) and 'Nama Barang' (Name of Item). The first column is a dropdown option which it's data get populated dynamically from another table. If a user select an Item ID, then the second column will automatically show the name of the item.
Let's say that I've only two row as this code below:
<HTML>
<table id="theTable" border="1">
<thead>
<tr>
<th> Kode Barang </th>
<th> Nama Barang </th>
<tr>
</thead>
<tbody>
<tr>
<td type="text" name="kode_barang" id="kode_barang"/readonly>
<?php
mysql_connect("localhost","root","");
mysql_select_db("skripsi_1");
$result = mysql_query("select * from input_data_barang");
$jsArray = "var kode_barang = new Array();\n";
echo '<select name="kode_barang" onchange="changeValue(this.value)">';
echo '<option></option>';
while ($row = mysql_fetch_array($result)) {
echo '<option value="' . $row['kode_barang'] . '">' . $row['kode_barang'] . '</option>';
$jsArray .= "kode_barang['" . $row['kode_barang'] . "'] = {name:'" . addslashes($row['nama_barang']) . "',desc:'".addslashes($row['nama_barang'])."'};\n";
}
echo '</select>';
?>
</td>
<td><input type="text" name="nama_barang" id="nama_barang"/readonly>
<script type="text/javascript">
<?php echo $jsArray; ?>
function changeValue(id){
document.getElementById('kode_barang').value = kode_barang[id].name;
document.getElementById('nama_barang').value = kode_barang[id].desc;
};
</script>
</td>
</tr>
<tr>
<td type="text" name="kode_barang" id="kode_barang"/readonly>
<?php
mysql_connect("localhost","root","");
mysql_select_db("skripsi_1");
$result = mysql_query("select * from input_data_barang");
$jsArray = "var kode_barang = new Array();\n";
echo '<select name="kode_barang" onchange="changeValue(this.value)">';
echo '<option></option>';
while ($row = mysql_fetch_array($result)) {
echo '<option value="' . $row['kode_barang'] . '">' . $row['kode_barang'] . '</option>';
$jsArray .= "kode_barang['" . $row['kode_barang'] . "'] = {name:'" . addslashes($row['nama_barang']) . "',desc:'".addslashes($row['nama_barang'])."'};\n";
}
echo '</select>';
?>
</td>
<td><input type="text" name="nama_barang" id="nama_barang"/readonly>
<script type="text/javascript">
<?php echo $jsArray; ?>
function changeValue(id){
document.getElementById('kode_barang').value = kode_barang[id].name;
document.getElementById('nama_barang').value = kode_barang[id].desc;
};
</script>
</td>
</tr>
</table>
</HTML>
The first row works perfectly. The problem is in the second row. If I select an option from the dropdown, then name of the item doesn't appear in the second row, but appear in the first row instead. Would anybody please show me how to fix this? Thank you.
You are appending your values using:
document.getElementById('kode_barang').value = kode_barang[id].name;
document.getElementById('nama_barang').value = kode_barang[id].desc;
The problem is, that there is an Element with the ID kode_barang/nama_barang in BOTH rows. So you have 2 Elements for the ID's. Javascript appereantly just decides only to take the first one. Just rename them in the second row to "kode_barang2" and "nama_barang2" and when setting the values change the names too:
document.getElementById('kode_barang2').value = kode_barang[id].name;
document.getElementById('nama_barang2').value = kode_barang[id].desc;

Get ID automatically in input-field after <SELECT> without button click

I have an SQL-database with many tables. Now I would like to create an input-form to be able to get data into the db without writing the entire sql-code every time. And this should work as follows:
All table names are listed in a drop-down menu. After having selected a table name, a new table with 4 columns is created automatically:
The first column of this table simply contains an increasing number.
The second column contains the field-names of the selected table.
In the third column there are empty input fields to enter the values for the database. Only in the third line (=product name) there is a drop-down menu with all product names from the main-table of the db.
The fourth column contains the data type (e.g. int or varchar)
All tables in the database have the same structure in the first 3 columns: the first column contains the table-id, the second column the foreign-key (=master_id) and the third column the product_name.
Up to this point, the script works well with the following 2 php-files (javasql.php and getuser.php):
javasql.php:
enter code here
<!DOCTYPE html>
<html>
<head>
<script>
function showUser(str) {
if (str=="") {
document.getElementById("txtHint").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 (this.readyState==4 && this.status==200) {
document.getElementById("txtHint").innerHTML=this.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="users" onchange="showUser(this.value)">
<option value="" class="optdrugs">please select</option>
<?php
include("files/zugriff.inc.php"); // database Access
$sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE
TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = 'product'";
$result = mysqli_query($db, $sql);
while ($row = mysqli_fetch_assoc($result)) {
echo '<option class="optdrugs" value="'. $row['TABLE_NAME'] . '">' .
$row['TABLE_NAME']. '</option>';
echo '<br>';
}
?>
</select>
</form>
<br>
<div id="txtHint"><b>Bitte Tabelle auswählen:</b>
<br>
<?php
if (isset($_POST["submit"])) {
$sent = $_POST['sent'];
$q = $_POST['tablename'];
$column_passed = unserialize($_POST['column']); // content of array
$column is passed from getuser.php
foreach ($_POST["insertvalue"] as $key => $value) {
echo $value . "<br>";
$werte[] = "'$value'";
}
$sql="INSERT INTO $q ($column_passed) VALUES (" .
implode(", ", $werte) . ")"; // data entry
mysqli_query($db, $sql);
if (mysqli_affected_rows($db) > 0) {
echo "<h3 style='color:blue'>successful</h3>";
} else {
echo "<h3 style='color:red'>not
successful</h3>";
}
}
?>
</div>
</body>
</html>
enter code here
getuser.php:
<!DOCTYPE html>
<html>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
padding: 5px;
}
th {text-align: left;}
</style>
</head>
<body>
<form id="formdatabase" name="formdatabase" action="javasql.php"
method="post">
<input type="hidden" name="sent" value="yes">
<?php
$q = strval($_GET['q']);
$con = mysqli_connect('localhost','root','','product');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM $q";
$result = mysqli_query($con,$sql);
$numcols = mysqli_num_fields($result); // gets number of columns in result table
$field = mysqli_fetch_fields($result); // gets the column names from the result table
$data_type_array = array(
1=>'tinyint',
2=>'smallint',
3=>'int',
4=>'float',
5=>'double',
7=>'timestamp',
8=>'bigint',
9=>'mediumint',
10=>'date',
11=>'time',
12=>'datetime',
13=>'year',
16=>'bit',
252=>'text',
253=>'varchar',
254=>'char',
246=>'decimal'
);
$data_type_array = array_flip($data_type_array);
echo "<table>";
echo "<tr>";
echo "<th>" . 'Nr' . "</th><th>" . 'Column names' . "</th>
<th>" . 'Values for db-entry' . "</th><th>" . 'Type' . "</th>";
echo "</tr>";
echo "<tr>";
$nr = 1;
for($x=0;$x<$numcols;$x++):?>
<td><?= $nr; ?></td>
<td><?= $field[$x]->name; ?></td>
<?= $column[] = $field[$x]->name; ?>
<td>
<?php
if ($field[$x]->name == 'Name') { // if-Beginn
?>
<select name="insertvalue[<?= $x; ?>]" id="insertvalue<?=
$x; ?>" size="1" onchange = "javascript:getSelectedRow()">
<?php
include("files/zugriff.inc.php");
$sql = "SELECT * FROM product_main ORDER BY Name";
$result = mysqli_query($db, $sql);
while ($row = mysqli_fetch_assoc($result)) {
echo '<option class="optdrugs" value='. $row['Name'] . '>' .
$row['Name'] . '</option>';
echo '<br>';
}
?>
</select>
<?php
$name_option = "";
} else {
$name_option = "<input type='text' id='insertvalue" . $x . "'
name='insertvalue[" . $x . "]' size='50'>";
echo $name_option;
}
?>
</td>
<?php
$key = array_search($field[$x]->type, $data_type_array);
if($key !== false){
echo "<td>" . $key . "</td>";
}else{
echo "<td>" . $field[$x]->type . "</td>";
}
?>
<td><?= $field[$x]->type; ?></td>
<?= $nr = $nr + 1; ?>
</tr>
<?php endfor;
echo "</table>";
mysqli_close($con);
?>
<input type="hidden" name="tablename" value="<?= $q; ?>">
<input type="hidden" name="column" value="<?php echo htmlentities
(serialize($column)); ?>">
<input type="submit" value="Enter values" name="submit">
</form>
</body>
</html>
Since I need the master_id (= foreign key) in addition to the product-name for database entry, I would like to extend my script, so that the respective master_id is automatically sent to the input field in line 2, when a product-name is selected in line 3 ... without clicking a button. I tried to do this with javascript but it didn´t work. As far as I know, the solution would be to use AJAX but unfortunately, I am not very used to AJAX.
I would be more than happy, if someone could help me to solve this problem!

How to post the information using javascript for a preview table

Hey I need to know how to post the information to another php page using javascript to provide a preview table.
Here's my HTML that has a onchange tag that sends the productID to the function.
<form action="Home.php" method="Post">
<div>
<p>
<span class="text">Please Select a product:</span>
<select id="Select_Product" name="Select_Product" onchange="productInfo(this.value)" class="select">
<?php
//setting the select statement and running it
$search = "SELECT * FROM Library.Products order by Name";
$return = mysql_query($search);
//echo "<select id=Select_Product name=Select_Product onchange=productInfo(this.value) class=select>";
while ($row = mysql_fetch_array($return)) {
echo "<option value='" . $row['ProductID'] . "' selected='selected'>".$row['Name'] . "</option>";
}
?>
</select>
</p>
<table>
<tr>
<td>
<input name="action" type="submit"class="button" id="button_Add" value="Add"/>
</td>
<td>
<input name="action" type="submit" class="button" id="button_Remove" value="Remove"/>
</td>
<td>
<input name="action" type="submit" class="button" id="button_empty" value="Empty"/>
</td>
</tr>
</table>
</div>
From there I want it to send it to catalogue.php.
<script>
function productInfo(key) {
//Send key to catalogue.php
}
</script>
If I can get the other page to get that variable I can run a MYSQL command to get the information. Here is what catalogue.php looks like at the moment.
<?php
$sql = "SELECT Name, Price FROM Library.Products WHERE ProductID = " . $product_id;
echo "<table border=\"1\" padding=\"3\" width=\"650px\"><tr><th>Name</th><th>Description</th><th>Price</th><th width=\"80px\">Image</th></tr>";
echo "<tr>";
echo "<td>" .$product_id . "</td>";
echo "<td> Hi</td>";
echo "<td></td>";
echo "<td align=\"center\"><img alt=\"\" src=\"productImages/".$product_id.".jpg\ width=\"120\" height=\"120\"/></td>";
echo "</tr>";
echo "</table><br>";
document.
?>
So in a sense I want to turn the key in productInfo(key) to be assigned to the variable $product_id in catalogue.php. Thanks for helping.
You can add an invisible form :
<script>
function productInfo(key) {
//Send key to catalogue.php
document.getElementById( "key" ).value = key;
document.getElementById( "frm" ).submit(); // SUBMIT FORM.
}
</script>
<form action="catalogue.php" method="post" id="frm"
style="display:none" target="_blank">
<input type="text" id="key" name="key"/>
</form>
catalogue.php needs one little change :
<?php
$product_id = $_POST[ "key" ]; //<================== VALUE FROM THE INVISIBLE FORM.
$sql = "SELECT Name, Price FROM Library.Products WHERE ProductID = " . $product_id;
echo "<table border=\"1\" padding=\"3\" width=\"650px\"><tr><th>Name</th><th>Description</th><th>Price</th><th width=\"80px\">Image</th></tr>";
echo "<tr>";
echo "<td>" .$product_id . "</td>";
echo "<td> Hi</td>";
echo "<td></td>";
echo "<td align=\"center\"><img alt=\"\" src=\"productImages/".$product_id.".jpg\ width=\"120\" height=\"120\"/></td>";
echo "</tr>";
echo "</table><br>";
document.
?>
Or you can use Ajax :
html file
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type = "text/javascript">
function myAjax ( key ) {
$.ajax( { type : 'POST',
data : { 'param' : key },
url : 'catalogue.php',
success: function ( data ) {
document.getElementById( "my_div" ).innerHTML = data;
},
error: function ( data ) {
alert( "error" );
}
});
}
function productInfo( key ) {
//Send key to catalogue.php
myAjax( key );
}
</script>
</head>
<body>
<button onclick="productInfo('123')">Click here to get the data</button>
<div id="my_div">
- data will show here -
</div>
</body>
</html>
catalogue.php
<?php
$key = $_POST[ "param" ];
echo "<table border='1'>" .
" <tr>" .
" <td>$key</td>" .
" <td>ABC</td>" .
" </tr>" .
"</table>";
?>

htmlspecialchars_decode causes width issues

I have been messing about creating stuff in PHP so decided to create a site... However, when I am pulling things from my DB it is resizing the text and pushing things off of the page :/
I have tested with plain text and my site is displaying correctly:
http://gentetcreations.co.uk/blog-2.php
However, with HTML text it displays in a weird way and I can't seem to get it fixed:
http://gentetcreations.co.uk/blog-1.php
JSFidle here!
<!DOCTYPE HTML>
<html>
<head>
<title>GentetCreations</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="style/style.css" />
</head>
<body>
<div id="main">
<?php
include("inc/pageHead.php");
?>
<div id="site_content">
<?php
include("inc/side.php");
?>
<div id="content">
<?php
include("inc/dbconnection.php");
$id = $_GET['id'];
$id = trim($id);
$result = mysqli_query($conn, "SELECT * FROM blog WHERE authorised = 1 AND blog_id = '" . $id . "'");
if(!$result) {
die("Database query failed: " . mysqli_error($conn));
} else {
$rows = mysqli_num_rows($result);
if ($rows > 0) {
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$tags = "";
$result2 = mysqli_query($conn, "SELECT * FROM tags WHERE blog_id = '" . $row['blog_id'] . "'");
if(!$result2) {
die("A Database query failed: " . mysqli_error($conn));
} else {
while ($row2 = mysqli_fetch_array($result2, MYSQLI_ASSOC)) {
$rawTag = $row2['tag'];
$tag = str_replace(" ", "", $rawTag);
$tags .= "<a href='tag-" . $tag . ".php'>" . $tag . "</a> ";
}
}
echo "
<span class='mainContentWidth'>
<table>
<tr>
<th>
<a href='blog-" . $row['blog_id'] . ".php'>
<h2>" . $row['title'] . "</h2>
</a>
</th>
</tr>
<tr>
<td>
<p>" . date("d/m/Y", strtotime($row['createdDate'])) . "</p><br />
<span>" . $row['content'] . "</span>
<br />
<br />
<span><small>Tags: " . $tags . "</small></span>
</td>
</tr>
</table>
</span>";
} //$row = mysqli_fetch_array($result, MYSQLi_ASSOC)
} else { //$rows > 0
echo "<br /><h1>An error occurred.</h1><br /><h2>The blog you were looking for could not be found.</h2>";
}
}
?>
</div>
</div>
<?php
include("inc/footer.php");
?>
</div>
</body>
</html>
I am new to doing web based coding so I am really confused here and not too sure what is going on.
If anyone could help me here or push me in the right direction to display everything correctly, I would be very happy!
You have block level elements inside a span tag. You should avoid doing that.
For current issue you can add this CSS
table tr td > span {
width: 615px;
}

How to call a PHP function from a HTML button click?

Can someone help me with some javascript that will allow me to call a function when I click on a button?
I know this has been posted before, but every answer I have seen is too vague and I have been at this for 8 hours now :(
Please bear in mind I am a javascript beginner.
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php include 'connect.php'; ?>
<table border cellpadding=5>
<div>
<tr>
<th>Report</th>
<th></th>
</tr>
<tr>
<td>Students with highest scores</td>
<td>
<button type= button>Generate report</button>
</td>
</div>
</table>
<?php
function highestScore()
{
$data = mysql_query("SELECT t.Test_name, s.Student_firstname, s.Student_surname, sc.Result
FROM Tests t
JOIN Scores sc ON t.id_Tests = sc.Tests_id_Tests
JOIN Students s ON sc.Students_id_Students = s.id_Students
WHERE t.id_Tests = 1
ORDER BY sc.Result DESC");
if(!$data)
{
die("Invalid Query: " . mysql_error());
}
Print"<table border cellpadding=5>";
while($info = mysql_fetch_array($data))
{
Print"<tr>";
Print "<th>Test:</th> <td>" . $info['Test_name'] . "</td> ";
Print "<th>First Name:</th> <td>" . $info['Student_firstname'] . "</td> ";
Print "<th>Surname:</th> <td>" . $info['Student_surname'] . "</td> ";
Print "<th>Result:</th> <td>" . $info['Result'] . "</td> ";
}
Print "</table>";
}
?>
</body>
I want to use the "Generate report" button I have made, to execute the "highestScore" function.
The function creates a table of values from a mySQL database.
There will eventually be more buttons which bring up different tables.
Any help is appreciated.
HTML and Javascript run on the browser while PHP runs on the server. You will have to make another server call either by using AJAX or refreshing the page. Here's how to do it with AJAX without refreshing the page. ($.ajax docs)
Create a new PHP page: query.php with the following code:
<?php
$data = mysql_query("SELECT t.Test_name, s.Student_firstname, s.Student_surname, sc.Result
FROM Tests t
JOIN Scores sc ON t.id_Tests = sc.Tests_id_Tests
JOIN Students s ON sc.Students_id_Students = s.id_Students
WHERE t.id_Tests = 1
ORDER BY sc.Result DESC");
if(!$data)
{
die("Invalid Query: " . mysql_error());
}
Print"<table border cellpadding=5>";
while($info = mysql_fetch_array($data))
{
Print"<tr>";
Print "<th>Test:</th> <td>" . $info['Test_name'] . "</td> ";
Print "<th>First Name:</th> <td>" . $info['Student_firstname'] . "</td> ";
Print "<th>Surname:</th> <td>" . $info['Student_surname'] . "</td> ";
Print "<th>Result:</th> <td>" . $info['Result'] . "</td> ";
}
Print "</table>";
?>
Use the button's click event to run an ajax request: (Add the following script to your HTML page)
$(function(){
$('button').click(function(){
$.ajax({
url:'query.php',
success:function(response){ alert(response); }
}); // this will alert the code generated in example.php
});
});
Instead of using button, use a form with a submit button. Send a request by POST, and detect that in PHP using isset($_POST['report']) and then display your report.
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php include 'connect.php'; ?>
<table border cellpadding=5>
<div>
<tr>
<th>Report</th>
<th></th>
</tr>
<tr>
<td>Students with highest scores</td>
<td>
<form method="POST">
<input type="submit" name="report">Generate report</button>
</form>
</td>
</div>
</table>
<?php
function highestScore()
{
$data = mysql_query("SELECT t.Test_name, s.Student_firstname, s.Student_surname, sc.Result
FROM Tests t
JOIN Scores sc ON t.id_Tests = sc.Tests_id_Tests
JOIN Students s ON sc.Students_id_Students = s.id_Students
WHERE t.id_Tests = 1
ORDER BY sc.Result DESC");
if(!$data)
{
die("Invalid Query: " . mysql_error());
}
Print"<table border cellpadding=5>";
while($info = mysql_fetch_array($data))
{
Print"<tr>";
Print "<th>Test:</th> <td>" . $info['Test_name'] . "</td> ";
Print "<th>First Name:</th> <td>" . $info['Student_firstname'] . "</td> ";
Print "<th>Surname:</th> <td>" . $info['Student_surname'] . "</td> ";
Print "<th>Result:</th> <td>" . $info['Result'] . "</td> ";
}
Print "</table>";
}
if (isset($_POST['report'])) {
highestScore();
}
?>
</body>
A raw button doesn't make sense in pure HTML. It does just nothing - except looking like a button.
You may use it in conjunction with JavaScript:
<form action="input_button.htm">
<textarea cols="20" rows="4" name="field1"></textarea>
<input type="button" name="Text 1" value="Add some new Text"
onclick="this.form. field1.value='Some new Text'">
</form>
This button executes a JavaScript through a click on it - and replaces the textarea named field1.
So you want this all on one page so the first thing you need is form html tag wrapped around the button, I have named mine 'submit' and set the action to the page itself <?php echo $_SERVER['PHP_SELF']; ?>. When the button is clicked it will preform your php code
Script
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php include 'connect.php'; ?>
<table border cellpadding=5>
<div>
<tr>
<th>Report</th>
<th></th>
</tr>
<tr>
<td>Students with highest scores</td>
<td>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <!-- Calls for the PHP script on the page-->
<button type= button>Generate report</button>
</form>
</td>
</div>
</table>
<?php
//Script that is called
if(isset($_POST['submit'])){ //The ID of the form we used is 'submit' so when that is clicked it will execute this
function highestScore()
{
$data = mysql_query("SELECT t.Test_name, s.Student_firstname, s.Student_surname, sc.Result
FROM Tests t
JOIN Scores sc ON t.id_Tests = sc.Tests_id_Tests
JOIN Students s ON sc.Students_id_Students = s.id_Students
WHERE t.id_Tests = 1
ORDER BY sc.Result DESC");
if(!$data)
{
die("Invalid Query: " . mysql_error());
}
Print"<table border cellpadding=5>";
while($info = mysql_fetch_array($data))
{
Print"<tr>";
Print "<th>Test:</th> <td>" . $info['Test_name'] . "</td> ";
Print "<th>First Name:</th> <td>" . $info['Student_firstname'] . "</td> ";
Print "<th>Surname:</th> <td>" . $info['Student_surname'] . "</td> ";
Print "<th>Result:</th> <td>" . $info['Result'] . "</td> ";
}
Print "</table>";
}
highestScore(); //executes your function you created
}
?>
</body>
HTML and JavaScript run on the browser while PHP runs on the server. You have to write Ajax or java-script.In java-script you can call the php page and do your stuff in that page.And it would be the better approach.You can pass the variable also.I post a example here.
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
function removeItem(oButton)
{
var hello = "hello";
var world = "world";
window.location.href = "trytest.php?w1=" + hello + "&w2=" + world;//Your page location
}
</script>
</head>
<body>
<form>
<h2>This is the test </h2>
<button type="show" onclick="removeItem(this); return false;">Test</button>
</body>
</html>

Categories

Resources