problems with web services

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simona_85
Forum Newbie
Posts: 1
Joined: Sun Aug 16, 2009 7:24 am

problems with web services

Post by simona_85 »

For my final work, I need to do online shop over web services. The thing that I can't do is to show values from database when I return them with array. I have found some code over the internet but it return empty array. Can somebody help me?
My code in web service is:

***** Please wrap PHP code with the Code tag (see buttons at top of editor) *****

Code: Select all

require_once('C:\wamp\www\seminarskiIteh\lib\nusoap.php');
 
$connect = mysql_connect("localhost", "root", "") or 
     die ("Neuspesna konekcija sa bazom podataka");
mysql_select_db("seminarski");
$server = new soap_server();
$server -> configureWSDL('webservis', 'urn:webservis');
 
 
$server->wsdl->addComplexType(
    'Proizvod',
    'complexType',
    'struct',
    'all',
    '',
    array(
        'ID' => array('name'=>'ID','type'=>'xsd:int'),
        'naziv' => array('name'=>'naziv','type'=>'xsd:string'),
        'opis' => array('name'=>'opis','type'=>'xsd:string'),
        'cena' => array('name'=>'cena','type'=>'xsd:float'),
        'kolicina' => array('name'=>'kolicina','type'=>'xsd:int')
    )
);
 
 
$server->wsdl->addComplexType(
    'NizProizvoda',
    'complexType',
    'array',
    '',
    'SOAP-ENC:Array',
    array(),
    array(
        array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Proizvod[]')
    ),
    'tns:Proizvod'
);
 
 
$server->register('izmeniProizvode', array(),             
array('return' => 'tns:NizProizvoda'),      
  'urn:izmeniProizvode'                      
);  
 
I just wrote that function izmeniProizvode because the others works...
 
 
function izmeniProizvode(){
$query="SELECT ID,naziv FROM proizvod WHERE kategorija='sofe' ";
 
 
 
        
$result=mysql_query($query)
  or die(mysql_error());
$kolona=mysql_num_rows($result);
 
 
if ($kolona>0){
 
 
while ($row = mysql_fetch_array($result)) {
  
 
$niz[]=array('ID'=>$row['ID'],
                'naziv'=>$row['naziv']
);
 
 
  
}
}
return $niz;
}
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: problems with web services

Post by susrisha »

Code: Select all

 
 
$niz[]=array('ID'=>$row['ID'],
                'naziv'=>$row['naziv']
);
 
I beleive the error lies here. Dont know how to solve it but found out that there is no element to which u are assigning the array.
Isnt it supposed to be

Code: Select all

 
$niz[$somecount]=array('ID'=>$row['ID'],
                'naziv'=>$row['naziv']
);
 
Post Reply