Jump to content

dtyson2000

Members
  • Posts

    93
  • Joined

  • Last visited

Posts posted by dtyson2000

  1. Thank you for your response. In the last thread, I did exactly as it seemed I was being told. Removed the delimited list of values and threw them up in columns (as mentioned above) in an almost excel sort of format. Item 1, Item 2, Item 3, under which I simply added a value of T where applicable. Each ROW consists of an id, a name, a date, item 1, item 2, item 3... again with the last three having either a null value or a value of T (which, yes, I will change to a boolean type). 

     

    I'm just not sure where I'm going wrong and REALLY want to be up to speed. Your response points me in a direction. But I'm just not sure how what I'm doing is not storing each piece of data in a row?

    id  |  name  |  date  |  item1  |  item2  |  item3
    1      dave    Y-m-d       T         NULL    NULL
    2      Ann     Y-m-d       NULL      T       NULL
    
    etc.
    
  2. Hello. Just a quick question about using a loop to create a string from post variables that will then be used in a query.

     

    I have several post variables submitted in a form, some of which contain a value of T. Others are not selected. In the database there are several columns which may contain values of T or may not. I would like to construct a query that searches for specific columns containing T and ignoring the rest. I'm using WHERE "T" IN(colnames). I need to get the column names into a comma separated string. Here's what I'm using:

    $postVal = array("1", "2", "3", "4", "5");
    		foreach ($postVal as $key=>$val){
    			$newVar = “col”.$val;
    	
    			if ($$newVar == "T") {
    				*create/add to comma-separated string
    				}
    				else {
    				*ignore
    				}
    			}
    

    I hope that seems clear enough. I'm just not sure if I'm on the right track or not. What do you think? Thank you, in advance!

  3. I hope “columns” actually means rows. If you've added a column for each element of the list, that's just as bad as stuffing comma-separated values into a VARCHAR attribute.

     

     

    Well. Yes. I meant columns. Each column represents, say, an item. Each person can select one item or a combination of items but only one of each. Those items will not change. Is it bad form to make them columns in this way?

    ID |NAMELAST |NAMEFIRST |1 |2 |3 |4 |5 |A
    1  |DOE	     |JOHN	|1 |  |1 |1 |  |	
    2  |DOE	     |JANE	|  |1 |1 |  |  |1
    3  |DOE	     |SALLY	|1 |1 |  |  |1 |
    
    

    I know it's not php help so if it's more appropriate to have the discussion elsewhere, I'm good with that. Thanks for your insight!

  4. Yep. That was it. Thank you! I found the white-space and everything works as needed. 

     

    I am interested in your comment on doing it as a separate row in the table for each checkbox. Is this a speed concern, just bad form, or something else?

  5. I have the following in a form that edits values already put into a dbase.

    $alev = array(1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => 'AP');
    $dblev = explode(',',$row['hw_lev']);
    
    foreach ($alev as $key => $lev){
    	if(in_array($lev,$dblev)){
    		echo "<input type='checkbox' name='ud_lev[]' value='$lev' checked> $lev";
    		}
    		else {
    			echo "<input type='checkbox' name='ud_lev[]' value='$lev'> $lev";
    			}
    
    
    When I attempt to edit the dbase values, the following occurs:
     
    • When I select the "A" checkbox, it is input into the database and reflects in the results. When I attempt to edit this, the "A" box is checked and all is well.
     
    • When I select anything else AND "A" ("1", "A"), it is input into the database and reflects in the results. When I attempt to edit this, the "1" box is checked but the "A" box is NOT checked. This is what I need. 
     

     

    I feel like the problem is with the array? But it could be the loop.. :) Probably something totally staring me in the face. You know how it goes. I was wondering if you see a problem in the array or in the loop. Any thoughts would be appreciated!
  6. That's the ticket. I swear I tried something similar but messed something up. I think it was the [$i] in the echo. I think I recall doing it but just putting , which threw an error of course. Then I became so "cornfused" that I tried 17 different things before asking. Thank you so much for your time and for enlightening me!

  7. Hello. I have a simple SQL query that returns a list of names, this is good and all is right with the world. I would like to associate a number with each person, a RANDOM number that will change each time I call the page. Desired result:

     

    Number      |      Name

    18               |      Jeff

    2                 |      Tammy

    12               |      Steve

    10               |      Phil

    5                 |      Michelle

     

    etc. etc.

     

    Pool of numbers will be from 1 to 30. Sometimes the names pool will result in 18 rows or 27 rows or any number in between. I just need to assign a number from 1 to 30 to each name that is not the same each time. Here's my loop.

    while ($row= mysql_fetch_array($result)) {
    	$lastname = $row["lastname"];
    	$firstname = $row["firstname"];
    
    	$numbers = range(1, 30);
    	shuffle($numbers);
    	foreach ($numbers as $number) {
    	}
    
    echo "<tr>
    		<td class='results'>$number</td>
    		<td class='results'>$firstname $lastname</td>
    	</tr>";
    }
    

    Here's the problem I'm encountering:

     

    1) If I leave the FOREACH inside the loop, I wind up with one or two repeated $number(s).

    2) If I take the FOREACH outside the loop, I wind up with the first integer from the $numbers range repeated as many times as there are names

     

    I'm just not sure how to achieve a unique designation for each name.

     

    Could someone point me in the right direction? Thanks so much!

     

     

  8. $d = new DateTime();
    $inc = new DateInterval('P1D');
    $dateOptions = '';
    $required = array(1,2,4);
    for ($i=0; $i<28; ++$i) {
    $d = $d->add($inc);
    if (in_array($d->format('w'), $required)) {
     $v = $d->format('Y-m-d');
     $t = $d->format('Y-m-d D');
     $dateOptions .= "<option value='$v'>$t</option>\n";
    }
    }
    ?>
    <select name="date">
    <option value=''>-select date-</option>
    <?php echo $dateOptions ?>
    </select>

     

    Wow. This is exactly it. I didn't expect you to write the code entirely but thank you! I'll definitely look at it and learn from it! Thanks, again!

  9. I think you're making this a bit more complicated than what it needs to be, by involving multiple loops.

    Also, the reason you're getting the mondays in multiple drop-down menus, is because you've told PHP to repeat all of the HTML code. If you want only one drop-down then you'll need to move the select tags out of the loop. (Remove the br tag too and replace it with a closing option tag.)

    As for adding the other days to the mix: Why not just copy the line that produces the mondays, and change it to read "tuesday" and "wednesday" instead? ;)

     

    Thanks for the direction! I've done just what you said and all dates have been moved to the pulldown; however, the loop runs through each "day producing line" and the dates wind up out of order:

     

    
    echo "<select>";
    echo "<option>SELECT A DAY</option>";
    for($i=1; $i<=4; $i++){
    echo "<option>".date("Y-m-d", strtotime('+'.$i.' Monday'))."</option>";
    echo "<option>".date("Y-m-d", strtotime('+'.$i.' Tuesday'))."</option>";
    echo "<option>".date("Y-m-d", strtotime('+'.$i.' Thursday'))."</option>";
    }
    echo "</select>";
    
    Produces:
    
    2013-02-11
    2013-02-12
    2013-02-07
    2013-02-18
    2013-02-19
    2013-02-14
    2013-02-25
    2013-02-26
    2013-02-21
    2013-03-04
    2013-03-05
    2013-02-28
    

     

    Any thoughts or further direction on how to get the dates into order?

  10. Hello...

     

    I'm trying to calculate the next four Mondays, Tuesdays and Thursdays and stick each result in a select statement. So far, the best I have gotten is each date for Monday in four separate pulldowns:

     

    for($i=1; $i<=4; $i++){
    echo "<select><option>";
    echo date("Y-m-d", strtotime('+'.$i.' Monday')).'<br>';
    echo "</select>";
    }
    

     

    I guess the question is twofold. How do I get all of the dates in one pulldown and should I do three separate FOR statements to do it?

     

    Thanks, in advance!

  11. Hello all.

     

    I have this query:

     

    SELECT userid, namelast, namefirst, userpaid
    (SELECT COUNT(*) 
       FROM login 
       WHERE YEARWEEK(logindate) = YEARWEEK(CURDATE()) 
       AND login.luserid = users.userid) 
       AS wklogins, 
    (SELECT COUNT(*) 
       FROM login 
       WHERE YEAR(logindate) = YEAR(CURDATE()) AND MONTH(logindate) = MONTH(CURDATE()) 
       AND login.luserid = users.userid) 
       AS mologins 
    FROM users 
    LEFT OUTER JOIN login ON users.userid = login.luserid AND !(login.logindate < CURDATE()) 
    LEFT OUTER JOIN payments ON users.userid = payments.puserid 
    WHERE ((DATE(login.logindate) != CURDATE()) || login.luserid IS NULL) && (users.userpaid = 'T') 
    ORDER BY users.namelast, users.namefirst
    

     

    For some reason, which I can't seem to find, the joins don't seem to be happening. I definitely know that I'm getting the desired results from the primary and subqueries but I am not seeing anything joined to the resulting dataset. Do you see something wrong with this query? If you do, can you point me in the direction I need to go to fixing it? Thank you, in advance, for your help!

  12. Happy New Year, phpfreaks!

     

    So I have a client that basically wants to see how many times THIS week (always in the present) his users are logging in. There's no real need to store any data. He just wants to see a current number for the current week he happens to be checking it in. So for a short time every week (starting at midnight Mondays) the counts will reset.

     

    I haven't moved beyond the "thinking about it" phase yet and before I do I wanted to check with you to see if my thoughts make sense. Here's how I see it playing out:

     

    1) obtain and set a variable for the current week of the year.

    2) query database and count login dates (YYYY-MM-DD) that fall in that week per userid.

    3) output user names and the number.

     

    Do you see any real hurdles here with comparing the login dates to the week number? And do those three steps seem to be in line with what most of you would do?

     

    Thanks for reading!

  13. How would you go about doing logging or auditing with two versions of the same user? Why does your client want one username but two users? Why are people sharing usernames to begin with? This whole thing sounds like an unreasonable client asking for something dumb. They pay you to be smart with computers. Tell them when their idea is stupid.

     

    And THIS is the solution...really. You're totally right!

  14. I have a quick question...

     

    Does it sound reasonable to provide a login form that uses a login name and password where the user enters his/her login name but then has a choice to use one of two passwords.

     

    One password would provide access to certain areas of the site while the other password would be limited to a specific page. Client wants to use one username but only allow certain people limited access.

     

    Is there a resource that you can point me to or a quick suggestion for a solution?

     

    Thanks so much for taking the time to read!

  15. Hello. I'm having trouble wrapping my head around this issue and wonder if anybody could suggest a direction I could take.

     

    I've got a function that grabs some preference data from a prefs table (a string that is exploded into an array). Once the string is exploded, I run it through a loop to output the options for an html select tag.

     

    I would like to compare an existing field from another table with the items in the exploded array and if there's a match mark that option as "selected"

     

    I currently have:

    $package = $row['package'];
    
    		$packages = explode(',',$prefs_pack);
    
    		foreach($packages as $pack) {
    			$packages .= '<option value="' . $pack . '">' . $pack . '</option>';
    			}
    		return $packages;	
    

     

    The $package row comes from the other table fine. The question is where should I put the comparison and what method would you use? Should I throw a switch into the foreach loop? The $packages explosion produces 5 items in the array. So I need to compare $package (from the other table) to those 5 items and then stick "selected" for the item that matches into that option tag.

     

    Any thoughts?

     

    Thanks, in advance, I really appreciate the suggestions!

  16. Ever have one of those days when you've looked and looked and tried and tried, yet everything has become totally jumbled and backwards and the obvious answer to a problem, which is probably staring you right in the face but you just don't see it? Yeah, that's me today/yesterday...

     

    I've been using this script (all one file... no separate form/processing files) for a year and everything has worked without a problem --- until I noticed that session_register() was deprecated and I made the changes necessary to no longer use it.

     

    I am getting a "Cannot modify header information - headers already sent" error, which I understand but I canNOT get past it since the addition of the isset($_SESSION condition.

     

    I need this script to check the date and depending on the last login date in the table either show a full list or a partial list. Then, once the user has clicked their name, insert their name and the time into a table, which is immediately followed by a "header: location" to avoid duplicate entries should someone click the reload button and to show who has not clicked their name yet today. The script isn't making it by that line since the addition of the isset($_SESSION condition.

     

    The insert into the database happens but I immediately get the "header already sent" error as a result and I no longer get the list of names that should be returned. Can someone please have a look at this and maybe offer some guidance explaining where I might put the "header: location" to get that reload to work without throwing the error?

     

    This is killing me.  :confused: And thank you so much for taking the time to think about it!

     

    Here's a sanitized version of the code:

     

    
    <?php 
    session_start();
    if(isset($_SESSION['login']) && isset($_SESSION['password'])) {
    
    	include ('header.php');
    
    	echo "<p>logged in as: ". $_SESSION['login'];	
    
    	checkdate();
    
    	include ('footer.php');
    
    	}
    
    	else {
    
    		header("location: login.php");
    
    		}
    
    function checkdate() {
    
    // check current date
    
    include ('config.php');
    include ('opendb.php');
    
    $today = date('Y-m-d');
    
    $query = "SELECT * FROM datetable DESC limit 1";
    
    $result = mysql_query($query) or die ("Couldn't execute query");
    
    while ($row= mysql_fetch_array($result)) {
    
    	$date = $row["date"];		
    
    	switch(TRUE) {
    
    		case ($date == $today) :
    
    			if ($_SERVER['REQUEST_METHOD'] == "POST") {
    
    				$userid = mysql_real_escape_string($_POST["userid"]);					
    
    				mysql_query ("INSERT INTO datetable (userid, date) VALUES ('$userid', DATE_ADD(NOW(), INTERVAL 1 HOUR))");
    
    				header("location: index.php");
    
    			}
    
    			else {
    
    			userlogin();
    
    			}
    			break;
    
    		case ($date != $today) :
    
    			if ($_SERVER['REQUEST_METHOD'] == "POST") {
    
    				$userid = mysql_real_escape_string($_POST["userid"]);
    
    				mysql_query ("INSERT INTO datetable (userid, date) VALUES ('$userid', DATE_ADD(NOW(), INTERVAL 1 HOUR))");
    
    				header("location: index.php");
    
    			}
    
    			else {
    
    			userlist();
    
    			}
    
    			break;
    	}
    }
    }
    
    function userlist() {
    //	form that shows all users
    }
    
    function userlogin() {
    //	another form that shows only users who haven't logged in today
    }
    ?>
    
    
    

  17. Wow that wasn't bad. I actually just used the $string[0] to get the first letter of the last name and wrapped it in (a name='$string[0]') then stuck the links at the top of the list as hrefs. All fixed. Much Ado about Nothing! ;-)

  18. Aside from the basic query and output, no I haven't started because I'm not sure how to go about analyzing each result (well I guess I can figure that part out) and then limit the action needed (the insertion of a string of html) to just the first instance of the letter A, then B, etc.

     

    Sorry this may sound vague.

  19. Afternoon!

     

    This is probably something very straightforward but I haven't been able to locate a resource. I have a list of names and would like to provide a set of links (alphabet at the top of the list) to the first instance of a last name starting with that letter. The (a href='#s') jumping to (a name='s') isn't the issue. Grabbing the names from the database and dynamically grabbing the first instance of a last name that starts with the next letter and inserting the 'a name=' tag is.

     

    Is there a resource for this anywhere that you can point me to?

     

    Thanks, ahead of time!

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