SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 40
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP loop function help needed!

    Hello,
    I'm trying to get this code to work:
    PHP Code:
    $item_number="5161516161,784684664864684";

    $item_numbers explode(","$item_number);
    foreach (
    $item_numbers as &$item_number) {
    echo 
    "$item_number";

    I need it to split the 5161516161,784684664864684 and run " echo "$item_number"; " twice, one for each item number.

    So if $item_number="5161516161,784684664864684,15515151"; then the script is supposed to run " echo "$item_number"; " three times, one time for each item number.

    Please help, how can I do that? What is wrong with my code/how should it be?

    /Oskar

  2. #2
    SitePoint Guru Ize's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    809
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, the ampersand doesn't serve a purpose here (do $item_numer instead of &$item_number), but that shouldn't make a difference.

    What is the output you get? Do you receive any errors?

  3. #3
    SitePoint Zealot Darren Lewis's Avatar
    Join Date
    Jul 2002
    Location
    UK
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You've got a type on the last line. It sould be a closing brace } not a closing bracket )

    Other than that, it should work.
    Censura - Add reviews and ratings to your site

  4. #4
    SitePoint Enthusiast snarzom's Avatar
    Join Date
    Jan 2007
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have a simular problem, with the below recordset, how do i split the data from postcode eg 0800,0801

    PHP Code:
    <? 
                        $postcodes 
    $row_Recordset1['postcode'];
    $postcodes explode(","$postcode);
    foreach (
    $postcodes as $postcode) {
    echo 
    "$postcode";
    }
    ?>

  5. #5
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    Hi snarzom,
    PHP Code:
    $postcodes explode(","$row_Recordset1['postcode']);
    foreach (
    $postcodes as $postcode) {
    echo 
    "$postcode";

    you are assigning $postcodes to the row variable but exloding $postcode which doesn't exist.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  6. #6
    SitePoint Enthusiast snarzom's Avatar
    Join Date
    Jan 2007
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i changed to below, nothing appears.
    PHP Code:
        $postcode $row_Recordset1['postcode'];
    $postcode explode(","$postcode);
    foreach (
    $postcode as $postcode) {
    echo 
    "$postcode";


  7. #7
    SitePoint Enthusiast snarzom's Avatar
    Join Date
    Jan 2007
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if i only have one number in $row_Recordset1['postcode'] it appears, if i have two nothing appears, im inserting like 0800,0810

  8. #8
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    It appears that because you are using the same variable name for different things in the script, it overwrites the previous variable.

    Run the following:
    PHP Code:
    $postcode $row_Recordset1['postcode'];
    #$postcode_in = "0800,0810";
    $postcode explode(","$postcode_in);
    foreach (
    $postcode as $postcode_out) {
        echo 
    $postcode_out .'<br />';
    }
    print_r($postcode); 
    see what happens.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  9. #9
    SitePoint Enthusiast snarzom's Avatar
    Join Date
    Jan 2007
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nothing happened, this has been puzzling me for a few days, any help from anyone would be great.
    Last edited by snarzom; Apr 17, 2007 at 04:40.

  10. #10
    SitePoint Zealot Darren Lewis's Avatar
    Join Date
    Jul 2002
    Location
    UK
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should work

    PHP Code:
    // Test populate the array
    $row_Recordset1 = array(
        
    "postcode" => "0800,0801"
    );

    $postcodes explode(","$row_Recordset1['postcode']);

    foreach (
    $postcodes as $postcode) {
        echo 
    $postcode .'<br />';

    Censura - Add reviews and ratings to your site

  11. #11
    SitePoint Enthusiast snarzom's Avatar
    Join Date
    Jan 2007
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tried that, no luck..the post code may vary, not always 0800, 0810, this will change depending what the admin allows them to view. by post code. if i can explain what im after.
    In the admin they imput a admin user with username password and a field postcode. in the postcode field it may be what ever there post code is plus another on or two. this then sorts what the user imputs in a form so the admin user can view his/her allocated postcodes, hope you get my drift.

  12. #12
    SitePoint Zealot Darren Lewis's Avatar
    Join Date
    Jul 2002
    Location
    UK
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the code isn't working, it looks like the issue is with $row_Recordset1['postcode'] that your are passing to the loop.

    The loop itself works, but it's relying on $row_Recordset1['postcode']

    Try
    PHP Code:
    print_r($row_Recordset1['postcode']);
    exit(); 
    before the loop and see what that outputs.
    Censura - Add reviews and ratings to your site

  13. #13
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Quote Originally Posted by spikeZ View Post
    It appears that because you are using the same variable name for different things in the script, it overwrites the previous variable.

    Run the following:
    PHP Code:
    #$postcode = $row_Recordset1['postcode'];
    $postcode_in "0800,0810";
    $postcode explode(","$postcode_in);
    foreach (
    $postcode as $postcode_out) {
        echo 
    $postcode_out .'<br />';
    }
    print_r($postcode); 
    see what happens.
    I tried this i am getting the result as

    0800
    0810
    Array ( [0] => 0800 [1] => 0810 )

    snarzom,are u looking 4 this result

    bye

  14. #14
    SitePoint Enthusiast snarzom's Avatar
    Join Date
    Jan 2007
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    kind of, i have a list of results, with name address post code, i want only certain people to view postcodes that the admin has assigned them. so example.
    i i give you access to post code 1234, 9876 but in the database there are results with the postcodes 0898 and 7777 etc, you can only view the rows with the postcodes i have allowed you to see (1234, 9876)

  15. #15
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    what you have to do here create a filed in the db and create any flags,based on that flag display the result

  16. #16
    SitePoint Enthusiast snarzom's Avatar
    Join Date
    Jan 2007
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have this query and session which works for one postcode entered into the postcode text field, what i need is, if i enter a second or third how do i get it to show. in the rows.

    Code:
    " SELECT `user`.username, `user`.postcode, `form`.userID, `form`.added_by, `form`.email, `form`.phone, `form`.mobile, `form`.address, `form`.suburb, `form`.postcode, `form`.`state`, `form`.`datetime` FROM `user` inner join `form` on `user`.postcode = `form`.postcode WHERE `user`.username = '".$HTTP_SESSION_VARS['usersession']."'ORDER BY userID DESC";

  17. #17
    SitePoint Enthusiast snarzom's Avatar
    Join Date
    Jan 2007
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    below is what the list looks like, but i want to show if i want them to also have listed people with a different post code not just 0870

    here is what i want it to look like
    Records 1 to 30 of 56
    Lead ID Name Submitted Suburb Post Code
    Delete
    #151
    Corinna 09-Apr-2007 10:31 pm Springs 0870


    #142
    Angela 02-Apr-2007 12:17 pm sydney 2001


    #139
    Mathew 30-Mar-2007 11:58 am Springs 0870


    #137
    Carlo De 29-Mar-2007 12:01 pm Springs 0870
    Last edited by snarzom; Apr 17, 2007 at 17:07.

  18. #18
    SitePoint Enthusiast snarzom's Avatar
    Join Date
    Jan 2007
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can someone help me on this one.. i hate to be a pain in the #$&#37;$#

  19. #19
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    Morning snarzom,

    After the query has done it's thing, what code do you have to loop through the results?

    Do you have something like:

    PHP Code:
    while($row_Recordset1 mysql_fetch_assoc($query)) {
    // results

    If you are using Dreamweaver it may be a do{ }while loop.

    Post the code you have for the results display.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  20. #20
    SitePoint Enthusiast snarzom's Avatar
    Join Date
    Jan 2007
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <?php do { ?>
                      <?php if ($totalRows_Recordset1 > 0) { // Show if recordset not empty ?>
                      <tr valign="middle" bgcolor="#FFFFCC">
                        <td width="40"><div align="center">#<?php echo $row_Recordset1['userID']; ?></div></td>
                        <td><a href="detail.php?userID=<?php echo $row_Recordset1['userID']; ?>"> <span class="textLink"><?php echo ucwords($row_Recordset1['added_by']); ?></span></a></td>
                        <td><?php echo $row_Recordset1['datetime']; ?></td>
                        <td width="121"><?php echo ucwords($row_Recordset1['suburb']); ?></td>
                        <td width="60"><?php 
    					#$postcode = $row_Recordset1['postcode'];
    $postcode_in = "$row Recordset1[postcode]";
    $postcode = explode(",", $postcode_in);
    foreach ($postcode as $postcode_out) {
        echo $postcode_out .'<br />';
    }
    print_r($postcode); 
     ?></td>
                        <td><div align="center" class="textLink"><a href="reply.php?userID=<?php echo $row_Recordset1['userID']; ?>">Respond</a></div></td>
                        <td><div align="center"><a href="javascript:BRB_PHP_DelWithCon('delete.php','userID',<?php echo $row_Recordset1['userID']; ?>,'Are you sure you want to delete this record?');"><img src="../images/cancel_f2.png" width="24" height="24" border="0" /></a></div></td>
                      </tr>
                      <?php } // Show if recordset not empty ?>
                      <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
                    </table>

  21. #21
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    just a a quick one, you have a typo in you explode part....
    PHP Code:
    $postcode_in "$row Recordset1[postcode]"
    should be:
    PHP Code:
    $postcode_in $row_Recordset1['postcode']; 
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  22. #22
    SitePoint Enthusiast snarzom's Avatar
    Join Date
    Jan 2007
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    changed that, still no change, i will post the whole page for you to look at.
    Code:
    <?php
    // Buzz inet PHPLS03 - Check User Session is set
    session_start();
    if(!isset($HTTP_SESSION_VARS['usersession'])){
    	header("Location: ../login.php");
    
    session_destroy();
    
    $message="";
    }
    ?><?php require_once('../Connections/conn_fra.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
    
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
    
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }
    
    $currentPage = $_SERVER["PHP_SELF"];
    
    $maxRows_Recordset1 = 30;
    $pageNum_Recordset1 = 0;
    if (isset($_GET['pageNum_Recordset1'])) {
      $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
    }
    $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
    
    mysql_select_db($database_conn_fra, $conn_fra);
    $query_Recordset1 = " SELECT `user`.username, `user`.postcode, `form`.userID, `form`.added_by, `form`.email, `form`.phone, `form`.mobile, `form`.address, `form`.suburb, `form`.postcode, `form`.`state`, `form`.`datetime` FROM `user` inner join `form` on `user`.postcode = `form`.postcode WHERE `user`.username = '".$HTTP_SESSION_VARS['usersession']."'ORDER BY userID DESC";
    $query_limit_Recordset1 = sprintf("&#37;s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
    $Recordset1 = mysql_query($query_limit_Recordset1, $conn_fra) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    
    if (isset($_GET['totalRows_Recordset1'])) {
      $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
    } else {
      $all_Recordset1 = mysql_query($query_Recordset1);
      $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
    }
    $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
    
    mysql_select_db($database_conn_fra, $conn_fra);
    $query_Recordset2 = "SELECT * FROM news";
    $Recordset2 = mysql_query($query_Recordset2, $conn_fra) or die(mysql_error());
    $row_Recordset2 = mysql_fetch_assoc($Recordset2);
    $totalRows_Recordset2 = mysql_num_rows($Recordset2);
    
    $queryString_Recordset1 = "";
    if (!empty($_SERVER['QUERY_STRING'])) {
      $params = explode("&", $_SERVER['QUERY_STRING']);
      $newParams = array();
      foreach ($params as $param) {
        if (stristr($param, "pageNum_Recordset1") == false && 
            stristr($param, "totalRows_Recordset1") == false) {
          array_push($newParams, $param);
        }
      }
      if (count($newParams) != 0) {
        $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
      }
    }
    $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
    ?>
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function BRB_PHP_DelWithCon(deletepage_url,field_name,field_value,messagetext) { //v1.0 - Deletes a record with confirmation
      if (confirm(messagetext)==1){
      	location.href = eval('\"'+deletepage_url+'?'+field_name+'='+field_value+'\"');
      }
    }
    //-->
    </script>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/admin.dwt.php" codeOutsideHTMLIsLocked="false" -->
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>Administration</title>
    <!-- InstanceEndEditable -->
    <!-- InstanceBeginEditable name="head" -->
    <link href="../css.css" rel="stylesheet" type="text/css" /><!-- InstanceEndEditable -->
    <link href="../css.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
    <!--
    body {
    	background-color: #CCCCCC;
    }
    -->
    </style></head>
    
    <body>
    <table width="20" border="0" align="center" cellpadding="3" cellspacing="0">
      <tr>
        <td><table width="872" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
          <tr>
            <td width="91"><img src="images/logo.gif" width="600" height="127" /></td>
            <td width="22">&nbsp;</td>
          </tr>
          <tr>
            <td colspan="2"><table width="861" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td colspan="5"><div align="right" class="BlueWhiteHeader">ADMINISTRATION </div></td>
                  </tr>
                <tr>
                  <td colspan="2">&nbsp;</td>
                  <td width="598" class="text">Hello <strong><? echo $_SESSION['usersession']; ?>! </strong>You are now Logged in. </td>
                  <td colspan="2" class="text"><div align="right"><a href="../default.php" class="textLink">Logout</a></div></td>
                  </tr>
                <tr>
                  <td width="118" valign="top"><p><a href="default.php" class="textLink">Home</a></p>
                    <p>Archieves</p>
                    <p><a href="contact_us.php" class="textLink">Contact Us</a></p></td>
                  <td width="4">&nbsp;</td>
                  <td colspan="3"><!-- InstanceBeginEditable name="body" -->
                    <table width="730" border="0" align="center" class="text">
                      <tr>
                        <td colspan="6" valign="top"><p><br />
                          Welcome to the your administration area.</p>
                            <p>View the list of leads below. Select there name to view details. </p>
                          <p>
                              <?php if ($totalRows_Recordset2 > 0) { // Show if recordset not empty ?>
                              <strong>Important News: </strong><br />
                              <?php echo nl2br($row_Recordset2['news']); ?>
                              <?php } // Show if recordset not empty ?>
                          </p>
                          <p>&nbsp;</p></td>
                        <td valign="top">&nbsp;</td>
                      </tr>
                      <tr>
                        <td colspan="6" valign="top"><em><strong>List of New Leads </strong></em></td>
                        <td valign="top">&nbsp;</td>
                      </tr>
                      <tr>
                        <td colspan="7">Records <?php echo ($startRow_Recordset1 + 1) ?> to <?php echo min($startRow_Recordset1 + $maxRows_Recordset1, $totalRows_Recordset1) ?> of <?php echo $totalRows_Recordset1 ?> </td>
                      </tr>
                      <tr bgcolor="#FF9900">
                        <td width="40"><strong>Lead ID</strong></td>
                        <td width="138"><strong>Name</strong></td>
                        <td width="132"><strong>Submitted</strong></td>
                        <td width="121"><strong>Suburb</strong></td>
                        <td width="60"><strong>Post Code</strong> </td>
                        <td width="49">&nbsp;</td>
                        <td width="42"><div align="center"><strong>Delete</strong></div></td>
                      </tr>
                      <?php do { ?>
                      <?php if ($totalRows_Recordset1 > 0) { // Show if recordset not empty ?>
                      <tr valign="middle" bgcolor="#FFFFCC">
                        <td width="40"><div align="center">#<?php echo $row_Recordset1['userID']; ?></div></td>
                        <td><a href="detail.php?userID=<?php echo $row_Recordset1['userID']; ?>"> <span class="textLink"><?php echo ucwords($row_Recordset1['added_by']); ?></span></a></td>
                        <td><?php echo $row_Recordset1['datetime']; ?></td>
                        <td width="121"><?php echo ucwords($row_Recordset1['suburb']); ?></td>
                        <td width="60"><?php 
    					#$postcode = $row_Recordset1['postcode'];
    $postcode_in = $row_Recordset1['postcode']; 
    $postcode = explode(",", $postcode_in);
    foreach ($postcode as $postcode_out) {
        echo $postcode_out .'<br />';
    }
    print_r($postcode); 
     ?></td>
                        <td><div align="center" class="textLink"><a href="reply.php?userID=<?php echo $row_Recordset1['userID']; ?>">Respond</a></div></td>
                        <td><div align="center"><a href="javascript:BRB_PHP_DelWithCon('delete.php','userID',<?php echo $row_Recordset1['userID']; ?>,'Are you sure you want to delete this record?');"><img src="../images/cancel_f2.png" width="24" height="24" border="0" /></a></div></td>
                      </tr>
                      <?php } // Show if recordset not empty ?>
                      <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
                    </table>
                    <br>
            <table border="0" width="50%" align="center">
              <tr>
                <td width="23%" align="center"><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
                      <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>" class="textLink">First</a>
                      <?php } // Show if not first page ?>            </td>
                <td width="31%" align="center"><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
                      <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>" class="textLink">Previous</a>
                      <?php } // Show if not first page ?>            </td>
                <td width="23%" align="center"><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
                      <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>" class="textLink">Next</a>
                      <?php } // Show if not last page ?>            </td>
                <td width="23%" align="center"><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
                      <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>" class="textLink">Last</a>
                      <?php } // Show if not last page ?>				  </td>
              </tr>
            </table>
            <!-- InstanceEndEditable --></td>
                  </tr>
                <tr>
                  <td colspan="2">&nbsp;</td>
                  <td colspan="2">&nbsp;</td>
                  <td width="103">&nbsp;</td>
                </tr>
            </table></td>
          </tr>
          <tr>
            <td colspan="2" bgcolor="#EEEEEE"><div align="center" class="text">&copy; Free Realestate Appraisals 2007 </div></td>
            </tr>
        </table></td>
      </tr>
    </table>
    </body>
    <!-- InstanceEnd --></html>
    <?php
    mysql_free_result($Recordset1);
    
    mysql_free_result($Recordset2);
    ?>

  23. #23
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    Ta, can I just check....
    in the postcode field the data would look something like:
    0199,8334,4544
    ......
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  24. #24
    SitePoint Enthusiast snarzom's Avatar
    Join Date
    Jan 2007
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, in the list of people it needs to show all people from a selected postcode/s. so if i allow you to view people with the post code of say 0810,0900,2000 you can only see those people in the database who fall under these postcodes.

  25. #25
    SitePoint Wizard TheRedDevil's Avatar
    Join Date
    Sep 2004
    Location
    Norway
    Posts
    1,190
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ize View Post
    Well, the ampersand doesn't serve a purpose here (do $item_numer instead of &$item_number), but that shouldn't make a difference.
    If he is running php 5 the ampersand keep the foreach from creating a new copy of the content of "$item_numner". So it has a purpose, imo a very importent purpose as it keeps your memory use down while keeping the speed of the foreach.

    In php 4, you should in general not use foreach on large arrays, but instead while (list($key, $value) = each($array)) {}
    Foreach will always create another copy of the array in php 4, but it is a few ms faster than a while loop, but on large arrays you will get a "Allowed Memory Size Exceeded" if the memory size has not been increased. Hence unless your certain the array will always stay around the same size, it is best to use a while loop


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •