Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem displaying mysql data in specified html format

Status
Not open for further replies.

Edward07

Programmer
Apr 13, 2007
49
NL
Hi all. I have the following php script that supposed to output mysql data in specified html format. The data is chat trascript but unfortuently it never outputs data and it gives me no error. could any one look at this and let me know what i am doing wrong.Thanks

The script supposed to create one line of html as shown for each row in db.
Code:
<font COLOR='#0000FF'>Edward: </font><font COLOR='#000000'>How are you?</font><br>
and if the row belongs to visitor it change the color of the text to #800080( if column textdataby has value you then we know it is for visitor text)

Code:
<font COLOR='#0000FF'>Visitor: </font><font COLOR='#800080'>I am doing good</font><br>

displaydata.php
Code:
<?
 Header('Cache-Control: no-cache');
 Header('Pragma: no-cache');

$sessionkey=$_GET['sessionkey'];

$server   = "localhost"; // MySQL hostname
$username = "root"; // MySQL username
$password = "root"; // MySQL password
$dbname   = "data"; // MySQL db name

$db = mysql_connect($server, $username, $password) or die(mysql_error());

      mysql_select_db($dbname) or die(mysql_error());

 //my otherquery

$res = mysql_query("SELECT textdata,textdataby,type,d FROM chattextuser where sessionkey='$sessionkey' ORDER BY date ASC") or die('<error>'.mysql_error().'</error>');

?>
<html>

<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>

<body scroll='no' leftmargin='0' topmargin='0' oncontextmenu='return true'>

<iframe name="textFrame" frameborder="0" border="0" width=100% height=100% ></iframe>

<script language="javascript">

function create()

{

var win = window.textFrame;

var doc = win.document;

doc.open("text/html");

doc.write("<html>\r\n<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\r\n<body \r\nborder='0' topmargin='0' bottommargin='0' leftmargin='10' rightmargin='10'>\r\n<center>\r\n<TABLE border='0' cellspacing='0' cellpadding='0' width='100%'>\r\n<TR><TD DIR='LTR'>\r\n<FONT FACE='Arial' SIZE='2'>\r\n<?

while($row = mysql_fetch_assoc($res))
{ 

echo '<font COLOR='#0000FF'>'.$row['textdata'].': </font><font COLOR='#000000'>'.$row['textdataby'].'</font><br>'; 

}
?>
</FONT>\r\n</TD></TR></TABLE></center>\r\n</BODY>\r\n</HTML>\r\n");

doc.close();

}

function scroll()

{

var win = window.textFrame;

win.scroll(0, 50000);

}

create();

scroll();

</script>

</body>

</html>
 
The line used to echo you result:
Code:
echo '<font COLOR='#0000FF'>'.$row['textdata'].': </font><font COLOR='#000000'>'.$row['textdataby'].'</font><br>';
You use single quotes to wrap your string, but you also have single quotes around the value of the COLOR attributes of the FONT tags. This should result in a parsing error. Try changing the line to:
Code:
echo '<font COLOR=\'#0000FF\'>'.$row['textdata'].': </font><font COLOR=\'#000000\'>'.$row['textdataby'].'</font><br>';
You may also want to use standard php tags instead of short tags. <?php ... ?>
 
Thanks for your suggestion. Itshim i tried your solution now when i check the source code of the page i see all part of the code but unfortunetly it doesn't display my data!! I think the problem is that all code inside doc.write("....");are not in one big line. That is why no data is shown on the page. Could you help me fix this problem?
 
we can help with php queries. go to the javascript forum for js queries.

the php looks fine to me. test this by removing all the js stuff and just echoing the data to the screen outside of the doc.write.

assuming your data is actually there then the js people can help further.

Code:
$server   = "localhost"; // MySQL hostname
$username = "root"; // MySQL username
$password = "root"; // MySQL password
$dbname   = "data"; // MySQL db name


$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

//always escape data used in queries
//if magic quotes is on, turn it off.
$sessionkey = mysql_real_escape_string(trim($_GET['sessionkey']));

$res = mysql_query("SELECT textdata,textdataby,type,d FROM chattextuser where sessionkey='$sessionkey' ORDER BY date ASC") or die(mysql_error());

while ($row = mysql_fetch_assoc($res)){
  echo "<pre>".printr($row, true)."</pre>";
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top