zero-perfoliate
zero-perfoliate

Author Topic: How do i return more than one result  (Read 372 times)

Offline Tracy

  • New PHP Members
  • Posts: 1
  • Karma: +0/-0
How do i return more than one result
« on: February 18, 2009, 08:32:32 AM »
Hi all, sorry for the long script but i am trying to return more than one result from the web server except i am not sure how to do it! Any ideas would be appreciated! Thank you.

<?php

$inCountry=false;
$inCity=false;
$inBar=false;
$inDesc=false;
$inId=false;

$countrys=array();
$citys=array();
$bars=array();
$descs=array();
$ids=array();

include ('call_web_service.php');

$a = $_POST["country"];
$b = $_POST["method"];

$result = call_web_service
("http://my_database_address/my_username/restserver.php?country=$a","$b");

$parser=xml_parser_create();
xml_set_element_handler($parser, "foundAnOpeningTag","foundAClosingTag");
xml_set_character_data_handler($parser, "foundSomeText");
xml_parse($parser,$result["content"]);
xml_parser_free($parser);

for($count=0; $count < count($countrys); $count++)
{
    echo "Country: " . $countrys[$count] . "
";
    echo "City: " . $citys[$count] . "
";
    echo "Bar: " . $bars[$count] . "
";
    echo "Description: " . $descs[$count] . "
";
    echo "ID: " . $ids[$count] . "
";
}

function foundAnOpeningTag($parser,$tag,$attributes)
{
   
    global $inCountry, $inCity, $inBar, $inDesc, $inId;
    if($tag=="COUNTRY")
    {
        $inCountry=true;
    }
    elseif($tag=="CITY")
    {
        $inCity=true;
    }
    elseif($tag=="BAR")
    {
       $inBar=true;
    }
    elseif($tag=="DESCRIPTION")
    {
       $inDesc=true;
    }
    elseif($tag=="ID")
    {
       $inId=true;
    }
}


function foundAClosingTag($parser,$tag)
{
    global $inCountry, $inCity, $inBar, $inDesc, $inId;
    if($tag=="COUNTRY")
    {
       $inCountry=false;
    }
    elseif($tag=="CITY")
    {
       $inCity=false;
    }
    elseif($tag=="BAR")
    {
       $inBar=false;
    }
    elseif($tag=="DESCRIPTION")
    {
       $inDesc=false;
    }
    elseif($tag=="ID")
    {
       $inId=false;
    }
}

function foundSomeText($parser,$characters)
{
    global $inCountry, $inCity, $inBar, $inDesc, $inId, $countrys, $citys, $bars, $descs, $ids;
    if($inCountry)
    {
        $countrys[] = $characters;
    }
    elseif($inCity)
    {
        $citys[] = $characters;
    }
    elseif($inBar)
    {
        $bars[] = $characters;
    }
    elseif($inDesc)
    {
        $descs[] = $characters;
    }
    elseif($inId)
    {
        $ids[] = $characters;
    }
}
?>

Offline PhPHelper

  • http://Digiscapers.com
  • Full Member
  • PHP Problem Solvers
  • ****
  • Posts: 179
  • Karma: +50/-0
    • Bad Apple Mail
Re: How do i return more than one result
« Reply #1 on: February 18, 2009, 09:10:03 AM »
Hi Tracy

what does this output:

Code: [Select]
for($count=0; $count < count($countrys); $count++)
{
    echo "Country: " . $countrys[$count] . "
";
    echo "City: " . $citys[$count] . "
";
    echo "Bar: " . $bars[$count] . "
";
    echo "Description: " . $descs[$count] . "
";
    echo "ID: " . $ids[$count] . "
";
}

 

zero-perfoliate