Jump to content

akitchin

Staff Alumni
  • Posts

    2,515
  • Joined

  • Last visited

    Never

Posts posted by akitchin

  1. if you're trying to access the same index from the $_POST['descr'] array, you'll actually need to grab the index from the $_POST['staff'] array in your foreach():

     

    foreach ($_POST['staff'] AS $key => $val)
    {
      echo 'Staff: '.$value.'<br />';
      echo 'Description: '.$_POST['descr'][$key].'<br />';
    }

  2. not sure why you're using:

     

    ($val BETWEEN sqf_min AND sqf_max, $val2 BETWEEN price_min AND price_max);

     

    that breaks the MySQL syntax. try:

     

    SELECT * FROM buyer_listings
      WHERE acct_type='FHA' AND
      buyerCity='Hollywood' AND
      bedrooms>=1 AND
      baths>=1 AND
      $val BETWEEN sqf_min AND sqf_max AND
      $val2 BETWEEN price_min AND price_max

     

    if that doesn't work, you may need to specify the BETWEEN requirements separately (ie. sqf_min <= $val AND sqf_max >= $val).

     

    EDIT: beaten to the punch, leaving this on because i don't want to have wasted all this finger pressing

  3. that data looks correct, except that every value between the first and last has a trailing space. trim *should* take care of that. once you run trim() against all values in the array (array_map comes in handy here), you can simply concatenate all the values into one comma-delimited string and put that into a SINGLE query:

     

    $trimmed_version = array_map('trim', $name);
    $single_list = implode(',', $trimmed_version);
    $query = "SELECT stuff FROM table WHERE name_column IN ($single_list)";

     

    i would suspect that the actual error occurs when, at the end of the loop with the query in it, you assign:

     

    $name = $row[0];
    echo $name."<br />";

     

    that would reset the $name variable and kill the foreach() loop.

  4. for this you would need a simple PHP AJAX form validation script of some sort (jQuery's example is on their website). provided you can standardize the user's input, the PHP code to verify it should be simple:

     

    1. validate the actual format of the date (see here for a quick tutorial on how to write this part).

    2. convert the value to a timestamp using strtotime, and compare it against the current timestamp (using time).

  5. this isn't an easy answer, considering we have no idea what script(s) you're using and what code excerpts are being used for the pagination and display. however, my guess would be that you are limiting the query to grabbing 10 at a time. try changing that; if you don't where to do so, post the code for the pagination and we may be able to help.

  6. back to the ORIGINAL topic (not that i don't appreciate the enjoyable detour this thread took) - also be careful that the things that may be revealed in a rant or complaint could be information that can't be publicly disclosed, which they could use as grounds for dismissal (or worse - could contravene a signed agreement between you and your employer, potentially leading to litigation).

  7. haha oops - forgot to scroll down in the first post to see the rest of the code..

     

    anyhow, you're not far off the mark, you just have the mail_message() call in the wrong place. once the code you've gotten from the other thread runs, you're left with all your name/email pairs in $list. what you need to do is iterate through that list, and use mail_message() for every pair. furthermore, we can edit your mail_message() function to return a message indicating the result, rather than the name/email pair - you don't need to return the pair, since we already know what it is (we have to pass it to the function after all):

     

    <?php
    
    function mail_message ($name,$email,$template_file) {
        if (empty ($name) || empty($email) || empty($template_file)) {
            return "One or more fields are missing";
        }
    
        else {
    
            #echo "inside $name, $email<br/>";
            $email_message = file_get_contents($template_file);
            $email_message = str_replace("#NAME#", $name, $email_message);
    
            #construct the email headers
            $to = $email;
            $from = "webmaster@viaeterna.com";
            $email_subject = "Your invited to a party!";
    
            #now mail
            $mailing_result = mail($to, $email_subject, $email_message, "From: Party List Central ".$from);
    
            if ($mailing_result == TRUE)
              return 'Mailing successful!';
            else
              return 'Mailing failed.';
    
        }
    }
    
    
    $list = array();
    foreach ($_POST as $key => $value) {
        // is this a name?
        if (substr($key, 0, 4) == 'name') {
            $index = (int)substr($key, 4);
            $list[$index]['name'] = $value;
            $name = $value;
            # echo "$name<br/>";
        }
    
        // is this an email
        if (substr($key, 0, 5) == 'email') {
            $index = (int)substr($key, 5);
            $list[$index]['email'] = $value;
            $email = $value;
            # echo "$email<br/>";
        }
    
    
    
    
    }
    
    foreach ($list AS $key => $pair_array)
    {
            //DOCUMENT_ROOT is the file path leading up to the template name.
            $this_result = mail_message($pair_array['name'],$pair_array['email'],'./invite_text.txt');
            $list[$key]['result'] = $this_result;
    }
    
    
    echo '<pre>';
    print_r($list);
    echo '</pre>';
    
    ?>

     

    give that a whirl and see what you get. i'm not sure if this deviates from your assignment, but hopefully it helps you see what order to process the data in. if you're ever wondering what to do with the data you've got, echo all your variables and see what you've got to work with.

  8. can we see the script that's calling this function? i presume you're iterating through the array of names/emails (as per the other thread) and running this function each time? if so, it's likely that you're replacing the $sent array every time mail_message() is called. the tell-tale sign of this being the issue is that it only ever contains the information of the last person mailed at the end.

  9. first off, please PLEASE get quotes around those HTML attributes! it's begging for issues to get into the habit of not using them. second, where is $month coming from, and what format is it in? third, what does the HTML output look like? do you end up with several options that have " selected" at the end of the option tag?

  10. You can try something like this

     

    $countsql = "SELECT name FROM Table";
    
    if (mysql_num_rows($countsql))
      {
        echo "Name already in database!< \n";
      }

     

    .. i think you forgot the part of the query where you tell it WHAT name to pull out of the table. otherwise, it will simply return all names currently in the database.

     

    if (isset($_POST['Name']))
    {
      $query = "SELECT NameDB FROM Table WHERE NameDB='{$_POST['Name']}'";
      $resource = mysql_query($query);
      if ($result === FALSE)
      {
        echo 'Query failed: '.$query;
      }
      else
      {
        if (mysql_num_rows($resource) == 0)
          echo 'Name is not taken.';
        else
          echo 'Name is currently taken.';
      }
    }

     

    it is extremely wasteful of resources and time to pull every record from the database and iterate through them looking for a matching value - let MySQL do the legwork, and SELECT exactly what you're looking for.

×
×
  • 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.