Jump to content

dmacman

Members
  • Posts

    39
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

dmacman's Achievements

Member

Member (2/5)

0

Reputation

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