THIS WORKS:
1 $number = 2;
2 $allofit = simplexml_load_file("thexmlfile.xml");
3 $thebook = $allofit -> booklist[$number] -> abook;
4 echo $thebook;
THIS FOLLOWING DOES NOT WORK: But if I want to read $number from a from with method GET I set
6 $number=$_GET[thenumber]; // $number=2 from the form//
7 echo $number; // and properly shows $number=2 --*/
8 $allofit = simplexml_load_file("thexmlfile.xml");
9 $thebook = $allofit -> booklist[$number] 开发者_运维百科-> abook;
10 echo $thebook;
The echo on line 10 reports nothing (no error, just blank space in the html) even though I can successfully echo $number in line 7... so its being set, but just not picked up in line 9.. although the equivalent in line 3 works (!).
Any ideas folks?
Thanks in advance J
$number=$_GET[thenumber];
At this stage $number is a string.
Do you need to coerce it into an integer? Probably with intval? http://php.net/manual/en/function.intval.php
Try:
$number=intval($_GET[thenumber]);
PHP should convert your "2" to a 2 without a problem. My guess is that you're missing quotes: $number=$_GET[thenumber]
. Try $number=$_GET['thenumber'];
精彩评论