Results 1 to 8 of 8

Thread: Expanding Database Results into PHP

  1. #1

    Thread Starter
    Addicted Member mfurqan's Avatar
    Join Date
    Oct 2005
    Location
    Pakistan
    Posts
    176

    Smile Expanding Database Results into PHP

    Hi,

    a database have 4 feilds, book_id autofull , book_title varchar(255), book_desc text, and book_author .. i need to do is to show all listings in htis category in xml format, primary key can be book_title

    can any one help me
    Muhammad Furqan Attari.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Expanding Database Results into PHP

    Very easy - depends on your intended XML output structure though.

    Something like this should get you started

    PHP Code:
    <?php
      $books 
    mysql_query('select * from `books`');
      
      while (
    $book mysql_fetch_assoc($books)):
    ?><book id="<?=$book['book_id']?>">
      <title><?=$book['book_title']?></title>
      <author><?=$book['author']?></author>
      <description><?=$book['book_desc']?></description>
    </book>
    <?php endwhile; ?>
    Should be able to adapt that to your XML structure

  3. #3

    Thread Starter
    Addicted Member mfurqan's Avatar
    Join Date
    Oct 2005
    Location
    Pakistan
    Posts
    176

    Re: Expanding Database Results into PHP

    sorry but is it possible like

    if some one use http://www.domain.com/abcxml.php?bookauthor=ABC

    when some one use XML results retriving cod ewith above url, will it be working ?
    Muhammad Furqan Attari.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Expanding Database Results into PHP

    just change the query

    PHP Code:
    $books mysql_query(select from `bookswhere `author` = \''.$_GET['bookauthor'].'\''); 

  5. #5

    Thread Starter
    Addicted Member mfurqan's Avatar
    Join Date
    Oct 2005
    Location
    Pakistan
    Posts
    176

    Re: Expanding Database Results into PHP

    1 thing please do i need XML headers i mean starting from <xml> tag.. do i need to put these headers in echo""; ???
    Muhammad Furqan Attari.

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Expanding Database Results into PHP

    Send an XML mime type:
    Code:
    header('Content-Type: application/xml');
    And add the XML declaration:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7

    Thread Starter
    Addicted Member mfurqan's Avatar
    Join Date
    Oct 2005
    Location
    Pakistan
    Posts
    176

    Re: Expanding Database Results into PHP

    and in botton /xml right ?
    Muhammad Furqan Attari.

  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Expanding Database Results into PHP

    No. The XML prolog is separate from the root node.

    Here is an example of a complete XML document.

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    
    <root-node>
      <child-node />
    </root-node>
    The child node is unnecessary, I put it in simply for the purpose of an example.

Posting Permissions

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



Click Here to Expand Forum to Full Width