简体   繁体   中英

Foreach loop only looping once?

I'm having trouble with my foreach loop opening multiple files.

My foreach loop is only running once for the first item number. The foreach loop runs then goes to the "api.php" page but then stops and doesn't go back to the foreach loop to get the next item number. How do I tell it to go through all of item numbers in my database?

Would I use cURL somehow?

Thanks

Here's my code:

$itemnumber = array("".$result['item_number']."");

foreach ($itemnumber as $item_number) {

echo "<form method=\"post\" action=\"api.php\" name=\"ChangeSubmit\" id=\"ChangeSubmit\">";
echo "<input type=\"text\" name=\"item_number\" value=\"{$item_number}\" />";

echo "<script type=\"text/javascript\">
function myfunc () {
var frm = document.getElementById(\"ChangeSubmit\");
frm.submit();
}
window.onload = myfunc;
</script></form>";



}

The foreach looks okay, but if you want to let it iterate over multiple numbers, you need to provide multiple. Right now you provide one number only.

You actually have only one item in your array. SO it is looping only once.

Your code $itemnumber = array("".$result['item_number'].""); will translate to

 $itemnumber = array($result['item_number']);

Because, the double double-quotes you provided have no significance in the code too. SO, at last the array will have only one item.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM