Jump to content

digitalgod

Members
  • Posts

    374
  • Joined

  • Last visited

    Never

Everything posted by digitalgod

  1. hey guys, trying to make a drop down that displays the days of the week starting by today but if it's past 9:15pm it shows the next day. I was wondering if I do something like [code=php:0] date('h:i:s a') [/code]  would a user be able to "cheat" by changing the time on his taskbar? Also how can I set the time to Eastern time all the time no matter where the user is from?
  2. what I mean is that I have a couple of checkbox "groups" meaning a user could select one or more options for a given category but it has to be at least 1. so let's say in my form I have : Select favorite type of music :  and I give the user a choice between 5 types, they all have the same id (mtype[]) then I ask the user Select Alcohol type : I give the user a few choice, they all have the same id (alcohol[]) Now when he/she clicks on submit I want to be able to check whether there's at least 1 option that has been checked for mtype[], and also check if there's at least 1 option that has been checked for alcohol[]. but I can't seem to get it to work...
  3. ok tried doing this but it doesn't work either.... any ideas? [code] function checkAlcohol() { var elements = document.forms["form"].getElementsByName("alcohol[]"); for(var i=0; i < elements.length; i++){ if(elements[i].checked) { checked = true; } } if (!checked) { alert('You have to select at least one type of alcohol.'); } return checked; } [/code]
  4. I know how to validate a form and the id is an array (actually it becomes an array in my php file when it gets processed), when the form gets processed whatever has been checked is stored in the array. I'm just looking for a way to make sure that at least one checkbox has been checked. I'll google some more I guess
  5. hey guys, was just wondering how can I use javascript to check if a checkbox has been checked.. I have a few checkboxes and I need at least one of them to be checked before submitting the form. Since the name of the checboxes are an array I'm not sure what to do. here's a part of the form [code] <td>*Alcohol:</td>               <td><table border="0">                 <tr>                   <td><label>                     <input name="alcohol[]" type="checkbox" id="alcohol[]" value="beer">                   </label></td>                   <td>Beer</td>                 </tr>                 <tr>                   <td><label>                     <input name="alcohol[]" type="checkbox" id="alcohol[]" value="wine">                   </label></td>                   <td>Wine</td>                 </tr>                 <tr>                   <td><label>                     <input name="alcohol[]" type="checkbox" id="alcohol[]" value="mixed drinks">                   </label></td>                   <td>Mixed Drinks </td>                 </tr>                 <tr>                   <td><label>                     <input name="alcohol[]" type="checkbox" id="alcohol[]" value="martinis &amp; coktails">                   </label></td>                   <td>Martinis &amp; Coktails </td>                 </tr>                               </table></td> [/code] and here's what I have so far for the javascript [code] function checkAlcohol() {   var frm = document.forms["form"];   if (frm.alcohol[].checked == false )   {     alert('You must select at least one type of alcohol');     return false;   }   else   {     return true;   } } [/code] that function is called when a user presses submit but it's giving me errors when the pages load.
  6. well here I'll show you the form [code] <form action="admin.php?a=viewusers&action=validate" method="post" name="validate" id="validate"> <input type="hidden" name="process_b" value="yes"> <div style="margin-left:8px; margin-top:10px; margin-right:8px; height:1px; background-image:url(images/dot.jpg) "><img src="images/spacer.gif"></div> <?php if (!isset($_SESSION['custom_browse']) && !isset($_GET['action'])) { $browse = mysql_query("SELECT * FROM users WHERE level='2' ORDER BY id DESC") or die(query_error()); } if (isset($_SESSION['custom_browse']) && !isset($_GET['action'])) { $browse = $_SESSION['custom_browse']; } if (!isset($_SESSION['custom_browse']) && isset($_GET['action'])) { $browse = $_SESSION['all_validate']; } while ( $row = mysql_fetch_array($browse)) { echo ' <div style="margin-left:9px; margin-top:7px; width:354px "> <div>Username: <strong>'.$row['username'].'</strong></div> <div>Last Name: <strong>'.ucfirst($row['lname']).'</strong></div> <div>First Name: <strong>'.ucfirst($row['fname']).'</strong></div> <div>Age: <strong>'.age($row['date_birth']).'</strong></div> <div>Sexe: <strong>'.ucfirst($row['gender']).'</strong></div> <div>Location: <strong>'.$row['city'].'</strong></div> <div>Active: <strong>'.$row['active'].'</strong></div>'; if ($browse != $_SESSION['all_validate']) { echo '<div>Level of validation: <strong>'.$row['validation'].'</strong></div> <div style="margin-top:7px " align="right"><a href="#" class="light_gray" style="text-decoration:none "><strong>view profile </strong></a></div> </div> <div style="margin-left:8px; margin-top:10px; margin-right:8px; height:1px; background-image:url(images/dot.jpg) "><img src="images/spacer.gif"></div>'; } else { echo '<div>Level of validation: <select name="valid_lvl" id="valid_lvl" style="width:40px; height:12px; font-family:tahoma; font-size:10px; color:#9A400C "> <option>Choose one</option>'; foreach ($aValid as $val) { echo "<option value='$val'"; if ($val==$row['validation']) { echo " selected"; } echo ">".$val; } echo '</select> Validate: <input type="checkbox" name="validate[]" value="'.$row['id'].'"></div> <div style="margin-top:7px " align="right"><a href="#" class="light_gray" style="text-decoration:none "><strong>view profile </strong></a></div> </div> <div style="margin-left:8px; margin-top:10px; margin-right:8px; height:1px; background-image:url(images/dot.jpg) "><img src="images/spacer.gif"></div>';   } } echo '<div style="margin-top:10px"><input type="submit" name="Submit" value="Validate"></div>'; ?> </form> [/code] the reason I want a checkbox is because I don't want to validate everyone in 1 shot sorry about the formating but whenever I copy and paste from dreamweaver everything is weird
  7. well their default level is 0 but I want to be able to change that with a drop down but I want to be able to keep some users at level 0 so if the level is 0 in the drop down and I check validate it will "confirm" his level. Trying to make this as clear as possible... If I have a list of 100 users, I want to validate them by choosing the level and checking the checkbox next to the drop down, so if I select level 3 in the drop down and check the box it will update his level and add "true" to validated. so far this is what I have to process the form [code=php:0] $validate = $_POST['validate']; $num_array = count($validate); for ($i=0; $i < $num_array; $i++) { $query = "UPDATE " . $prefix . "users SET validation='$validation',validated='true' WHERE id = ".$validate[$i].""; $result = mysql_query($query) or die(query_error()); } [/code] what I'm missing is the $validation (which is the level)
  8. where $level would be the value of the drop down? I'm really not sure how to accomplish this, the values that have to be stored in the array would be the id of the user and the chosen level but those values are only stored if I checked "validate" so if I have 5 entries and I only select 3 of them the array would like Array (    [2] => 0    [4] => 3    [5] => 5 ) where the first part is the id number and the second part is the level.
  9. would using a 2d array work?? something like grabbing the id of what has been checked and the level at the same? not sure how to do it though
  10. all that just for 1 sign.... arrg lo the heat is getting to me. Thanks again ryanlwh works great so far
  11. sure this is what I got when I select between 18 and 22 SELECT * FROM users WHERE date_birth <= (NOW() - INTERVAL 18 YEAR) AND date_birth >= (NOW() - INTERVAL 21 YEAR) AND level='2' ORDER by id DESC so I'm guessing I should take off the -1 but then we'll back to the same old problem again...
  12. well I don't see what that will change, the level is whether the user is a superadmin, admin, user, etc but ok I'll give it a shot *edit* still gives me the same result
  13. thanks onlyican but how do I grab the value of the drop down at the same time, so if for one entry I choose level 3 in the drop down and check the validate checkbox, how do I associate that level to that id?
  14. still doesn't show any entries when selecting 22 - 22, works perfectly if I select different ages though..... *edit* actually no, if I do 18-23 it doesn't show me the entries that have 22....
  15. gives me this query... for some reason $v seems to disappear or something SELECT * FROM users WHERE date_birth <= (NOW() - INTERVAL 21 YEAR) AND -1 YEAR) AND level='2' ORDER by id DESC
  16. yeah my bad just fixed that a few seconds ago, but it still doesn't work if I still have to choose from 21 to 23 to get people that are 22, selecting 22 to 22 gives me nothing
  17. must be the heat ;) don't know about you but I'm cooking over here hehe hmm I don't get what you mean I switched it to this and I'm getting an error [code=php:0] case 'from': $qtmp[] = "date_birth <= (NOW() - INTERVAL " . $v . " YEAR) AND"; break; case 'to': $qtmp[] = "> (NOW() - INTERVAL " . $v . " YEAR) AND "; break; [/code]
  18. ok tha didn't work either, change my code to try your MySQL query but now it won't show me ny results [code] <select name="from" style="width:60px; height:17px; font-family:tahoma; font-size:10px; color:#9A400C "> <?php for ($i=18;$i <= 100;$i++) {    echo '<option value="'.$i.'">'.$i.'</option>'; } ?> </select> and <select name="to" style="width:60px; height:17px; font-family:tahoma; font-size:10px; color:#9A400C "> <?php for ($i=18;$i <= 100;$i++) {     echo '<option value="'.$i.'"';     if ($i==35) { echo " selected"; } echo '>'.$i.'</option>';      } ?> </select> [/code] and [code] <?php foreach($_POST as $k => $v) switch ($k) {       case 'from': $qtmp[] = "date_birth BETWEEN (NOW() - INTERVAL " . $v . " YEAR) AND"; break;       case 'to': $qtmp[] = "(NOW() - INTERVAL " . $v . " YEAR) AND "; break; } $query = "SELECT * FROM " . $prefix . "users " . implode(' ', $qtmp) . "level='2' ORDER by id DESC"; $_SESSION['custom_browse'] = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error()); ?> [/code] but you can be 22 and born in 1983 so it won't display you :P
  19. hey ryanlwh I don't think it's working properly (unless I'm doing something wrong) here's what I have (used your old code but I'll try again with MySQL) [code] <select name="from" style="width:60px; height:17px; font-family:tahoma; font-size:10px; color:#9A400C "> <?php for ($i=18;$i <= 100;$i++) {    $bDate = date('Y-m-d',strtotime("-$i year"));    echo '<option value="'.$bDate.'">'.$i.'</option>'; } ?> </select> and <select name="to" style="width:60px; height:17px; font-family:tahoma; font-size:10px; color:#9A400C "> <?php for ($i=18;$i <= 100;$i++) {    $bDate = date('Y-m-d',strtotime("-$i year"));     echo '<option value="'.$bDate.'"';     if ($i==35) { echo " selected"; } echo '>'.$i.'</option>';      } ?> </select> [/code] and the processing part [code] <?php // If I chose between the ages of 22 and 22 I get $qtmp = array();                    foreach($_POST as $k => $v)                    switch ($k) {                     case 'from': echo $v; //returns 1984-07-31  which is not right $qtmp[] = "date_birth <='" . $v . "' AND "; break; case 'to': echo $v; //returns 1984-07-31 which is not right $qtmp[] = "date_birth >='" . $v . "' AND "; break; } ?> [/code]
  20. thanks guys ryanlwh that worked perfectly with a few tweaks, was just wondering if you could explain it to me. I don't understand why you did -$age year *edit* just noticed your edit, I'm guessing that query is much faster right? And I need to search between 2 dates, so if I select between the ages of 18 and 35 the query has to look for everything >= 18 and <= 35
  21. If you want to close the connection you close it at the very end, because when you're updating a row you're still connected to the db.
  22. well that's what I have in my db, date_birth is in this format 2006-07-31 and I already have a function to calculate the age but I really don't know how to calculate the exact year depending on the current date. I have 2 drop downs, something like Select age between 1st drop down and 2nd drop down
×
×
  • 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.