Ajax adding data to MySQL database
What i am trying to do is add data to my database using AJAX. I have PHP
code that pulls the columns and the rows from the database and lists them
in a table dynamically. That way i don't have to many or less rows and
columns. (I listed the code below.)
I have done research into what i am looking to do, i have gone to
w3schools.com went thought their tutorials for ajax which was very
informational. I have also gone to many other websites and done a lot of
google searching but i cannot find any help on what i am trying to do.
My issue is i cannot find anything, anywhere that has a example or
tutorial to add data to the table cells in a dynamic table.my ultimate
goal is, i want users to be able to click on the cells and a small window
will pop up with different selections where they choose a bullet and it
will enter a number value into the cell. All the examples i have found
require knowing the column name. Any help, Or if you can point me to
another post that will help i would greatly appreciate it.
<?php
header("Refresh: 30;");
session_start();
include("connect.php");
$tbvbr= $_SESSION['gamecode'];
$global_dbh = mysql_connect($hostname, $username, $password);
mysql_select_db($db, $global_dbh)
or die("Could not select database");
function display_db_query($query_string, $connection, $header_bool,
$table_params) {
// perform the database query
$result_id = mysql_query($query_string, $connection)
or die("display_db_query:" . mysql_error());
// find out the number of columns in result
$column_count = mysql_num_fields($result_id)
or die("display_db_query:" . mysql_error());
// Here the table attributes from the $table_params variable are added
print("<TABLE $table_params >\n");
// optionally print a bold header at top of table
if($header_bool) {
print("<TR>");
for($column_num = 0; $column_num < $column_count; $column_num++) {
$field_name = mysql_field_name($result_id, $column_num);
print("<TH>$field_name</TH>");
}
print("</TR>\n");
}
// print the body of the table
while($row = mysql_fetch_row($result_id)) {
print("<TR ALIGN=LEFT VALIGN=TOP>");
for($column_num = 0; $column_num < $column_count; $column_num++) {
print("<TD>$row[$column_num]</TD>\n");
}
print("</TR>\n");
}
print("</TABLE>\n");
}
function display_db_table($tablename, $connection, $header_bool,
$table_params) {
$query_string = "SELECT * FROM $tablename";
display_db_query($query_string, $connection,
$header_bool, $table_params);
}
?>
<HTML><HEAD><TITLE>Displaying a MySQL table</TITLE></HEAD>
<BODY>
<TABLE><TR><TD>
<?php
//table name variable
$table = $tbvbr;
//field name test
$_SESSION['fieldnames'] = $result_id;
//end of test
display_db_table($table, $global_dbh,
TRUE, "border='2'");
?>
</TD></TR></TABLE></BODY></HTML>
No comments:
Post a Comment