SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php as xml? (xml to retrieve mysql data)

    well i was using one of the xml/flash slideshow.Well the slide show takes the image source and link as follows from a xml file called images.xml

    Code:
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <images>
        <pic>
            <image>http://www.xyz.com/modelimage/image1.jpg</image>
    		<link>http://www.xyz.com/modelimage/showmodel.php?id=1</link>
        </pic>
       <pic>
            <image>http://www.xyz.com/modelimage/image2.jpg</image>
    		<link>http://www.xyz.com/modelimage/showmodel.php?id=2</link>
        </pic>
       <pic>
            <image>http://www.xyz.com/modelimage/image3.jpg</image>
    		<link>http://www.xyz.com/modelimage/showmodel.php?id=3</link>
        </pic>
    </images>

    now what i want is to display the latest 3 images from my modelimage folder(the files are uploaded through php and filename is added to database and file is transferred to folder)
    googling and going through some tutorials...
    i came up with this..


    PHP Code:
    <?php 

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

    $host "localhost"
    $user "root"
    $pass ""
    $database "dbname"

    $linkID mysql_connect($host$user$pass) or die("Could not connect to host."); 
    mysql_select_db($database$linkID) or die("Could not find database."); 

    $query "SELECT photo_id,image FROM model_photo ORDER BY postedon DESC limit 3"
    $resultID mysql_query($query$linkID) or die("Data not found."); 

    $xml_output "<?xml version=\"1.0\"?>\n"
    $xml_output .= "<images>\n"

    for(
    $x $x mysql_num_rows($resultID) ; $x++){ 
        
    $row mysql_fetch_assoc($resultID); 
        
    $xml_output .= "\t<pic>\n"
          
    $xml_output .= "\t\t<image>\"http://www.xyz.com/modelimage/{$row['photo_id']}\"</image>\n";  
       
    $xml_output .= "\t\t<link> \"http://www.xyz.com/modelimage/showmodel.php?id= {$row['photo_id']}\"</link>\n";//have doubt in this line
       
        
    $xml_output .= "\t</pic>\n"


    $xml_output .= "</images>"

    echo 
    $xml_output

    ?>
    note:i used google got one tutorial and edited it so it may conatin some parse error...help to remove it would be great

    it should be saved as images.php (not xml) but the flash file has the hardcoded images.xml filename(xml file) in actionscript (fla file)...

    so how can i get it work with out using any external plugin or mod rewrite(there can be other real xml files)...

    any idea...?
    here ...the file should be xml but it should contain php which retrives data from mysql to show images

    any help
    so how can i het it work...
    (or i should use only use xml file(with out php) to get data from mysql..if that is the way any help how it can be done)

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What's wrong with mod_rewrite?
    Saul

  3. #3
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View Post
    What's wrong with mod_rewrite?
    i was not trying to exploit xml....well i am new to mod rewrite but intrepretreting all the php files as xml or all xml files as php...there can be problem in the run long...
    so was just trying to be safe...

    is that only the solution...

    i searched the whole day..
    can any body me a good link to flash slideshow backed by php(mysql)
    i found the one called ..manni.us...
    but it has its one link for whole movie which cannot be removed..
    and doesnt work on ie6...

    other actually no luck...
    finally i got it work but it is xml based...

    so any others..any body..

    any way even this this is mod rewrite only option left now...
    i am not sure but how about putting the swf file in the php page..and every time the php page is excessed it outouts to xml files and updates it.,..

    but i am confused how to output..and fear it will be too clumsy...

    any way thanks
    if this problem is solved i guess we can convert any xml based slideshow to php...

  4. #4
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You got the idea of mod_rewrite all wrong. You can simply rewrite images.php to images.xml, leaving other all xml files completely out of scene. It's ForceType you're talking about that would make all your xml files php parseable.
    Saul

  5. #5
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View Post
    You got the idea of mod_rewrite all wrong. You can simply rewrite images.php to images.xml, leaving other all xml files completely out of scene. It's ForceType you're talking about that would make all your xml files php parseable.
    so in our scenario what can we do...
    save second file and xml and mod rewrite in htacess to intrepret as php?

    by the way is that second file error free..prase error..?
    thanks

  6. #6
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Have a images.php exactly as you posted in your original post.

    Use mod_rewrite rule to pass the handle to images.php when images.xml is requested:

    RewriteRule ^images.xml$ images.php
    Saul

  7. #7
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View Post
    Have a images.php exactly as you posted in your original post.

    Use mod_rewrite rule to pass the handle to images.php when images.xml is requested:

    RewriteRule ^images.xml$ images.php
    that means i need add this line to htacess file ...RewriteRule ^images.xml$ images.php(as i have said i am new to mod rewrite)
    by the way what should be done to test it locally..should we need to make htacess file...

    next thing i have doubt there may be problem with the php file...can any body have a quick look on it...

    by the way for once again are there any other slideshow based on php+flash +mysql(not that mani)...
    thanks

  8. #8
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yep, .htaccess. If you run apache locally too, it's the same. The full code to add would be:
    Code:
    RewriteEngine on
    
    RewriteRule ^images.xml$ images.php
    Your code seems ok more or less. Did you test it? Except maybe in the xml that you output itself -- you don't need double quotes around the links between <image> and <link> tags.
    Saul

  9. #9
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View Post
    Yep, .htaccess. If you run apache locally too, it's the same. The full code to add would be:
    Code:
    RewriteEngine on
    
    RewriteRule ^images.xml$ images.php
    Your code seems ok more or less. Did you test it? Except maybe in the xml that you output itself -- you don't need double quotes around the links between <image> and <link> tags.
    really thanks..
    any way well i am using easy php 1-8 locally...and i cannot see any .htacess file in the root..i need htacess file in the folder the swf ..php ..xml resides or the root...
    or i need to have htacess file in the root folder..may be apache..do i need to create myself...

    well really thanks..sorry for asking but as i am new to mod rewrite..

    by the way is it good idea to follow this kind of tech using xml in this way..
    thanks...

  10. #10
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    after searching whole day and reading forums..i found this ...
    http://www.kirupa.com/forum/attachme...6&d=1163709142
    this seems quite similar what i was looking for i have not tested it yet..
    but it has used xml inside php and used php file...xml file not required..

    any way i am testing
    really thanks php_daemon for allsupport
    keep good thought and help coming

  11. #11
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It's definitely ok.

    You have to create the .htaccess in the folder your php script resides.
    Saul

  12. #12
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by frank1 View Post
    after searching whole day and reading forums..i found this ...
    http://www.kirupa.com/forum/attachme...6&d=1163709142
    this seems quite similar what i was looking for i have not tested it yet..
    but it has used xml inside php and used php file...xml file not required..

    any way i am testing
    really thanks php_daemon for allsupport
    keep good thought and help coming
    Your problem is feeding the xml document to your flash app. There's no difference as far as the extension to an xml document itself, but since you can't modify your flash app, you have to feed it as images.xml. That's how I see your situation anyway.
    Saul

  13. #13
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View Post
    Your problem is feeding the xml document to your flash app. There's no difference as far as the extension to an xml document itself, but since you can't modify your flash app, you have to feed it as images.xml. That's how I see your situation anyway.
    sorry i feel like i have been like a dumb ..do you mean to say that changing file name from images.xml to xml.php will do the job..
    i dont know actionscript and felt that it must have xml...
    i do have fla here it is

    Code:
    var id, current;
    var k = 0, p = 0;
    var slide = 1;
    function loadXML(loaded) {
    	if (loaded) {
    		xmlNode = this.firstChild;
    		image = [];
    		link = [];
    		total = xmlNode.childNodes.length;
    		for (i=0; i<total; i++) {
    			image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
    			link[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
    		}
    		id = setInterval(preloadPic, 100);
    	} else {
    		content = "file not loaded!";
    	}
    }
    xmlData = new XML();
    xmlData.ignoreWhite = true;
    xmlData.onLoad = loadXML;
    xmlData.load("images.xml");
    function preloadPic() {
    	clearInterval(id);
    	var con = picture.duplicateMovieClip("con"+k, 9984+k);
    	con.loadMovie(image[p]);
    	preloader._visible = true;
    	con._alpha = 0;
    	var temp = _root.createEmptyMovieClip("temp"+k, 99+k);
    	k++;
    	temp.onEnterFrame = function() {
    		var total = con.getBytesTotal();
    		var loaded = con.getBytesLoaded();
    		percent = Math.round(loaded/total*100);
    		preloader.preload_bar._xscale = percent;
    		if (con._width) {
    			preloader._visible = false;
    			con.onEnterFrame = fadeIn;
    			if (slide) {
    				id = setInterval(nextImage, 5000);
    			}
    			delete this.onEnterFrame;
    		}
    	};
    }
    MovieClip.prototype.fadeIn = function() {
        if (this._alpha<100) {
            current._alpha -= 10;
            this._alpha += 10;
        } else {
            current._visible = 0;
            current = this;
            this.onRelease = function() {
                getURL(link[p], "_blank");
            };
            delete this.onEnterFrame;
        }
    };
    function nextImage() {
    	p<total-1 ? p++ : p=0;
    	preloadPic();
    }
    function picture_num() {
    	current_pos = p+1;
    }
    preloadPic();

    do you mean to say that changing this line
    xmlData.load("images.xml");
    to xmlData.load("images.php");
    will do the job..

    sorry if all seems stupid ..i dont have much idea about xml and action script...
    really thanks for help

    Note :link i gave in above post was made in flash 8 so i was unable to test ..so seems like should stick this this one
    any way thanks

  14. #14
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by frank1 View Post
    do you mean to say that changing this line
    xmlData.load("images.xml");
    to xmlData.load("images.php");
    will do the job..


    I thought you didn't have the source. In that case, definitely, all you need to do is to change the extension.

    And for the reference, you can not only change the extension, but add params to it too. For example, your script can return a specified amount of images -- xmlData.load("images.php?count=10") would work perfectly fine.
    Saul

  15. #15
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View Post


    I thought you didn't have the source. In that case, definitely, all you need to do is to change the extension.

    And for the reference, you can not only change the extension, but add params to it too. For example, your script can return a specified amount of images -- xmlData.load("images.php?count=10") would work perfectly fine.
    really sorry to be dumb actually oversmart and thinking how could that problem..
    actually it did work...
    just i used images.xml in place of images.xml
    all started working ..fine..
    some time it happen..
    sorry for taking time
    some time little knowledge is really dangerous...
    really thanks...php_daemon..
    really thanks....
    any way it is getting glitterly bcoz of mysql query i will have a look
    thanks

    after all xml is very powerful cross platform..language..i should have rememberred old college lectures
    thanks

  16. #16
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Sure, glad to help
    Saul


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •