Reputation: 3253
I have a function below which gets name from a site. Below is the partial code, not complete. The values are passed thru a for loop using php.
function funct($$name,$page)
{
$url="http://testserver.com/client?list=$name&page=$page";
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,url);
$result=curl_exec($ch);
$dom = new DOMDocument();
@$dom->loadHTML($result);
$xpath=new DOMXPath($dom);
$elements = $xpath->evaluate("//div");
foreach ($elements as $element)
{
$name = $element->getElementsByTagName("name")->item(0)->nodeValue;
$position=$position +1;
echo $name.$position;
}
}
The code works fine but when i get a name i need to add a position and for each name it will be incremented by 1 to make it contentious. But when the values for the pages are passed, for an example when i move from page 1 to page 2. the count starts again from first, next page... same problem.
How can i make it continues on every page?
Upvotes: 0
Views: 95
Reputation: 8020
Either make $position
a global variable (global $position;
) or pass it to the function: function funct($name, $page, &$position)
. (What's with the variable variable $$name
in your function signature?)
Upvotes: 2