Jump to content

dmacman

Members
  • Posts

    39
  • Joined

  • Last visited

    Never

Everything posted by dmacman

  1. You are correct, I was not aware that it would do that, and now that you explained it, of course it makes sense. I changed it to: SELECT voters.VotersID, ballots.VotersID, voters.EmailAddress, ballots.BallotID, ratings2.ProductID, ratings2.SKU, classes.ClassID, class.Class, comments.Comments, ratings2.Rating FROM voters, ballots, classes, comments, ratings2, class WHERE ballots.VotersID=voters.VotersID AND classes.BallotID=ballots.BallotID AND comments.BallotID=ballots.BallotID AND ratings2.BallotID=ballots.BallotID AND classes.ClassID=class.ClassID ORDER BY SKU, Class And now it is listed just like I wanted. Thanks for the help and the explaination. Regards, Don
  2. Hi All, I have a multiple join that works for everything but one. I get back the correct info, except the ClassID and Class, both repeat the first records value. I cannot figure out why. Here is my query. SELECT voters.VotersID, ballots.VotersID, voters.EmailAddress, ballots.BallotID, ratings2.ProductID, ratings2.SKU, classes.ClassID, class.Class, comments.Comments, ratings2.Rating FROM voters, ballots, classes, comments, ratings2, class WHERE ballots.VotersID=voters.VotersID AND classes.BallotID=ballots.BallotID AND comments.BallotID=ballots.BallotID AND ratings2.BallotID=ballots.BallotID AND classes.ClassID=class.ClassID GROUP BY voters.VotersID, ratings2.RatingID Here is a snapshot of the results. I tried many different approaches and they all give me the same results. As always, I appreciate the help. regards, Don
  3. Hi All, I have a user table that I need to delete all records that are duplicates (based on the EmailAddress field). I have my site coded to not allow dupes (by query first then either update or insert), but I also have a page for employees to import records from a CSV with fgetscv that sometimes inserts records where that email address exists. I tried about a dozen different approaches, and none worked. Here is a sample of what I tried and end up with it timing out (The table has 1.8 million records). $sql = "SELECT MIN(maxID) AS totalcount FROM max8 GROUP BY EmailAddress"; $result = mysql_query($sql) or die (mysql_error()); $num_rows = mysql_num_rows($result); $unique_ids = array(); for($i=0;$i<$num_rows;$i++) { $unique_ids[] = mysql_result($result,$i,0); } mysql_free_result($result); $id_list = implode(',',$unique_ids); $sql = "DELETE FROM max8 WHERE maxID not in($id_list)"; $query = mysql_query($sql) or die (mysql_error()); mysql_close($conn); echo 'All duplicates where deleted'; I also noticed some addressed this by making a temp table, then exporting a unique select query, then comparing and deleting, but that seems like a round-about way. My end goal it to make a process page, that I can run and either delete all the dupes (or if it is a timeout issue) delete them state by state. Thoughts? Regards, Don
  4. Hi all, I am trying to use a pagination loop, and I have it is close to doing what I need with one exception. I needed to set the values of the array items to start at 1 instead of 0 (zero) for some loops I am doing on the next form. So I manually assigning them and here is where I am causing the issues. So when I build my table, I get back the correctly listed items in order, but I am stuck trying to get the ID's ($ID) correctly matched to the products. What I am currently getting is the IDs are assigned row by row (left to right, top to bottom) and I need them assigned columns (top to bottom, left to right). Currently I have.. 1-2-3 4-5-6 7-8-9 And I need... 1-4-7 2-5-8 3-6-9 Here is the code I am using ... //connect to MySQL include('conn.php');// Select the DB $db_selected=mysql_select_db("db"); if(!$db_selected) { die(mysql_error()); } $name = array(); $sql = "SELECT * FROM table WHERE SiteEnabled='1' AND Path='1' ORDER BY DateAdded DESC"; // We do the query, and find out how many items we'll need to list. $result = mysql_query($sql); // Define whats left and right for columns $num = mysql_num_rows($result); $left = ceil($num/3); // Define the left column for reference and the loop below // Set up the array to hold the items $items = array(); // Get all rows into array while($row = mysql_fetch_array($result)) { $items[] = $row; // $x++; } //now start the table (HTML) $ID = 1; //set the start ID for the Products loop echo '<table>'; for($i=0; $i<$left;$i++) { $left_item = $items[$i]; $mid_item = $items[$i+$left]; $right_item = $items[$i+$left+$left]; echo '<tr>'; //------------------------1st column start----------------------------------// if(!empty($left_item['Name'])) { echo '<td width="300 align=left style="padding-left:10px" nowrap="nowrap">'; echo '<input name="Products['.$ID.']" id="dy_rating_chk_'.$ID.'" type="checkbox" tabindex="' . $tab . '" value="'.$left_item['SKU'].'"'; if(isset($_SESSION['products'][$ID])) //check and see if the box is checked IE they came back in the browser { echo ' checked>'; } else { echo ' >'; } echo htmlstripline($left_item['Name']); echo '</td>'; } else { echo '<td> </td>'; } $ID++; //------------------------1st column end----------------------------------// //------------------------2nd column start----------------------------------// if(!empty($mid_item['Name'])) { echo '<td width="300 align=left style="padding-left:10px" nowrap="nowrap">'; echo '<input name="Products['.$ID.']" id="dy_rating_chk_'.$ID.'" type="checkbox" tabindex="' . $tab . '" value="'.$mid_item['SKU'].'"'; if(isset($_SESSION['products'][$ID])) //check and see if the box is checked IE they came back in the browser { echo ' checked>'; } else { echo ' >'; } echo htmlstripline($mid_item['Name']); echo '</td>'; } else { echo '<td> </td>'; } $ID++; //------------------------2nd column end----------------------------------// //------------------------3rd column start----------------------------------// if(!empty($right_item['Name'])) { echo '<td width="300 align=left style="padding-left:10px" nowrap="nowrap">'; echo '<input name="Products['.$ID.']" id="dy_rating_chk_'.$ID.'" type="checkbox" tabindex="' . $tab . '" value="'.$right_item['SKU'].'"'; if(isset($_SESSION['products'][$ID])) //check and see if the box is checked IE they came back in the browser { echo ' checked>'; } else { echo ' >'; } echo htmlstripline($right_item['Name']); echo '</td>'; } else { echo '<td> </td>'; } $ID++; //------------------------3rd column end----------------------------------// echo '</tr>'; } echo '</table>'; //-------------------------------- End dynamic loop --------------------------------// As always, I appreciate the help, regards, Don
  5. Sorry, { echo ' checked>'; } else { echo Should have been this. But still not retaining the $_SESSION['products'][$i] like in the if(isset($_SESSION['products'][1])) { echo ' checked'; } version before the pre-written version. Don
  6. Well I got closer with this... // Handle the last $padding rows specially, by ignoring the last column. for(/*$i already has the correct value*/; $i<$display_rows; $i++) { echo '<tr>'; for($j=0; $j<$display_columns-1; $j++) { echo '<td width="250 align=left style="padding-left:10px" nowrap="nowrap"><input name="Products['.$i.']" id="dy_rating_chk_'.$i.'" type="checkbox" tabindex="29" value="'.$i.'"'; if(isset($_SESSION['products'][$i])) { echo ' checked="checked" >'; } else { echo ' >'; } echo $all_columns[$j][$i]; echo '</td>'; } // Empty padding cell. echo '<td></td>'; echo '</tr>'; } echo '</table>'; But if the user comes back to the page to fix an error, all the item are now checked. NOTE, I am using a SELF form. I still could use some help though. Thanks, Don
  7. I am trying to implement some pre-written pagination code I found with my code. It is using a mysql_result with straight <td> </td> tags, and I have somewhat more complicated tags with an if statement enclosed in a input tag, making is near impossible for me to get the pre-written code to work for me. (for space sakes, I did not display the non-applicable code that is before and after [for the rest of the table] or the connection code). Here is the pre-written example: //The usual "Let's push elements onto an array" deal. $all_columns[$current_column][]=mysql_result($result,$i,'ShortName'); for($i=0; $i<$display_rows-$padding; $i++) { echo '<tr>'; for($j=0; $j<$display_columns; $j++) { echo '<td>',$all_columns[$j][$i],'</td>'; } echo '</tr>'; } And the part I am stuck on is my equivalent of the <TD></TD> tags are... <td width="196" align=left style="padding-left:40px" nowrap="nowrap"> <input name="Products[1]" id="dy_rating_chk_1" type="checkbox" tabindex="29" value="1" <?php if(isset($_SESSION['products'][1])) { echo ' checked'; } ?>> The Great Depression</td> And my attempt to mix my code with the $display_columns was a feeble disaster. here... for($i=0; $i<$display_rows-$padding; $i++) { echo '<tr>'; for($j=0; $j<$display_columns; $j++) { echo '<td width="196" align=left style="padding-left:40px" nowrap="nowrap"><input name="Products['.$i.']" id="dy_rating_chk_'.$i.'" type="checkbox" tabindex="29" value="'.$i.'"'; if(isset($_SESSION['products'][$i])) { echo ' checked'; } echo $all_columns[$j][$i].'</td>'; } echo '</tr>'; } Which should have gave me 3 colums, 11 items all with names and check boxes. What I got 3 columns, 6 check boxes in the top 2 row with no names, and 4 names in the bottom 2 rows with no check boxes. As always, I appreciate the guidance, and help. Regards, Don
  8. Thanks barand, I will put your fix in my saved code library. I made a stupid mistake. I forgot to go back and get the ProductID from the first form from the database and I had hard-coded it with the ID's starting at 0 <input name="Products[0]" //etc And I went back here and changed it to get the data from the table, and now I am in sync (starting with 1 as I should be. But you fix is something I can still use in another thing I was thinking of, thanks. I owe you one. regards, Don
  9. I get what your saying, but that is if I am defining the array. This array is from $_POST['Class'] data from the previous page, which is set to zero by default. So how can I have it start at 1 or at least, add 1 to all the indexes in the loop. Or is that too tough to do? Thanks, Don
  10. Hi Barand, That worked great, but, for my use, I had to change it to: foreach ($_POST['Class'] as $ProductID => $classesArray) { foreach ($classesArray as $ClassID) { //insert ratings data into MySQL $sql ="insert into classes"; $sql .="(BallotID, ProductID, ClassID, Date)"; $sql .="values('$BallotID', '$ProductID', '$ClassID', '$Date')"; if(!mysql_query($sql)) { echo 'insert into classes error<br><br>' . mysql_errno().'<br>'.mysql_error().'<br><br>'; } { { But the question I have is, the array of course, start with zero, as they all do. I need the $ProductID to start with 1, how would I do that in this instance? Thanks, Don
  11. I want to insert the data. What I need to get is: (and if I am totally wacko on this, please let me know, since I am not a multi dim guru). The BallotID was 1 (from the query before this, and I just need to use that for this insert, and not change it) And I need to insert the for the chosen checkboxes array index, and which ones they picked. so... BallotID ClassID ClassesID 1----------0--------1 1----------0--------2 1----------1--------3 1----------1--------4 1----------2--------5 1----------2--------6 And this is from the POST data of Does that make sense? Thanks, Don
  12. Hi everyone, I am can do this with a one dim. array, but when I get back what I need, like this.. [Class] => Array ( [0] => Array ( [1] => 1 [2] => 2 ) [1] => Array ( [3] => 3 [4] => 4 ) [2] => Array ( [5] => 5 [6] => 6 ) ) I get messed up. With my other arrays, I would do this... foreach($_POST['Class'] $BallotID => as $ClassID) { //insert ratings data into MySQL $sql ="insert into classes"; $sql .="(BallotID, ClassID, Date)"; $sql .="values('$BallotID', '$ClassID', '$Date')"; if(!mysql_query($sql)) { echo 'insert into classes error<br><br>' . mysql_errno().'<br>'.mysql_error().'<br><br>'; } } But that of course, gets me only the last item chosen. I appreciate the help, Don
  13. BINGO Craygo! $Rate[$xx].'['.$key1.']' Now gives me... And I end up with my arrays the way I need them... Sweet, thanks Craygo, perfect answer, owe ya one! Don
  14. I am sorry, but I am not making it clear. You are correct, that is what I want from the loops, but I need help nesting the array coding. Let me try to simplify my code (I am not showing the entire page for readability) I am building this page dynamically, from a previous page where the user picked a certain number of videos. That choice dictates how many sets of checkboxes will be displayed on this page. So in this example, I am showing 2 sets of checkboxes, and I need them to be named: ( I am assuming this is the correct naming convention for a multidimensional checkbox array) Set 1: name='checkbox[0][0]' name='checkbox[0][1]' name='checkbox[0][2]' Set 2 name='checkbox[1][0]' name='checkbox[1][1]' name='checkbox[1][2]' So , I define the array name, and increment it like this, before the loop that displays the checkboxes. $zz=1; $xx=1; foreach($_SESSION['products'] as $key => $value) { // build the other elements of the form -- working fine //---------- make a dummy array for the Class loop to use as Rating[x] names for checkbox array -----// $Rate = array(); $Rate[$zz] = "Class[" . $key . "]"; //for the Class loop - check box array names $zz++; //------------------------------------------------------------------------------------// foreach($Class_array as $key1=> $value) { echo '<label for=' . $xx . '_' . $key1 . ' style=\'padding-right:3px;display:block;\'><input name=\'' . $Rate[$xx] . '\' value=\'' . $key1 . '\' type=\'checkbox\' id=' . $xx . '_' . $key1 . ' onclick=\'highlight_div(this);\'>' . $value . '</label>'; } $xx++; } Then I am trying( Here is my attempt.. ... to display the checkboxes and get the names to be like the example above (IE Set 1, Set 2) in this code snippet... echo '<label for=' . $xx . '_' . $key1 . ' style=\'padding-right:3px;display:block;\'><input name=\'' . $Rate[$xx][$key] . '\' value=\'' . $key1 . '\' type=\'checkbox\' id=' . $xx . '_' . $key1 . ' onclick=\'highlight_div(this);\'>' . $value . '</label>'; This is probably incorrect, but do you see what I am attempting to do? I appreciate your patience and help, Don
  15. Hi everyone, I opted to do this as checkboxes vs a select list because I could not come up with a 'working' option that did not fall apart at some point [hopefully, this avenue will not either] so please bear with me. I have a series of checkboxes that are dynamically created from a previous form, and are named Class, and contain all the possible 'classes' (88 total subjects taught, and I need to let them choose multiple classes, IE, thats why I opted for checkboxes) that a teacher may have used for each of the video they chose on the previous form. So on this form, I will give this example. (Here I will show 2 videos selected from the previous form, creating 2 sets of checkboxes for the 'Class' checkboxes, so for so good? ---------------------------------------------------- $zz=1; $xx=1; foreach($_SESSION['products'] as $key => $value) { // build the other elements of the form -- working fine //---------- make a dummy array for the Class loop to use as Rating[x] names for checkbox array -----// $Rate = array(); $Rate[$zz] = "Class[" . $key . "]"; //for the Class loop - check box array names $zz++; //------------------------------------------------------------------------------------// foreach($Class_array as $key1=> $value) { echo '<label for=' . $xx . '_' . $key1 . ' style=\'padding-right:3px;display:block;\'><input name=\'' . $Rate[$xx] . '\' value=\'' . $key1 . '\' type=\'checkbox\' id=' . $xx . '_' . $key1 . ' onclick=\'highlight_div(this);\'>' . $value . '</label>'; } $xx++; } But this will not give me a multidimensional array. And I believe I need to change this... echo '<label for=' . $xx . '_' . $key1 . ' style=\'padding-right:3px;display:block;\'><input name=\'' . $Rate[$xx][$key] . '\' value=\'' . $key1 . '\' type=\'checkbox\' id=' . $xx . '_' . $key1 . ' onclick=\'highlight_div(this);\'>' . $value . '</label>'; ...but that doesnt give me a nested array in the first array either. I am not an array 'guru', I am missing that gene. I would appreciate anyone with that gene's help. Thanks, Don
  16. Thanks for the mods and code cleanup (sorry, dreamweaver [and me] sometimes do not indent correctly) I made your changes and it still did not identify when they did not pick a drop down. I played with this and got it working. I had to change it to: And now, it they do not select a video, it will tell them. Thanks for the help. I think this is resolved, unless you see something I missed? Don
  17. I am sorry, I am not explaining myself very well. I don't think you understand what I need. I need to test the value of Rating[0] - x to ensure they chose a value for each of the drop downs, and the default for each is "" => "Rate this video:" So if I test for !empty and the $key, it would return that the $key is not empty and let them continue. And they did not pick a value for each of the drop downs. I have this in place now before my code... if(empty($_POST['Rating'][$key])) { echo '$_POST[\'Rating\']['.$key.']\'=' . $_POST['Rating'][$key] . '<br><br>'; } And if they do not select anything from the drop downs, it gives me... I need to test that they picked one of the values for each of the ratings. Does that make more sense now? Thanks a lot, Don
  18. Yep, that was it. That solved that. But now I ended up with another issue. I have an array for this item that I want the user to rate. And I am checking to see if they picked a value or not and I am testing it, but I always get a true and its not correct. Here are the values for the array: // $key added to make the drop down dynmamic and uses the $key from the foreach loop function makeDropListKey($name,$list,$selected="",$key) { // $name select name // $list array of value, label pair // $selected selected value global $x;//for the tab index global $key;//gets this value from the foreach loop while(list($value,$label) = each($list)) { $options .= '<option value="'.$value.'">'.$label.'</option>'; } $dropList = '<select name="'.$name.'['.$key.']" tabindex="'.$x.'">'.$options.'</select>'."\n"; $dropList = ereg_replace("value=\"$selected\"","value=\"$selected\" selected",$dropList); return $dropList; } $label = array( "" => "Rate this video:", "1" => "1 Poor", "2" => "2", "3" => "3", "4" => "4", "5" => "5 Excellent"); // default for empty selected And what I am testing for is the $key, but it will always test as TRUE since there is POST data for the keys. But unless they choose an item from the menu, there wont be a $value. So how would I test for the $value dynamically instead of the $key? Here is my $key test code: foreach($_SESSION['products'] as $key => $value) { if(!isset($_POST['Rating'][$key]) && (isset($_POST['form2_submit']))) { echo '<font face="Arial" color="#FF0000" size="+1"><b>' . $name . '</b></font>'; } else { echo $name . '</td>'; } //more code goes here that does not apply (for the $value) $list = makeDropListKey('Rating',$label,$_SESSION['Rating'][$key],$key); //used makeDropListKey which adds $key to make the Rating[$key] <-- dyanamic ability to function echo $list; { Thanks, Don
  19. Hi all, I am stumped in how to code this. What I am trying to do is to code this out so that it will give me... foreach($_SESSION['products'] as $key => $value) { if(isset($_POST['Rating[0]']) && (isset($_POST['form2_submit']))) //some more code goes here.... } in the end. Where 0 in $_POST['Rating[0]'] is replaced $key so I can increment thru my foreach and loop thru the keys and get all the POST data. But I am stuck and I tried... $_POST['Rating['.$key.']] $_POST['Rating'.[$key]] and so forth and never get a value for $POST['Rating[0]'] and the rest when it exists, so I know I am not writing it correctly in my foreach loop. Does this make sense? Thanks for the help. Don
  20. One other thing, does this new way of doing a foreach with the POST data automatically make all POST data an error if not filled out? Because, if so, thats going to cause a problem with my code, since not all the fields are required and my page code, is going to fail if they do not fill out all the fields. thanks, Don
  21. For the last POST, I should mention, if I chose K-3 and 4, and did a print_r, I would get. Also, with the new function, I now get ( I am assuming its the checkbox arrays, since I have 2 sets of them and I am getting 2 errors). and line 16 of the function is. return $errors[$string]; So to condense, I have 2 issues, the checkboxes not retaining there checked state, and them causing the Illegal offest. I found this comment on http://www.php.net/manual/en/language.types.array.php about arrays. So will this still work for the checkboxes, and can we fix it and make them retain their checked states when we come back to fix the errors? Don
  22. Yes, you hit it right on the head. Thanks that worked great! If you don't mind, I had another function/test that I cannot seem to resolve which is right along the same line. I have a dynamic function checkbox code, that works, except it doesn't seem to get the POST data for 'checked' so when they come back, like when they do not fill in the data like above, the checkboxes are always reset. Here is my code. $grades = array('K-3', '4', '5', '6', '7', '8', '9', '10', '11', '12', 'Other'); $x='5'; //tabindex value $zz='0'; foreach($grades as $grade) { $selected = ((isset($_POST['grade']) && !empty($_POST['grade'])) ? in_array($grade, $_POST['grade']) : false); echo '<input type="checkbox" id="chk" name="GRADE['.$zz.']" tabindex="'.$x.'" value="GRADE ' . $grade . '"' . ($selected ? 'checked' : '') . '>'; if($grade=='Other') { echo ' <label for="' . $grade . '_chckbx">' . $grade .' '; } else { echo ' <label for="' . $grade . '_chckbx">' . $grade . ' |'; } $x++; $zz++; } The HTML result of the above is (to save you from putting in your editor). What did I miss? I posted this on another forum and they were stumped? Thoughts? Thanks, Don
  23. I am defining the them in the loop. And I think I follow what you are saying and I 'think' thats what I am trying to get to, but don't know how to change my function and or code the array to work with it. Can you guide me on this? Thanks in advance, Don
  24. I have 24 instances of the FirstName value. (actually, 24 of all of them) [1] => "First Name" thru [337] => "First Name" And if i echo $errors['FirstName'] I do not get anything. If I change the loop to ... $errors['FirstName'] = errors($_POST['FirstName'], '"First Name" required field, please correct this entry.'); and then echo errors['FirstName']l it works. Don
  25. Hi Ray, So I did like you suggested. $errors = array(); foreach($_POST as $key => $val){ if(errors($val, "\"$key\" is a required field, please correct this entry.")){ $errors[] = errors($_POST['Title'], '"Title" required field, please correct this entry.'); $errors[] = errors($_POST['FirstName'], '"First Name" required field, please correct this entry.'); //etc } } End it I print_R($errors) I get ... and repeats up to 349 ???? Why? Also, doing it this way, what to I echo $errors['Title'] wont work, so I would have to echo $errors[0] correct? Don
×
×
  • 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.