Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

1 Neutral

About dtyson2000

  • Rank
    Regular Member

Profile Information

  • Gender
    Not Telling
  1. dtyson2000

    Using Loop to Create String from Post Variables

    Ok. I need to wrap my head around this. Thank you very much for pointing me in the right direction. I really had no idea. I've always done it the way I've always done it. I guess it's time for a change - and to start reading! Thank you, again!
  2. dtyson2000

    Using Loop to Create String from Post Variables

    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.
  3. 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!
  4. dtyson2000

    Array Question (Issue)...

    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!
  5. dtyson2000

    Array Question (Issue)...

    Advice taken. I switched it to columns. Makes more sense and a whole lot easier! Thanks!
  6. dtyson2000

    Array Question (Issue)...

    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?
  7. dtyson2000

    Array Question (Issue)...

    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!
  8. dtyson2000

    To Loop or not to Loop?

    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!
  9. dtyson2000

    To Loop or not to Loop?

    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!

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.