PHP - How To Exit Foreach At The Following Statement
HI,
I have a foreach loop but after some execution it begins to show me this:Invalid argument supplied for foreach() ... so I want to exit from it.how can I do that? Thanks Similar TutorialsHi 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 Array ( [rfid_id] => Array ( [23641] => 1 [5609] => 3 ) ). -------> this is the array data
----------------------------------------------- How can I get the loop to iterate to the next value?
Edited October 3, 2020 by Barand code block/indents Object- Take array of IP addresses and add up all occurrences of a particular IP address. //$item is an array of IP addresses foreach ($item as $key => $unique_ip) { if($unique_ip == $ip) $a++; } echo $a; I get a blank page. What am I missing? I have some code that will update a record and is generic, meaning any POST variables can be used - whatever you have on the form. See below: Code: [Select] $set = array(); foreach($_POST as $field => $value){ $field = mysql_real_escape_string($field); $value = mysql_real_escape_string($value); $set[] = "`{$field}` = '{$value}'"; } $query .= implode(", ",$set) . " WHERE $id_name = '".$id."' LIMIT 1"; mysql_query($query) or die(mysql_error()); My question is, how would I modify this to insert a NEW record (not update an existing one). I'm not sure how to order this within a foreach statement because the add query has a different form: insert into tabel (all the fieldnames here) VALUES (all the values here) I am having a go at writing my own simple gallery. As the I want to display an image from a folder in a directory of all the images... for example, I have 10 folders each containing images. I want my code to take image 01.jpg out of each folder and display it on my page, so that when I add folders to my main images folder, they will automatically be added to the page... but I only want the last 10 folders to display... so once I have 20 folders, it only shows 10. I also want the images to be 5 across and then make a new row. My folders will be numbered in order... 001, 002, 003, etc... and I need them sorted in reverse order, so the folder added last is displayed first. So... this is where I am at with the code : Code: [Select] $dir = "gallery/"; if (is_dir($dir)) { [color=red] foreach(array_keys($file) as $n) {[/color] if ($n+1 == 5) { echo "<td><img src=\"" . $dir . $file . "/01.jpg\" width=\"140px\" height=\"93px\" alt=\"\" /></td></tr><tr>"; } elseif ($n+1 > 10) { echo ""; } else { echo "<td><img src=\"" . $dir . $file . "/01.jpg\" width=\"140px\" height=\"93px\" alt=\"\" /></td>"; } closedir($dh); } } For some reason, I am getting the following error on the page : Warning: First argument to array_keys() should be an array in /path/to/gallery.php on line 8 Warning: Invalid argument supplied for foreach() in /path/to/gallery.php on line 8 line 8 is the one in red above. So... I have a couple of questions... 1. What have I done wrong so far? I cannot see it 2. How would I then go about putting the galleries in reverse order? I know it must be rsort, but not to sure if I need to do this first or after... ? Any help greatly appreciated, and I would also be greatful f an idiot's explanation, as I am really trying to understand all this! I'm getting there... slowly! hi, i am having issues with sorting within a conditional statement. please see the code below. right now, i ve commented out the sorting below. basically i want to sort by: $venue1->hereNow->count. I am managing to pull the data correctly. see: http://marineboudeau.com/lab/4sq/ <?php if (is_object($venue->response)) { //sort($venue->response->groups[0]->items->hereNow->count); foreach ($venue->response->groups[0]->items as $venue1) { if ($venue1->hereNow->count != '0'){ //var_dump ($venue1); echo "<div style='font-weight:bold;'>".$venue1->name."</div>"; echo "<div>".$venue1->location->address." ".$venue1->location->city."</div>"; echo "<div>".$venue1->hereNow->count."</div>"; echo "</br>"; } } }?>() any idea what i need to do to make it happen? thank you. marine hi guys.. im not sure if im in the right section but. i have this script below and it exits BUT i would like it to exit After it applies the CSS to my Error. i want it to display nothing except the error if there is an error.. the php is being included on the index.php page which links to the css. this works IF i put the include after the CSS link but wondering if theres a better way. PHP <?php $host = 'localhost'; $user = 'user'; $pass = 'password'; $db = 'upload'; $link = @mysqli_connect( $host, $user, $pass, $db); if(!$link){?> <div id='conn_error'> <?php echo 'There was an Error Connecting to the Server'; ?> </div><?php } ?> Css Code: [Select] #conn_error{ background: red; font-size: 24px; font-family: arial; color: white; width: 500px; text-align: center; border: solid 2px black; position: absolute; top: 150px; left: 30%; padding: 2px; } The code seems to cear debug until I attempt to exit after doing a while loop. PHP Parse error: syntax error, unexpected T_ELSE in C:\Users\Bob\Desktop\TAFT WEB\test\login.php on line 46 Here's the code: <?php /* -----------------------NOVEMBER 2010-------------------- */ // User has 3 trys to enter correct username and password // increment by one $num_log = ($num_logs + 1); if ($_POST['username']) { //Connect to the database through our include include_once "connect_to_mysql.php"; $username = stripslashes($_POST['username']); $username = strip_tags($username); $username = mysql_real_escape_string($username); $password = ereg_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters $password = md5($password); } // Make query and then register all database data that - // cannot be changed by member into SESSION variables. // Data that you want member to be able to change - // should never be set into a SESSION variable. $sql = mysql_query("SELECT * FROM register WHERE username='$username' AND password='$password'"); $login_check = mysql_num_rows($sql); if($login_check > 0); { while($row = mysql_fetch_array($sql)){ // Get member ID into a session variable $id = $row["id"]; session_register('id'); $_SESSION['id'] = $id; // Get member username into a session variable $username = $row["username"]; session_register('username'); $_SESSION['username'] = $username; // Update last_log_date field for this member now mysql_query("UPDATE user_log SET log_on=now() WHERE id='$id'"); // Print success message here if all went well then exit the script header("location: memPage.shtml php?id=$id"); exit(); } // close while ERROR ---> else { exit() } // Print login failure message to the user and link them back to your login page print '<br><br> <font color="#FF0000"> No match was found in our member records, try again. </font> <br><br> <a href="login.php">Click here</a> to go back to the login page.'; exit(); // close if post ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Login to your profile</title> <script type="text/javascript"> <!-- Form Validation --> function validate_form ( ) { valid = true; if ( document.logform.email.value == "" ) { alert ( "Please enter your User Name" ); valid = false; } if ( document.logform.pass.value == "" ) { alert ( "Please enter your password" ); valid = false; } return valid; } <!-- Form Validation --> </script> </head> <body> <div align="center"> <h3 style="test-align:center;font-weight:bold; color:blue;padding-top:25px;padding-bottom;15px;"> Log in to your account here </h3> </div> <table align="center" cellpadding="5"> <form action="login.php" method="post" enctype="multipart/form-data" name="logform" id="logform" onsubmit="return validate_form ( );"> <tr> <td class="style7"><div align="right">Username:</div></td> <td><input name="username" type="varchar" id="username" size="30" maxlength="50" /></td> </tr> <tr> <td class="style7"><div align="right">Password:</div></td> <td><input name="password" type="password" id="password" size="50" maxlength="24" /></td> </tr> <tr> <td> </td> <td><input name="Submit" type="submit" value="Login" /></td> </tr> </form> </table> </body> </html> I'm new to php and I created a user registration form. But whenever I submit the form, part of my page doesn't load. I see the "successful registration" message, but I don't see my right sidebar, footer, or my wrapper div. After searching the internet all day, I concluded it was the exit() function. But if I leave in the exit function and submit the form, all of my page loads, but the original registration form is still shown below my "successful registration" message. Can someone please help? Code: [Select] <?php require_once('_includes/connectvars.php'); if (isset($_POST['submitted'])) { $firstname = mysql_real_escape_string(trim($_POST['firstname'])); $lastname = mysql_real_escape_string(trim($_POST['lastname'])); $email = mysql_real_escape_string(trim($_POST['email'])); $birthdate = mysql_real_escape_string(trim($_POST['birthdate'])); $zipcode = mysql_real_escape_string(trim($_POST['zipcode'])); $gender = $_POST['gender']; $username = mysql_real_escape_string(trim($_POST['username'])); $password1 = mysql_real_escape_string(trim($_POST['password1'])); $password2 = mysql_real_escape_string(trim($_POST['password2'])); $terms = $_POST['terms']; $newsletter = $_POST['newsletter']; $activationkey = mt_rand() . mt_rand() . mt_rand() . mt_rand() . mt_rand(); $captchchk = 1; require_once('_includes/recaptchalib.php'); $privatekey = "some#"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (preg_match ('%^[A-Za-z\.\' \-]{2,15}$%', stripslashes(trim($_POST['firstname'])))) { $firstname = escape_data($_POST['firstname']); } else { $firstname = FALSE; echo '<p class="error">Please enter a valid first name!</p>'; } if (preg_match ('%^[A-Za-z\.\' \-]{2,30}$%', stripslashes(trim($_POST['lastname'])))) { $lastname = escape_data($_POST['lastname']); } else { $lastname = FALSE; echo '<p class="error">Please enter a valid last name!</p>'; } if (preg_match('%^(0?[1-9]|1[012])[/](0?[1-9]|[12][0-9]|3[01])[/](19|20)?[0-9]{2}$%', stripslashes(trim($_POST['birthdate'])))) { $birthdate = escape_data($_POST['birthdate']); } else { $birthdate = FALSE; echo '<p class="error">Please enter a valid date of birth in the format of MM/DD/YYYY</p>'; } if (preg_match ('%^[0-9]{5}$%', stripslashes(trim($_POST['zipcode'])))) { $zipcode = escape_data($_POST['zipcode']); } else { $zipcode = FALSE; echo '<p class="error">Please enter a valid 5 digit zip code!</p>'; } if ($gender !== 'M') { if ($gender !== 'F') { echo '<p class="error">Please select your gender!</p>'; } } if (preg_match ('%^[A-Za-z][A-Za-z0-9]*(?:_[A-Za-z0-9]+)*(\S{4,75})$%', stripslashes(trim($_POST['username'])))) { $username = escape_data($_POST['username']); } else { $username = FALSE; echo '<p class="error">Please enter a valid username!</p>'; } if (preg_match ('%^[A-Za-z0-9]{6,15}$%', stripslashes(trim($_POST['password1'])))) { $password1 = escape_data($_POST['password1']); if (($_POST['password1'] == $_POST['password2']) && ($_POST['password1'] != $_POST['username'])) { $password1 = escape_data($_POST['password1']); } elseif ($_POST['password1'] == $_POST['username']) { $password1 = FALSE; echo '<p class="error">Your password cannot be the same as the username!</p>'; } else { $password1 = FALSE; echo '<p class="error">Your password did not match the confirmed password!</p>'; } } else { $password1 = FALSE; echo '<p class="error">Please enter a valid password!</p>'; } if ($terms !== 'Y') { echo '<p class="error">You must agree to the terms of use!</p>'; } if (!$resp->is_valid) { echo '<p class="error">The CAPTCHA Code wasn\'t entered correctly!</p>'; $captchchk = 0; } if ($firstname && $lastname && $email && $birthdate && $zipcode && $gender && $username && $password1 && $terms && $captchchk) { $query = "SELECT * FROM members WHERE username = '$username'"; $result = mysql_query($query) or trigger_error(mysql_error().$query); if(mysql_num_rows($result) == 1) { echo '<br><br><p class="error">An account already exists for this username. Please select a different username.</p>'; $username = ""; } else { if(mysql_num_rows($result) == 0) { $query = "INSERT INTO members (first_name, last_name, email, dob, zip_code, gender, username, password, join_date, newsletter, active, terms, status) VALUES ('$firstname', '$lastname', '$email', STR_TO_DATE('$birthdate', '%m/%d/%Y'), '$zipcode', '$gender', '$username', SHA('$password1'), NOW(), '$newsletter', '$activationkey', '$terms', 'verify')"; $result = mysql_query($query) or trigger_error(mysql_error().$query); if (mysql_affected_rows() == 1) { $to = $_POST['email']; $subject = "Registration"; $message = "Welcome to Mysite.com!\n\nYou, or someone using your email address, has completed registration at Mysite.com. You can complete registration by clicking the following link:\n\nhttp://www.mysite.com/verify.php?$activationkey\n\nIf this is an error, ignore this email and you will be removed from our mailing list.\n\nRegards,\n\nThe Mysite.com Team"; $headers = 'From: noreply@ Mysite.com' . "\r\n" . 'Reply-To: noreply@ Mysite.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); echo '<br /><br /><p>Thank you for registering! A confirmation email has been sent to your email. Please click on the link in that email in order to activate your account.</p>'; } else { $queryString = $_SERVER['QUERY_STRING']; $query = "SELECT * FROM members"; $result = mysql_query($query) or trigger_error(mysql_error().$query); while($row = mysql_fetch_array($result)){ if ($queryString == $row["active"]){ echo "Congratulations!" . $row["username"] . " is now a member of Mysite.com!"; $query="UPDATE members SET active = '', status='activated' WHERE (user_id = $row[user_id])"; if (!mysql_query($query)) { die('Error: ' . mysql_error()); } } } } } } } exit(); mysql_close(); } There is a function (that cannot be changed) which has an include:
<?php function a() { include 'file.php'; echo 'work'; } ?> ==file.php== <?php echo 'play'; ## Need to leave a() now! ?>The included file can be changed. I would like a way for file.php to cause PHP to return out of the function a(). A return; statement in file.php has PHP pick up execution with the statement following include. What is there in PHP that will allow returning out of a() at some point in file.php? I have a script that allows a User to create a new password as part of a password re-set flow. In my script, I store the $memberID in the Session so that when I redirect from "create_password.php" to "results.php" I still have the $memberID and can store it in the transaction log in my database. The problem is that even though I have unset() after the redirect, it is somehow erasing the value in $_SESSION['memberID'] before the redirect, and thus I get "0" in the database when "results.php" runs?! // Temp Password expires in 1 hour (3600 seconds). if ((time() - $tempResetOn)>10){ // Temp Password Expired. $_SESSION['resultsCode'] = 'PASSWORD_TEMP_PASSWORD_EXPIRED_2112'; // Set Error Source. $_SESSION['errorPage'] = $_SERVER['SCRIPT_NAME']; // Redirect to Outcome Page. header("Location: " . BASE_URL . "/members/results.php"); unset($_SESSION['memberID']); // End script. exit(); }//End of CHECK FOR EXPIRED TEMP PASSWORD How do I unset the Session variable - in the "create_password.php" script above - AFTER I successfully redirect and store the $memberID in the database? Thanks, Debbie hey all; I have a member.php page filled with html and some php, at the top the first thing it does is check for a session if it's not present it displays Sorry you must be logged in to view this page if it's there is says welcome blah blah blah problem is even if it's not present it's showing all the rest the content under the sorry you must be logged in to view this page.. tried adding an exit; did the same thing showed content and tried die; did the same thing showed content? Hi, I have been working on an application where when the user logs in, the status field in the database isset to 1 (online), and when logging off set to 0 (offline). I was wondering if there is a way, using PHP or otherwise, of accomodating for when the user closes the browser manually? I have been looking at other forums who say that it is possible to set a timer which automatically logs the user off after a set amount of time but I dont know how to actually do this or where to start; will the code go on every page of the site? Thanks in advance for any replies I am trying to protect my queries to check the user's ip address to make sure they are not banned... When I comment out the if statement in $db->query the error goes away... The checkIp function works in other instances, I am just trying to call it so nobody can inject things by trying to go around the actual pages... my db function class looks like this: Code: [Select] class dblib { function query($sql) { if ($this->checkIp($_SERVER['REMOTE_ADDR']) == true) { die("GH".$ip); // Used to see if I can get that far... $result = mysql_query($sql) or die("Database error: " . mysql_error() . "<br /><br /><h2>SQL</h2><p>$sql</p>"); return $result; } else { die("<h1>Banned</h1>"); } } /// .......some other functions function checkIp($ip) { $sql = "SELECT * FROM block WHERE ip='$ip' LIMIT 1 "; $result = $this->query($sql); if (mysql_num_rows($result) == 0) return true; else return false; } This topic has been moved to Application Frameworks. http://www.phpfreaks.com/forums/index.php?topic=355772.0 I have a db class that contains several db functions. The biggie is $db->query($sql) function. EVERYTHING that goes to the database goes through this function, and I want to add some security... I have a another function in the db class, checkIp($ip) that checks to see if the ip is in the block list or not. Whenever I update the code (from the simple $result = mysql_query()... and return $result to have the if..else statement, I get a signal Segmentation fault... Any ideas? Code: [Select] class dblib { function query($sql) { if ($this->checkIp($_SERVER['REMOTE_ADDR'])) { //die("GH"); // For testing... $result = mysql_query($sql) or die("Database error: " . mysql_error() . "<br /><br /><h2>SQL</h2><p>$sql</p>"); return $result; } else { die("<h1>Banned</h1>"); } } function checkIp($ip) { $sql = "SELECT * FROM block WHERE ip='$ip' LIMIT 1 "; $result = $this->query($sql); if (mysql_num_rows($result) == 0) return true; else return false; } } I'm having issues with the following: Code: [Select] <?php session_start(); $_SESSION['username']=$_POST['username']; $_SESSION['password']=$_POST['password']; if($_SESSION['username']=="username" && $_SESSION['password']=="password"){ if($_GET['product']=="add"){ $content.=' <p><label>Product Name:</label> <input type="text" name="product_name" size="30" /> <label>Product Price:</label> <input type="text" name="product_price" size="5" /> </p> <p><label>Product Category:</label> <input type="text" name="product_category" size="30" /></p> <p><label>Product Link:</label> <input type="text" name="product_link" size="30" /></p> <p><label>Product Image:</label> <input type="text" name="product_image" size="30" /></p> <p><label>Product Tag:</label> <input type="text" name="product_tag" size="30" /></p> <p><label>Product Keywords:</label> <input type="text" name="keyword" size="30" /></p> <p><label>Product Features:</label><br /> <textarea name="product_features" rows="10" cols="60"></textarea> </p> <p><label>Product Pros:</label><br /> <textarea name="product_pros" rows="5" cols="30"></textarea> </p> <p><label>Product Cons:</label><br /> <textarea name="product_cons" rows="5" cols="30"></textarea> </p> <p><label>Product Description:</label><br /> <textarea name="product_description" rows="10" cols="60"></textarea> </p> <p><label>Product Notes:</label><br /> <textarea name="product_notes" rows="5" cols="30"></textarea> </p> '; $logout='<div><a href="./acp_admincp.php?log-out">Log-Out</a></div>'; } elseif($_GET['product']=="view"){ } else{ $content.=' <a href="./admincp.php?product=add">Add New Product</a> <br /> <a href="./admincp.php?product=view">View Products</a> '; } } elseif(isset($_GET['log-out'])){ session_start(); session_unset(); session_destroy(); header("Location: ./admincp.php"); } else{ $content=' <form action="./admincp.php" method="post"> <p><label>Username:</label> <input type="text" name="username" size="30" />'; $content.='</p> <p><label>Password:</label> <input type="password" name="password" /></p>'; $content.='<p><input type="submit" value="Submit" name="Submit" /></p> </form>'; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <base href="http://ghosthuntersportal.com/" /> <title>Ghost Hunter's Portal - Admin Control Panel</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="verify-v1" content="" /> <meta name="keywords" content="ghost, hunters, hunter, ghosts, spirit, spirits, paranormal, investigation, investigator, investigators, k2, emf, meter, kii" /> <meta name="description" content="Ghost Hunters Potal. Parnormal research equipment store." /> <meta name="author" content="Andrew McCarrick" /> <meta name="robots" content="index, follow" <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <img src="./logo.png" alt="Ghost Hunter's Portal Admin Control Panel" /> <br /> <div style="color: #AA44AA; font-size: 26px; margin-top: -30px; margin-left: 125px;">Admin Control Panel</div> <?php echo $logout; echo $content; ?> </body> </html> I can log-in, and get to the page with the two links on it. However, once I click one of the links it falls back to the log-in page, and it ends up being a never ending loop. It's doing this: Log-In --> Page with links ---> Log-In page again Should be doing this: Log-In --> Page with links --> Add Product page or View Products page I can never get into the the actual sub page. Just to be clear, the address bar actually shows product=add or product=view, but it still shows the log-in page.
Is there a shorthand for:
This obviously doesn't work (but I tried it anyway 😃 )
.... I also tried every permutation of: Maybe a stupid question... after typing it out, if($dog!='bark') exit('go away'); looks pretty short already. I'm not sure if the title explains it very well, but here is an image of it. I am trying to figure out how to access the option selected (equal, not equal, etc.), along with its input box, for each column (the checkboxes on the right) selected. The purpose of this is to allow a non-programming administrator user to create a custom query to access information. I can find out which checkboxes are selected no problem, but finding the accompanying drop-down option and input box is difficult for me. How do I do this? If you have a suggestion on how to change it, I'm very open. Thank you in advance! Code: [Select] if(!isset($_POST['submit'])) { echo " <form method='post'> <table> <tr> <td valign='top'>SELECT</td> <td valign='top'> <table>"; // LIST ALL COLUMNS IN A TABLE $result = mysql_query("SELECT * FROM table_name") or die(mysql_error()); $rowcount=mysql_num_rows($result); $y=mysql_num_fields($result); for ($x=0; $x<$y; $x++) { echo " <tr> <td> <input type='checkbox' name='fields[]' value='".mysql_field_name($result, $x)."'>".mysql_field_name($result, $x)." </td> </tr>"; } echo " </table> </td> <td valign='top'>FROM allocations</td> <td valign='top'>WHERE</td> <td> <table>"; // LIST ALL COLUMNS IN A TABLE $result = mysql_query("SELECT * FROM table_name") or die(mysql_error()); $rowcount=mysql_num_rows($result); $y=mysql_num_fields($result); for ($x=0; $x<$y; $x++) { echo " <tr> <td> <input type='checkbox' name='column[]' value='".mysql_field_name($result, $x)."'>".mysql_field_name($result, $x)." </td> <td> <select name='operator[]'> <option value='='>equals</option> <option value='<>'>does not equal</option> <option value='>'>greater than</option> <option value='<'>less than</option> <option value='>='>greater than or equal to</option> <option value='<='>less than or equal to</option> <option value='LIKE'>is like</option> </select> </td> <td><input type='text' name='criteria[]'></td> </tr>"; } echo " </table> </td> <td valign='top'><input type='submit' value='Process Query' name='submit' class='submit'></td> </tr> </table> </form>"; } else { echo "<b>Fields to edit:</b> "; foreach ($_POST['fields'] as $fields) { echo $fields,", "; } echo "<br><br>"; echo "<b>Columns to query:</b> "; foreach ($_POST['column'] as $columns) { echo $columns," HERE IS THE SPOT, "; } } Hello Everyone, I have to change the if statements to a switch statement, in this game. Can anyone help? Thanks. var checkKeyPressed = function (e) { // Press key A or key D to make dog run to the left or right // The running speed is specified by the step variable, 10 by default. // If you replace 10 with a larger integer, the dog will run faster. //press A, dog runs left if (e.keyCode == "65") { if (prex[0] > 5) { prex[0] = prex[0] - step; } } //press D, dog runs right if (e.keyCode == "68") { if (prex[0] < right) { prex[0] = prex[0] + step; } } }; Hi All, I essentially am trying to figure out how to print out all of the zip codes that are associated with a search that I am doing, but not list the same zip code more than once. My current foreach statement is as follows and prints out the zip code for each property that is associated with the search: <ul> <?php foreach($properties as $property) { ?> <li><?=$property->$zipcode?></li> <?php } ?> </ul> How would I modify this to print out 1 occurrence of each zip code that is in the search, even if, for example 20 properties have the same zip code? Thanks in advance! P.S. - Tried using an array to work with it but pretty sure my logic was incorrect when putting it together and couldn't get past the errors. Anyways, thanks in advance for the help! |