Jump to content

Search the Community

Showing results for tags 'foreach loop'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 4 results

  1. Hi I am new to PHP and I am having an issue with a foreach loop combined with an if statement, basically the if statement is getting the data from the first result in the foreach but not getting the second result, I have tried implement a count by using a variable to iterate but it isnt working: Code as follows: foreach(findCustomAlerts($customerid) as $key=>$value){ echo "ID of cat : ".$rifdid = $value['Catid']."<br>"; echo "Visits required per day : ".$visitsneeded= $value['Visits required']."<br>"; } foreach(getTodaysVisits($device_id) as $rfid){ foreach($rfid as $key=> $read){ if($key ==$rifdid && $read < $visitsneeded) { echo"<br>". $key." has not visited enough"; } } } Ouput is : ID of cat : 5609 Visits required per day : 3 ID of cat : 23641 Visits required per day : 5 Array ( [rfid_id] => Array ( [23641] => 1 [5609] => 3 ) ). -------> this is the array data 23641 has not visited enough ----------------------------------------------- How can I get the loop to iterate to the next value?
  2. I have 2 pages...1 one that has something like 500 checkboxes that list all of the active users in a database. When any number of checkboxes are selected it passes the variables from the checkboxes to the next page, asking for confirmation. Right now I have the 2nd page displaying numbers for the people, but doesn't display the correct entries. The code is below, hopefully it helps: if(isset($_POST['Update'])) //if the update button was pressed { if (isset($_POST['Player_number'])) //checks to see if any checkboxes are selected { //$Player_number = IMPLODE(',',$_POST['Player_number']); //putting the comma in between the array items echo $Player_number; ?> <input type="hidden" name="<?PHP $Player_number; ?>" value="<?PHP $Player_number; ?>"> $Player_number = IMPLODE(',',$_POST['Player_number']); //putting the comma in between the array items $result = mysql_query("SELECT * FROM `players` WHERE `Player_number` = '$Player_number' ORDER BY Player_Last_Name") or die(mysql_error()); while ($row = mysql_fetch_array($result)) //while ($row = mysql_fetch_assoc($result)) { // here is your data echo "FName: ".$row['Player_First_Name']; echo "lName: ".$row['Player_Last_Name']; echo "email: ".$row['player_email']; } foreach($_POST['Player_number'] as $row) { $result = mysql_query("SELECT `Player_First_Name`,`Player_Last_Name`,`player_email`, `Player_number` FROM `players` WHERE `Player_number` = '$Player_number' ORDER BY Player_Last_Name") or die(mysql_error()); $Player_number = IMPLODE(',',$_POST['Player_number']); //putting the comma in between the array items while($rows=mysql_fetch_array($result)) { echo "Player Number: ".$Player_number; //echo "pNumber: ".$row; //echo $rows['Player_First_Name']; ?> <tr bgcolor='<?PHP echo $bkcolor; ?>'> <td width = '20%' height="20"><div align="center"><input type="hidden" name="Player_number[]" value="<?php echo $row; ?>"></div></td> <td width= '20%' headers="20"><div align="center"><?php echo $rows['Player_First_Name']; ?></div></td> <td width= '20%' headers="20"><div align="center"><?php echo $rows['Player_Last_Name']; ?></div></td> <td width= '20%' headers="20"><div align="center"><?php echo $rows['player_email']; ?></div></td> <?PHP }//close of the while loop }//close of the foreach loop }//close of if (isset($_POST['Player_number'])) } //close of (isset($_POST['Update'] My issue that it goes through the For loop that is listed above, but list the player first name X amount of times.
  3. I'm a beginner currently studying Object Oriented Programming. The code in question is quite long so I will just share the snippet that I can't understand. private $productlist = array(); public function addproduct($product){ $this->productlist[] = $product; } public function stockup(){ foreach($this->productlist as $product){ $product->addstock(100); } I'm sure that function addproduct adds product objects to the product list array. What does the foreach loop: foreach($this->productlist as $product) in the stockup function do? Does it take those values and store them back in $product?
  4. I'm having a bit of trouble maintaining the value of a variable within a while do loop. It seems the pointer keeps pointing to the first id no matter how many loops there are. I've inserted a hidden field which pulls in each id with shows the IDs are fine but whenever I click on 'editForm' anchor it always points to either the first or last id in the loop, (depending on whether I put the editForm div tag before or after the loop). Can anyone out there help me fix this problem? The code is shown below: $('.formEditAnchor').click(function() { $('#editMyForm').submit(); }); <?php function editFunction($editID) { $database = new database(); $res = $database->selectDB("select content as EditContent from content where id = '$editID'"); $editForm = "<form method='POST' action='_scripts/_php/edit-file.php'>"; $editForm.= "<textarea name='saveContent' cols='70' rows='25'>"; while($row = mysql_fetch_array($res)) { $row = mysql_fetch_array($res); $editableFile = $row['EditContent']; $editableContent = file($editableFile); $editableString = implode($editableContent); } $editForm.= $editableString; $editForm.= "</textarea>"; $editForm.= "<input type='hidden' name='hiddenEditPath' value='<?php echo $editableFile; ?>' />"; $editForm.= "<br />"; $editForm.= "<input type='submit' name='saveFile' value='Save'>"; $editForm.= "</form>"; return $editForm; } function submitEditForm() { if (isset($_POST['formEditAnchor'])) { $usersReplyId = $_POST['hiddenUserReplyID']; $returnEdit = editFunction($usersReplyId); return $returnEdit; } } $result3 = $database->selectDB("select * from blog_content where content_id = '$id'"); $r = array(); while($rows = mysql_fetch_array($result3)) { $myID = $rows['id']; $file = $rows['content']; $contents = file($file); $string = implode($contents); ?> <form name="editMyForm" id="editMyForm" method="post" action"<?php echo $_SERVER["PHP_SELF"]?>"> <input type="hidden" name="hiddenUserReplyID" id="hiddenUserReplyID" value="<?php echo $myID ?>" /> <table> <tr> <tr> <td bgcolor="#F8F7F1" align="center">Date/Time:<?php echo $rows['datetime']; ?></td> </tr> <tr> <td bgcolor="#f8f7f1"><?php echo $string; echo "<br /><br />"; ?> </td> </tr> <tr> <td><a href="#editContent" class="create-content" id="formEditAnchor" onclick="<?php $myReturnEdit = submitEditForm(); ?>">Edit File</a></td> </tr> </tr> </table> </form> <?php } ?> <div id='editContent' class='create-topic'> <?php echo $myReturnEdit; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.