Jump to content

[SOLVED] convert ASP coding to PHP


Nazirul

Recommended Posts

Hi...

 

i want to declare XML in PHP just like ASP code below :

 

<!--#include file="ADOVBS.INC"-->
<%
Set ConnObj = Server.CreateObject("ADODB.Connection")
Set RstObj = Server.CreateObject("ADODB.Recordset")

ConnObj.Open "spa"

sql="select *from CUSTOMER"

set RstObj=ConnObj.Execute(sql,RecordsAffected) %>

<?xml version="1.0" encoding="windows-1252"?>
<?xml-stylesheet type="text/xsl" href="ViewAllSpaCust.xsl"?>

<Senarai_Pelanggan>

<% While not rstobj.eof %>

<senarai> </senarai><senarai><Nama><%=rstobj("CUSTNAME")%></Nama> 

<NoIc><%=rstobj("CUSTIC")%></NoIc> <Gender><%=rstobj("CUSTGENDER")%></Gender> 

<Address><%=rstobj("CUSTADDRESS")%> </Address>

<Race><%=rstobj("CUSTRACE")%></Race> 

<Dob><%=rstobj("CUSTDOB")%></Dob> 

<MobileNo><%=rstobj("CUSTMOBILENO")%></MobileNo> 

<HomeNo><%=rstobj("CUSTHOMENO")%></HomeNo>

<MemberDate><%=rstobj("CUSTMEMBERDATE")%></MemberDate> 

</senarai> 

<%rstobj.MoveNext%>

<%wend%>

</Senarai_Pelanggan>

 

what is the similar syntax for the XML embedded in PHP just like the ASP.. i've tried :

 

<?php

//php code goes here

?>

<?xml version="1.0" encoding="ISO-8859-1"?>
..

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>...

 

but no luck.. it give error :

 

Parse error: syntax error, unexpected T_STRING in C:\wamp\www\collegeXML\ViewStudent.php on line 28

 

hmm.. :D

Link to comment
Share on other sites

well whats the php code inside your php tags? Cant tell u what the error is without anycode to look at...

 

and you more likley would have something along these lines...

<?php

//php code goes here to query DB

?>

<?xml version="1.0" encoding="windows-1252"?>
<?xml-stylesheet type="text/xsl" href="ViewAllSpaCust.xsl"?>

<Senarai_Pelanggan>

<?php
//your php goes here....just echo/print any xml eg...

echo '<tag>'. $phpVariableHoldingValue .'</tag>';
?>

</Senarai_Pelanggan>

 

or you can also look into php5's XMLWriter class...

Link to comment
Share on other sites

well... the error was in line 28 .. that refer to the <?xml version="1.0" encoding="windows-1252"?>

 

im not sure if it either php version problem...im using php 4.4.8 right now..

 

i've tried this

 

<studNumber><? $Student_Number ?></studNumber>

 

but no luck...

Link to comment
Share on other sites

ah...yes....i've come accross that before my work around for that was just to echo the xml declaration...

 

<?php
echo '<?xml version="1.0" encoding="windows-1252"?>';
?>

 

Its the only way I was able to do it, php interpreter might confuse the <?xml for a short php tag.....

Link to comment
Share on other sites

lol.. use ----> php 5

 

<?php
echo '<?xml version="1.0" encoding="ISO-8859-1"?>';
echo '<?xml-stylesheet type="text/xsl" href="ViewStudent2.xsl"?>';
echo '<student>';
echo '<room_number>'. $room_number .'</room_number>';
echo '<student_number>'. $student_number .'</student_number>';
echo '<student_name>'. $student_name .'</student_name>';
echo '<student_course>'. $student_course .'</student_course>';
echo '<semester>'. $semester .'</semester>';
echo '<address>'. $address .'</address>';
echo '<under>'. $Undergraduate_From .'</under>';
echo '</student>';
?>

 

that works... but the XSL cant be used ..

echo '<?xml-stylesheet type="text/xsl" href="ViewStudent2.xsl"?>';

 

 

Link to comment
Share on other sites

how about sending some headers specifying that its an XML document...then maybe your document be rendered correctly...

<?php
header('Content-type:text/xml');
echo '<?xml version="1.0" encoding="ISO-8859-1"?>'; //after echo and before <? theres a ' 
echo '<?xml-stylesheet type="text/xsl" href="ViewStudent2.xsl"?>';
echo '<student>';
echo '<room_number>'. $room_number .'</room_number>';
echo '<student_number>'. $student_number .'</student_number>';
echo '<student_name>'. $student_name .'</student_name>';
echo '<student_course>'. $student_course .'</student_course>';
echo '<semester>'. $semester .'</semester>';
echo '<address>'. $address .'</address>';
echo '<under>'. $Undergraduate_From .'</under>';
echo '</student>';
?>

 

Link to comment
Share on other sites

not work..

 

i think the reason why it works might be.. the php ignore the '<room_number' n etc... and only display the $value

 

my friend email me the working code and it is :

 

<?php
ob_start();
session_start();
?>
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="detail.xsl"?>
<!DOCTYPE recipe SYSTEM "detail.dtd">
<recipe>
<?php
$id = $_GET['id'];
include("library/config.php");
include("library/opendb.php");
$sql = "SELECT * FROM recipe WHERE id = '$id' AND act = '0'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$cat_id = $row['category'];
$sql = "SELECT cat_name FROM category WHERE id = '$cat_id'";
$result2 = mysql_query($sql);
$r = mysql_fetch_array($result2);
?>
<data>
<recId><?php echo $id; ?></recId>
<recTitle><?php echo $row['title']; ?></recTitle>
<ingredient><?php echo $row['ingredient']; ?></ingredient>
<instruction><?php echo $row['instruction']; ?></instruction>
<suggestion><?php echo $row['suggestion']; ?></suggestion>
<comment><?php echo $row['comment']; ?></comment>
<source><?php echo $row['source']; ?></source>
<sender><?php echo $row['name']; ?></sender>
<email><?php echo $row['email']; ?></email>
<date><?php echo $row['date']; ?></date>
<catId><?php echo $cat_id; ?></catId>
<catName><?php echo $r['cat_name']; ?></catName>
</data>
<formFunction>
<approve><a href='approve.php' class='content'>Approve</a></approve>
</formFunction>
<?php
include("library/closedb.php");
?></recipe>

 

great thanks : DarkSuperHero   ;D

you are very helpful... :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.