First off, sorry for the long answering time.
If you have not found a solution(requires PHP5) yet i would suggest to change a couple of things so that it would be easier to sort through the DB.
First if you do not have it yet you will need a
id field with
NOT NULL, INT, AUTO_INCREMENT in your
stone table.
Second of change the
group TEXT null to
group_id INT NOT NULL
Third make a new table called
group.
HTML Code:
CREATE TABLE `group` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`group` VARCHAR( 255 ) NOT NULL
);
Now when the user inputs data into the DB, your script will go in and check the
group table to see what the
id is from there and then input the data into your table, the only difference is that insted of inputting the
g1 and
g2 it inputs the
id from
group into
group_id in the
stone table.
Now use this to read you table data:
PHP Code:
class DataArray
{
public $Data;
public $iCount;
public $jCount;
private $link;
private $db;
private function init(){
$sql = "SELECT * FROM group";
$result = mysql_query($sql,$this->link);
if(!$result = mysql_query($sql,$this->link)){die('Invalid Query: '.mysql_error());}
$this->iCount = mysql_num_rows($result);
for($i=0;$i < $this->iCount; $i++){
$j = 0;
$sql = "SELECT text, data FROM stone WHERE group_id = '$i' ORDER BY id ASC";
if(!$result = mysql_query($sql,$this->link)){die('Invalid Query: '.mysql_error());}
while($row = mysql_fetch_assoc($result)){
$this->Data[$i][$j]['text'] = $row['text'];
$this->Data[$i][$j]['data'] = $row['data'];
$j++;
}
$this->jCount[$i] = $j;
}
}
public function GroupName($id){
$sql = "SELECT group FROM group WHERE id = '$id'";
$result = mysql_query($sql,$this->link);
if(!$result = mysql_query($sql,$this->link)){die('Invalid Query: '.mysql_error());}
while($row = mysql_fetch_assoc($result)){
return $row['group'];
}
}
function __construct(){
$this->link = mysql_connect('localhost','username','password');
if(!$this->link){die('No Connection: '.mysql_error());}
$this->db = mysql_select_db('your_db_name',$this->link);
if(!$this->db){die('No such Database: '.mysql_error());}
$this->init();
}
function __destruct(){
mysql_close($this->link);
}
}
Now you have all data sorted by group in the
DataArray class.
You have all the information you need in
$data->Data,
$data->iCount and
$data->jCount.
$data->Data[number][number]['text']/['data'] - Is containing the sorted data in an array.
$data->iCount - Is containing the amount of groups in the array.
$data->jCount[number] - Is countaining the amount of data in the second array of
$data->Data
From here you can extract the data from the array and put into tables.
EX:
PHP Code:
$data = new DataArray;
$display = "<table border=\"0\">";
for($i=0;$i < $data->iCount;$i++){
$display .= "<tr><td colspan=\"2\">".$data->GroupName($i)."</td><tr><td>Text</td><td>Data</td><tr>";
for($j=0;$j < $data->jCount;$j++){
$display .= "<tr><td>".$data->Data[$i][$j]['text']."</td><td>".$data->Data[$i][$j]['data']."</td></tr>";
}
}
$display .= "</table>";
Hopes this was the solution you where looking for.