[php] meerdimensionale array uit functie (nusoap)

Pagina: 1
Acties:

Onderwerpen


Verwijderd

Topicstarter
Normaal lurk ik een beetje rond op deze forums, maar nu heb ik toch echt hulp nodig met dit probleem.

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<<SERVER.PHP>> 
<?php 
// includes nusoap classes 
    require('nusoap.php'); 
    
    // create server 
    $l_oServer = new soap_server(); 
   
    // wsdl generation 
    $l_oServer->debug_flag=false; 
    $l_oServer->configureWSDL('eehmmDB', 'http://localhost'); 
    $l_oServer->wsdl->schemaTargetNamespace = 'http://localhost'; 

    // add complex type 
    $l_oServer->wsdl->addComplexType( 
        'ArtikelData', 
        'complexType', 
        'struct', 
        'all', 
        '', 
        array( 
            'NI_HEADLINE' => array('name'=>'NI_HEADLINE', 'type'=>'xsd:string'),  
            'NI_ARTIKEL' => array('name'=>'NI_ARTIKEL', 'type'=>'xsd:string')) 
            //'AANTAL' => array('name' => 'AANTAL', 'type' =>'xsd:string')) 
    ); 
   
    // register method 
    $l_oServer->register('getArtikel',  
                        array('artikel' => 'xsd:string'),  
                        array('return'=>'tns:ArtikelData'),  
                        'http://localhost'); 
   
    // method code (get DB result) 
    function getArtikel ($a_stInput) { 
        if (is_string($a_stInput)) {    
            $l_oDBlink   = @mysql_connect( 
                'localhost', 'root', ''); 
            $l_oDBresult = @mysql_db_query( 
                'eehmmDB',  
                'SELECT * FROM nieuwsberichten WHERE NI_HEADLINE = LCASE("' . mysql_escape_string((string)$a_stInput) . '") LIMIT 1'); 
           
            // simple error checking 
            if (!$l_oDBresult) { 
                return new soap_fault('Server', '', 'Internal server error.'); 
            } 
      
            // no data avaible for artikelen 
            if (!mysql_num_rows($l_oDBresult)) { 
                return new soap_fault('Server', '','Niet gevonden.'); 
            } 
            mysql_close($l_oDBlink); 
               
             
             
            // return data 
            return mysql_fetch_array($l_oDBresult, MYSQL_ASSOC);     
        }  
        // we accept only a string 
        else { 
          return new soap_fault('Client', '', 'Service requires a string parameter.'); 
        } 
      } 
   
    // pass incoming (posted) data 
    $l_oServer->service($HTTP_RAW_POST_DATA); 
?> 



<<CLIENT.PHP>> 
<?php 
  // use form data 
     if ((string)$_GET['action'] == 'get_data') { 
    
         // includes nusoap classes 
         require('nusoap.php'); 
   
         // set parameters and create client 
        $l_oClient = new soapclient_xxx('http://localhost/servert/server.php?wsdl', 'wsdl'); 
        $l_oProxy  = $l_oClient->getProxy(); 
         
        // call a webmethod (getWeather) 
        $l_stResult = $l_oProxy->getArtikel((string)$_POST['headline']); 
       
        // check for errors 
        if (!$l_oClient->getError()) { 
          // print results   
          print '<h1>Current data for: '  . (string)$_POST['headline']  
              . ':</h1><ul><li>hoofdlijn: '   . $l_stResult['NI_HEADLINE']  
              . '</li><li>inhoud: ' . $l_stResult['NI_ARTIKEL']  
              . '</li></ul>'; 
           
          print_r(array_keys($l_stResult)); 
        } 
        // print error description 
        else { 
          echo '<h1>Error: ' . $l_oClient->getError() . '</h1>'; 
        } 
    } 
   
    // output search fclientorm 
    print ' 
        <form name="input" action="'.$_SERVER['PHP_SELF'].'?action=get_data"  method="POST"> 
        Hoofdlijn: <input type="text" name="headline"> 
        <input type="submit" value="Search"> 
        </form> 
    '; 
?> 


Het ophalen van een enkele array uit de getArtikel functie lukt wel, maar er moet nu een meerdimensionale array uit de functie gehaald worden, die dus ook via de webservice naar de client gestuurd wordt.

  • NMe
  • Registratie: Februari 2004
  • Laatst online: 09-09 13:58

NMe

Quia Ego Sic Dico.

Hoi fburgh85, en welkom op GoT. :)

Ik ben bang dat we je met deze topicstart niet echt kunnen helpen. Je dumpt je code en zegt wat je wil, maar je geeft niet aan wat er momenteel fout gaat en wat je überhaupt probeert te doen. Daarnaast is het niet de bedoeling dat wij voor jou gaan debuggen, aangezien je zelf de enige bent die dat kan doen, aangezien jij de volledige code hebt, inclusief de kennis die je nodig hebt om het te kunnen gebruiken. Lees ook P&W FAQ - De "quickstart" even door. :)

Pas dus even je startpost aan met wat meer informatie, en eidt wat code weg zodat alleen relevante code over blijft. Op die manier word je het snelst geholpen. :)

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


Acties:
  • 0 Henk 'm!

  • T-MOB
  • Registratie: Maart 2001
  • Laatst online: 22:34
Tsja welke items wil je precies hebben in je meerdimensionale array? Om ze allemaal op te halen voldoet het volgende. Hierin heb ik alle eigenaardigheden in de code laten staan waaronder het openen van een database-connectie bij elke functie-aanroep...
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// method code (get DB result) 
function getAllArticles () {
    $output = array();
    
    $l_oDBlink   = @mysql_connect('localhost', 'root', ''); 
    $l_oDBresult = @mysql_db_query('eehmmDB', 'SELECT * FROM nieuwsberichten'); 
        
    // simple error checking 
    if (!$l_oDBresult) { 
        return new soap_fault('Server', '', 'Internal server error.'); 
    } 
      
    // no data avaible for artikelen 
    if (!mysql_num_rows($l_oDBresult)) { 
        return new soap_fault('Server', '','Niet gevonden.'); 
    } 
     
    while ($data = mysql_fetch_assoc($l_oDBresult)) {
        array_push($output, $data);
    }
        
    return $output;
}

Regeren is vooruitschuiven