Yes, you’re correct in saying you need to add the field names to the web service results. What I’d imagine would be something like this, as in post #28:
$returnValue = $result;
$properties = explode('|', $returnValue);
unset($nt);
foreach ($properties as $item) {
$tHotel = explode('/', $item);
$nt['Id_Hot'] = $tHotel[0];
$nt['Eml_Hot'] = $tHotel[1];
$nt['Nom_Hot'] = $tHotel[2];
// and do this for each field in the original $nt
// results from your query, so it's the same layout
// then add it to the main array
$hotelArray[] = $nt; // exactly the same as from your query.
}
var_dump($hotelArray);
So what we’re doing here is trying to transform the data you get back from the web service into the same format as the data you got back from the query. So we create a blank array called $nt
, give it all the same field names, and just assign the correct values (or nothing) to each one. Once that’s done, for each one, we append to the main array exactly as we did for the query results. The idea is that we end up with an array where you no longer care where the data came from, because it’s all in the same format, so all you have to do is output it.
As for arrays, think of them as a table of data items which are accessed by a key - similar to a database table in that regard. That key can be a number, or a string, depending on what is most convenient. So if you ran this code:
$nt = array(); // create a blank array
$nt[] = "Test"; // append an element to it
$nt[] = "Another test"; // and another
you now have a table of data like:
Array $nt :
Index | Data
0 | "Test" - string, 4 chars long
1 | "Another Test" - string, 12 chars long
You would access those strings directly as $nt[0]
or $nt[1]
, or using a foreach()
loop.
When you create a two-dimensional array, that’s basically an array of arrays. So with this code:
$hotelArray = array();
for ($i = 1; $i<6; $i++ ) {
$nt[0] = "Test " . $i;
$nt[1] = "Temp " . $i;
$hotelArray[] = $nt;
}
you run through a loop five times, create an array ($nt) of two elements, which contain a word and the value of the loop. Then you append that array to the main array. So you now get
Index | Data
0 | array{ 0 = "Test 1", string 6 chars; 1= "Temp 1", string 6 chars }
1 | array{ 0 = "Test 2", string 6 chars; 1= "Temp 2", string 6 chars }
2 | array{ 0 = "Test 3", string 6 chars; 1= "Temp 3", string 6 chars }
3 | array{ 0 = "Test 4", string 6 chars; 1= "Temp 4", string 6 chars }
4 | array{ 0 = "Test 5", string 6 chars; 1= "Temp 5", string 6 chars }
and you’d access those using both indices:
echo $hotelArray[0][0]; // gives "Test 1"
echo $hotelArray[3][1]; // gives "Temp 4"
So if you expand on that using field names instead of numbers for the second dimension, you’ll have an array like
Index | Data
0 | array { "Nom_Hot" = "smartline Hotel"; "Id_Hot" = "247682" etc. for each field}
And you can access them via your foreach() and display them easily, because they’re all in the same format.
I did wonder if this was the same site that had a way to load parts of the total data set and a ‘next’ button, the two trailing divs looked familiar. That’s something you’ll have to add later, I suspect, and in the meantime consider at what point in the list you want to add in the hotels that come from the web service.