PHP การสร้างฟอร์มเพื่อสร้าง XML นี่ทำยังไงหรอคะ โดย มายองเนสจัง

เริ่มโดย มายองเนสจัง, 30 กันยายน 2012, 11:43:46

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

มายองเนสจัง

XML ที่มายองคิดไว้ประมาณนี้น่ะค่ะ แต่ไม่ค่อยเข้าใจการสร้างไฟล์ ของ PHP เท่าไหร่  :P

<?xml version="1.0" encoding="utf-8"?>
<activity>
    <name>Mayong</name>
    <category>Travel</category>
    <content>blabla bla bla bla bal bla bla bla </content>
</activity>

ต้องสร้างไฟล์ php ยังไงหรอคะ รบกวนด้วยค่ะ งงเต้กเลย  :wanwan001:


:wanwan022: :wanwan022:

whatif

มารออ่าน คำตอบ คำถามหมูหยอง ...
ก็ write เป็น textfile ดื้อๆ เลย หรือลองหา class/function มาใช้งานโลด

มายองเนสจัง


smapan

อ้างถึงจาก: มายองเนสจัง ใน 30 กันยายน 2012, 12:04:37
ปัญหาคือ ความรู้ PHP เท่านิ้วก้อยค่ะ  :wanwan001:

ไม่รู้ต้องลงเงินครับ จ้างเพื่อนๆในนี้แหละครับ

