tags:

views:

47

answers:

3

Ok, So I have a external php script that get data from a DB and displays it in a table. I want to run it in a specific div in my html so the data gets echoed out in the right place?

Any ideas how to do that?

Html div

<div id="statsContent">

<?php include('updatestats.php'); ?>

</div>

Heres the PHP code.

<?php

//Start session
session_start();

//Make sure user is logged in
require_once('auth.php');

//Include database connection details
require_once('config.php');

//Connect to DB
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}

//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}

//Create Querys
$query = "SELECT * FROM stats WHERE member_id='" . $_SESSION['SESS_MEMBER_ID'] . "' "; 
$result = mysql_query($query);

//Gather the whole row into an array
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
{
    $money = $row['money'];
    $bank_money = $row['bank_money'];
    $ap = $row['ap'];
    $exp = $row['exp']; 
} 

//Now create a table to display the data to the user
echo "<table> 
<tr>
    <td>Money $$money</td>
    <td>Action Points $ap</td>
    <td>Experience $exp</td>
</tr>";

?>
+2  A: 
<div><?php *whatever you want to do inside the div*?></div>
stillstanding
+1  A: 

just include it inside your div by using:

<?php include('filename.php'); ?>
aadravid
The grey box just dissapears and none of the content is display.
can you share the code you have?
aadravid
Ill add the php page in my OP.
oh wow. i didnt close the table tag and it f-ed everything else up.problem solved.
+3  A: 

you can include PHP script in any tag by calling include("path_to/myscript.php") or require("path_to/myscript.php")

  <div>
<?php include("path_to/myscript.php"); ?>
</div>
Shota Bakuradze
For some reason I can't edit this for you, but for clarifcation, "or" is not part of the code above. It is either include("path_to/myscript.php") or require("path_to/myscript.php") but not both.
Brad