PHP
  Home arrow PHP arrow Page 4 - Building A Document Request Protocol Part ...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Building A Document Request Protocol Part 2/2
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-02-24

    Table of Contents:
  • Building A Document Request Protocol Part 2/2
  • Connecting to our SARP server
  • Logging in
  • Using SARP commands
  • Adding new content using SARP commands
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Building A Document Request Protocol Part 2/2 - Using SARP commands


    (Page 4 of 6 )

    Now that we're connected and authenticated, we can use any of the SARP commands that we defined in the first article to retrieve the details of the brands and cars in our articles database. If your memory needs refreshing, here are the commands we've defined for our SARP server to respond to:
    • LOGIN [user] [password]
    • LIST CATEGORIES
    • LIST ARTICLES [category name]
    • ADD CATEGORY [category name]
    • ADD ARTICLE [title] [content] [price] [category id]
    Let's retrieve the list of categories from our SARP server (remember that when our SARP server receives this command, it uses a select * from categories query to retrieve the category names from our Access database and forms them into a single string variable):

    fputs($sarpHandle, "LIST CATEGORIES");

    $sarpData = fgets($sarpHandle, 1024);


    The data returned into the $sarpData variable looks like this:

    1|BMW;4|Lamborghini;2|Mercedes-Benz;3|Porsche;

    We can use PHP's explode function to separate each categories ID and name into an array:

    $cats = explode(";", $sarpData);

    echo "<h3>Available Content:</h3>";


    Now that each category is separated into a separated index in the $cats array, we can loop through each category and use the "LIST ARTICLES" SARP command to retrieve the details of each article stored in our SARP servers Access database:

    for($i = 0; $i < sizeof($cats) - 1; $i++)

    {

    $catFields = explode("|", $cats[$i]);

    echo $catFields[1] . "<br>";



    fputs($sarpHandle, "LIST ARTICLES " . $catFields[0]);

    $sarpData = fgets($sarpHandle, 1024);



    $arts = explode(";", $sarpData);

    echo "<ul>";



    for($j = 0; $j < sizeof($arts) - 1; $j++)

    {

    $art = explode("|", $arts[$j]);

    echo "<li><b>" . $art[1] . "</b><br>";

    echo $art[2] . "<br><b>Price: $" . number_format($art[3], 2, ".", ",");

    echo "</b></li>";

    }



    echo "</ul>";

    }


    The output from the code above looks like this:

    Retrieving categories and articles from our SARP server

    More PHP Articles
    More By Mitchell Harper


     

    PHP ARTICLES

    - Making Usage Statistics in PHP
    - Installing PHP under Windows: Further Config...
    - File Version Management in PHP
    - Statistical View of Data in a Clustered Bar ...
    - Creating a Multi-File Upload Script in PHP
    - Executing Microsoft SQL Server Stored Proced...
    - Code 10x More Efficiently Using Data Access ...
    - A Few Tips for Speeding Up PHP Code
    - The Modular Web Page
    - Quick E-Commerce with PHP and PayPal
    - Regression Testing With JMeter
    - Building an Iterator with PHP
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT