Support Forum Softcomplex logo
About Us  | Services  | Download  | Order  | Support  | |
| Search | Today's Posts | Stats | Board Rules | Not logged in [ Login | Register ]
go to bottom
Last active: Never

Printable Version | Subscribe | Add to Favourites   Post new thread
Author: Subject: A PHP Function To Fill Content Array From MySQL Result Resource
Justin
Junior Member

Posts: 6
Registered: 10/2/2006
Location: San Diego
Member Is Offline
posted on 10/10/2006 at 03:40 PM Reply With Quote
A PHP Function To Fill Content Array From MySQL Result Resource


Here is a PHP function I wrote to automatically fill the content array from a php MySQL result resource. I know this code could be cleaner but it works, but if you can figure out a way to clean it up feel free to post it.

Code:

function fill_js_table_content_from_mysql($result_obj)
{
echo '<script type="text/javascript">var TABLE_CONTENT = [';

$i = 1;

while($row = mysql_fetch_array($result_obj))
{
$j = 0;

echo '[';
while($j < mysql_num_fields($result_obj))
{
if(is_numeric($row[$j]))
{
echo isnull($row[$j]);
}
else
{
echo '"' . isnull($row[$j]) . '"';
}

if(($j + 1) == mysql_num_fields($result_obj)) { break; }

echo ',';
$j++;
}

if($i == mysql_num_rows($result_obj)) { echo ']'; }
else { echo '],'; }
$i++;
}

echo '];</script>';
}


Your going to need this little function as well:

Code:

function isnull($input) {
if(empty($input))
{
return ('---');
}
else
{
return ($input);
}
}
View User's Profile View All Posts By User U2U Member
Justin
Junior Member

Posts: 6
Registered: 10/2/2006
Location: San Diego
Member Is Offline
posted on 10/10/2006 at 03:42 PM Reply With Quote

Here is an example usage:

<?php
$sql = "SELECT ins.date, ins.time FROM ins, transactions WHERE transactions.employee_id = " . mysql_smart_quote($_SESSION['session_id']) . " ORDER BY ins.date";
$result = mysql_query($sql) or die(fatal_error_alert(mysql_error(), $sql));
fill_js_table_content_from_mysql($result);
?>
<script type="text/javascript">
new TTable(TABLE_CAPT, TABLE_CONTENT, TABLE_LOOK);
</script>
View User's Profile View All Posts By User U2U Member
Post new thread

Related Links:
Product Page
Product Demonstrations Live Demos
Simple
XP-styled
3D designed
Product Documentation Documentation
Documenation Page
Change Log
Support Forum Technical Support
Support Forum
Customer Care System
Order Now ORDER NOW!
Add to Cart
View Cart

Go To Top


Powered by XMB 1.9.1 Nexus
Developed By Aventure Media & The XMB Group © 2002-2004