TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-23-2009, 06:57 AM   #1 (permalink)
The Visitor
 
Join Date: Aug 2009
Posts: 1
Thanks: 0
cjay is on a distinguished road
Default Retrieve data error...plz help

hello ppl!

i have a xml file and i refresh it with a php file...
into the php file i have a query which i retrieve my data from a sql db...the output result is n't the right...because it "write" to the xml file only the last record from db...look what i mean:

php file:

PHP Code:
<?php
@include("xconf.php");

$query  "SELECT * FROM images";
$result mysql_query($query);

while(
$oz mysql_fetch_array($result))
{

$myFile "data.xml";
$fh fopen($myFile'w') or die("can't open file");
$stringData "<?xml version=\"1.0\" encoding=\"ISO-8859-7\" ?>\n\n<gallery>\n\n<photos>\n";
fwrite($fh$stringData);
$stringData "<photo>\n<thumb src=\"$oz[mikro]\" />\n<img src=\"$oz[s]\" />\n<caption text=\"$oz[title]\" />\n<desc> <![CDATA[$oz[per]]]> </desc>\n</photo>\n\n";
fwrite($fh$stringData);
$stringData "</photos>\n\n";
fwrite($fh$stringData);
$stringData "</gallery>\n";
fwrite($fh$stringData);

fclose($fh);

}
?>
and the data.xml:

PHP Code:
<?xml version="1.0" encoding="ISO-8859-7" ?>

<gallery>

<photos>
<photo>
<thumb src="http://www.talkphp.com/images/thumb_Free_web_development_icon_set.jpg" />
<img src="http://www.talkphp.com/images/Free_web_development_icon_set.jpg" />
<caption text="yt4" />
<desc> <![CDATA[er]]> </desc>
</photo>

</photos>

</gallery>
how can i correct the code? i want the output result appear all the db records...:(

thank you
friendly
cjay is offline  
Reply With Quote
Old 08-23-2009, 12:49 PM   #2 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

PHP Code:
<?php
@include("xconf.php");

$query  "SELECT * FROM images";
$result mysql_query($query);

while(
$oz mysql_fetch_array($result))
{

$myFile "data.xml";
$fh fopen($myFile'w') or die("can't open file");

$stringData "<?xml version=\"1.0\" encoding=\"ISO-8859-7\" ?>\n\n<gallery>\n\n<photos>\n";
fwrite($fh$stringData);

$stringData "<photo>\n<thumb src=\"{$oz['mikro']}\" />\n<img src=\"{$oz['s']}\" />\n<caption text=\"{$oz['title']}\" />\n<desc> <![CDATA[{$oz['per']}]]> </desc>\n</photo>\n\n";
fwrite($fh$stringData);

$stringData "</photos>\n\n</gallery>\n";
fwrite($fh$stringData);

fclose($fh);

}
?>
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 08-24-2009, 06:55 PM   #3 (permalink)
The Wanderer
 
JaimePinheiro's Avatar
 
Join Date: Jul 2009
Posts: 5
Thanks: 0
JaimePinheiro is on a distinguished road
Default

Try to replace this before while loop:
$myFile = "data.xml";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "<?xml version=\"1.0\" encoding=\"ISO-8859-7\" ?>\n\n";

And this:
fclose($fh);
just after.

You are looping through each register of database, and for each one, you are openning the file, writing xml header, writing one register and closing the file, n times.
JaimePinheiro is offline  
Reply With Quote
Old 08-24-2009, 06:57 PM   #4 (permalink)
The Wanderer
 
JaimePinheiro's Avatar
 
Join Date: Jul 2009
Posts: 5
Thanks: 0
JaimePinheiro is on a distinguished road
Default

Oh, just one more thing, the $stringData must concatenate the strings, so inside the while loop you'll have:
$stringData .= "<gallery>\n\n<photos>\n";
...
JaimePinheiro is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Injection and mysql_real_escape_string Durux General 61 01-29-2013 12:20 PM
How do you access your data in a class? Wildhoney Advanced PHP Programming 4 06-08-2009 10:16 PM
Venerable methods and the applications they are commonly trusted in. Village Idiot Tips & Tricks 7 11-06-2008 07:36 AM
The act of sharing your data Wildhoney General 0 12-06-2007 03:31 PM
Tips: PHP security Village Idiot Tips & Tricks 22 11-23-2007 11:17 PM


All times are GMT. The time now is 09:04 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design