หรือปัญหาต่อไปคือเงินอีก  :P
[direct=http://cp.siamhostweb.com/cart.php?gid=1]จูมล่าโฮส สยามโฮสเว็บ[/direct] [direct=http://www.modty.com]modty.com[/direct]
[direct=http://www.apartment.in.th]รวมที่พัก เช่ารายวัน ที่พักเช่ารายเดือนมากที่สุดแจ่มจริง[/direct]
***Tel 083-757-1515 ติดปัญหา Joomla ตรงไหนรับปรึกษาฟรี โทรมาเถอะครับ ถ้าตอบได้ช่วยแน่นอน ไม่มีกั้ก. ***

มายองเนสจัง

ขอลองงมก่อนละกันค่ะ ถ้าไม่ได้จริงๆ ค่อยจ้างคนเขียนเอา  :wanwan022:

smapan

[direct=http://cp.siamhostweb.com/cart.php?gid=1]จูมล่าโฮส สยามโฮสเว็บ[/direct] [direct=http://www.modty.com]modty.com[/direct]
[direct=http://www.apartment.in.th]รวมที่พัก เช่ารายวัน ที่พักเช่ารายเดือนมากที่สุดแจ่มจริง[/direct]
***Tel 083-757-1515 ติดปัญหา Joomla ตรงไหนรับปรึกษาฟรี โทรมาเถอะครับ ถ้าตอบได้ช่วยแน่นอน ไม่มีกั้ก. ***

liveadsense

ทำไมผมอ่านแล้วไม่ค่อยเข้าใจ ต้องการ จะสร้างยังงัย ลองดูไม่รู้ตรงคำถามป่าว  :P

file xml.php

header("Content-Type: application/xml; charset=utf-8"); # จั่วหัวไปก่อน
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
print("<activity>");
  #### ดึงข้อมูลจาก db มาใส่  ####
print("</activity>");


หรือ อีกความหมาย


$file = 'file/data.xml';
$data = '
<?xml version="1.0" encoding="utf-8"?>
<activity>
    <name>Mayong</name>
    <category>Travel</category>
    <content>blabla bla bla bla bal bla bla bla </content>
</activity>
';
$fp = fopen($file, 'w');
fwrite($fp, $data);
fclose($fp);


น่าจะประมาณนี้ครับ

เตือนตัวเอง ว่าเก่งได้ แต่อย่ากร่าง
รู้รับฟัง ไม่ใช่พล่ามเป็นน้ำไหล
อย่าหลงตน ให้คนอื่นเหนื่อยหน่ายใจ
เจอบันได ถ้าขึ้นได้ ต้องลงเป็น

moshikub1

ถ้าง่ายหน่อยใช้

Dom ครับผม


<?
include("connect.php");
$sql = "SELECT * FROM Products";
$query = mysql_query($sql,$conn);
if($query) {
header("Content-type:text/xml");
$dom = new DOMDocument();
$products = $dom->createElement("products");
$dom->appendChild($products);

while($rs = mysql_fetch_assoc($query)) {
$pro_item = $dom->createElement("pro_item");
$products->appendChild($pro_item);

foreach($rs as $fieldname => $fieldvalue) {
$child = $dom->createElement($fieldname);
$child = $pro_item->appendChild($child);
$value = $dom->createTextNode($fieldvalue);
$value = $child->appendChild($value);
}
}
$dom->save("pro.xml");
$xml = $dom->saveXML();
echo $xml;
}
?>


อย่างตัวนี้ดึงออกมาจากฐานข้อมูล ครับ เซฟลง pro.xml


<?xml version="1.0"?>
<products>
<pro_item>
<ProductID>1</ProductID>
<ProductName>Chai</ProductName>
<SupplierID>1</SupplierID>
<CategoryID>1</CategoryID>
<QuantityPerUnit>10 boxes x 20 bags</QuantityPerUnit>
<UnitPrice>18</UnitPrice>
<UnitsInStock>39</UnitsInStock>
<UnitsOnOrder>0</UnitsOnOrder>
<ReorderLevel>10</ReorderLevel>
<Discontinued>0</Discontinued>
</pro_item>
<pro_item>
<ProductID>2</ProductID>
<ProductName>Chang</ProductName>
<SupplierID>1</SupplierID>
<CategoryID>1</CategoryID>
<QuantityPerUnit>24 - 12 oz bottles</QuantityPerUnit>
<UnitPrice>19</UnitPrice>
<UnitsInStock>17</UnitsInStock>
<UnitsOnOrder>40</UnitsOnOrder>
<ReorderLevel>25</ReorderLevel>
<Discontinued>0</Discontinued>
</pro_item>
</products>


ข้อมูลก็แล้วแต่ฐานข้อมูลของเราครับ ผมใช้

foreach($rs as $fieldname => $fieldvalue) {

อ่านค่าเอาครับ
[direct=http://xn--72c6afaabg9f6ca6ci1b0pmcr0c.com]งานออนไลน์[/direct] | [direct=http://www.xn--l3cuicec1bie1f0ac4mg5cze.com]รายได้เสริม[/direct] |   [direct=http://www.xn--l3cuicec1bie1f0ac4mg5cze.com]รายได้พิเศษ[/direct] | [direct=http://xn--12cbfs2fia1ehdz2gga2etb5bxa7l1d6c8e.com/]ธุรกิจออนไลน์[/direct] | [direct=http://www.niyombrand.com]ชุดเวียดนาม[/direct]

รับปั่น UIP ละ 6 บาทต่อเดือน เช่น 1000UIP/วัน = 6000 บาท จำนวนเยอะต่อรองราคาได้ เป็นคนไทยคนจริง 99%

รับทำ Autopost CURL หน้าเว็บได้ทุกรูปแบบครับ PM มาได้เลย ราคาสบายๆ

ball6847

เรื่องที่ต้องใช้ก็มี
- html ในการสร้างฟอร์ม
- การรับค่าจาก form ด้วย php
- รู้จักตัวแปรชนิด String ใน php
- รู้โครงสร้างของ XML
- รู้วิธีการเอา String เขียนลงไฟล์ด้วย file_put_contents

มายองทำได้แน่นอน ถ้ามีเวลางมมากพอ ยกเว้น ถ้าไม่มีเวลาก็หาคนมาช่วย ...
We use Ubuntu.

[direct=http://ng-seo.sourcelab.xyz/]AngularJS SEO Experimental[/direct]