Php & Xml

shortened the 1st post since this thread was getting long…

uncomment this line

//header("Content-type: text/xml");

should be like this:

header("Content-type: text/xml");

I wrote this tutorial about it: http://www.kirupa.com/web/mysql_xml_php.htm

thanks… that helped… forgot I commented it out when trying to debug…but got another problem… now

see below edit post so thread would be shorter and not to much CODE :slight_smile:

that seems like something to do with your database set-up… can’t realy tell you how to fix that because all databases are different…

I thought that but have played around with the DB and still same result … DB is MYSQL and the table looks like this

Table structure for table board

CREATE TABLE board (
id int(11) NOT NULL auto_increment,
parent int(11) default ‘0’,
thread int(11) default ‘0’,
name tinytext,
email tinytext,
subject tinytext,
message text,
date timestamp(14) NOT NULL,
ip varchar(15) default NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;

i think it has something to do with my array… not sure thought… back to hunting and pecking thru the code…

heres the next stuck point …

NOT… finally got it figured out…

thanks for all the help…

working code


<?php
//{}_______________________________________________________________________________________________________________
	$mbname = "Message Board";
	$dbname = "mx_board";
	$dbhost = "localhost";
	$dbuser = "root";
	$dbpass = "";
	$limit  = "40";
	$page = 1;
//{}_______________________________________________________________________________________________________________	
	header("Content-type: text/xml");
//{}_______________________________________________________________________________________________________________	
	$link = mysql_connect($dbhost, $dbuser, $dbpass) or die("Error!");
	mysql_select_db($dbname, $link) or die("Error!");
	$q = mysql_query("SELECT id FROM board WHERE parent=0 ORDER BY date DESC",$link);
	$z = mysql_query("SELECT *,UNIX_TIMESTAMP(date) FROM board WHERE parent=0",$link);
	list($id,$parent,$thread,$name,$email,$subject,$message,$baddate,$ip,$date)=mysql_fetch_row($z);
	$date = date("Y-m-d g:i:sa",$date); 
	$list = array();
	while(list($id)=mysql_fetch_row($q)) {
		array_push($list,$id);
	}
	$num_threads = count($list);
	$threads = array_splice($list,0,($limit * $page));
	$html .=  "<OBJ who=\"BINARYCORTEX \">FMX BOARD
";
	foreach($threads as $id) {
			if($id == $thread) {
		$html .= "</OBJ>";
	}

		thread($id);
	}
	$html .= "</OBJ></OBJ>";
	mysql_close($link);
	swapHtml($html);
function thread ($id) {
	global $mes_id;
	global $link;
	global $html;
	global $page;
	$q = mysql_query("SELECT *,UNIX_TIMESTAMP(date) FROM board WHERE id=$id",$link);
	list($id,$parent,$thread,$name,$email,$subject,$message,$baddate,$ip,$date)=mysql_fetch_row($q);
	$date = date("Y-m-d g:i:sa",$date); 
	$name = htmlspecialchars($name);
	$email = htmlspecialchars($email);
	$subject = htmlspecialchars($subject);
	$message = htmlspecialchars($message);
	if($id == $thread) {
		$html .= "<OBJ who=\"$name\" when=\"$date\" z=\"$id\"  y=\"$parent\"  x=\"$thread\"> $subject";
	}
	if($parent > 0) {
		$html .= "<OBJ who=\"$name\" when=\"$date\" z=\"$id\" y=\"$parent\"  x=\"$thread\"> $subject";
	}
	$q = mysql_query("SELECT id FROM board WHERE parent=$id ORDER BY date DESC",$link);
	$num=mysql_numrows($q);
	if($num) {
		while(list($id)=mysql_fetch_row($q)){
			thread($id);
		}
	}
	if($parent > 0) {
		$html .= "</OBJ>";
	}
		if($id == $thread) {
		$html .= "</OBJ>";
	}
}
function swapHtml($html) {
	$contents = $html;
	echo $contents;
}
?>

well I thought it was working… only works for the data I was testing with… once i tried new data it was broke again… the code shouldn’t be that hard, just trying make a old school message board but in a XML format

trying to get this
-1st post
-----reply to 1st post
-2nd post
-3rd post
------reply to 3rd
------------reply to 2nd of 3rd post
-4th post

to look like this in PHP
<obj>1st post
<obj>reply to 1st</obj>
</obj>
<obj>2nd post</obj>
<obj>3rd post
<obj>reply to 3rd
<obj>reply to 2nd of 3rd post</obj>
</obj>
</obj>
<obj>4th post</ob>

the above code is somewhat working, having problems inserting the </obj> at the right places…something with the IF statements I think… please help :slight_smile:

if it helps heres the data in the SQL Database

CREATE TABLE beta_board (
id int(11) NOT NULL auto_increment,
parent int(11) default ‘0’,
thread int(11) default ‘0’,
subject tinytext,
PRIMARY KEY (id)
) TYPE=MyISAM;

Dumping data for table beta_board

INSERT INTO beta_board VALUES (1, 0, 1, ‘1ST POST’);
INSERT INTO beta_board VALUES (2, 0, 2, ‘2ND POST’);
INSERT INTO beta_board VALUES (3, 0, 2, ‘3RD POST’);
INSERT INTO beta_board VALUES (4, 0, 2, ‘4TH POST’);
INSERT INTO beta_board VALUES (5, 1, 1, ‘REPLY TO 1ST POST’);
INSERT INTO beta_board VALUES (6, 3, 2, ‘REPLY TO 3RD POST’);
INSERT INTO beta_board VALUES (7, 6, 2, ‘REPLY TO 2ND OF 3RD POST’);

and for anyone who can help me get this working… I’ll give the FLA for this project…

view the project here ----> http://66.93.244.18/dev/