Jump to content

rbragg

Members
  • Posts

    176
  • Joined

  • Last visited

    Never

Everything posted by rbragg

  1. You are continually awesome! I'm trying to apply this idea when using operations. I'm doing a query to get values currently stored in a db table. I am adding the posted values to those and then doing an update query. Here is what I have so far: <?php while($all = mysql_fetch_array( $allstats )) { foreach ($player as $id => $playerID) { $hit = $_POST['hit'][$id]; $allhit = $all['hit'] + $hit; $ab = $_POST['ab'][$id]; $allab = $all['ab'] + $ab; $bb = $_POST['bb'][$id]; $allbb = $all['bb'] + $bb; $secondb = $_POST['2b'][$id]; $all2b = $all['2b'] + $secondb; $thirdb = $_POST['3b'][$id]; $all3b = $all['3b'] + $thirdb; $hr = $_POST['hr'][$id]; $allhr = $all['hr'] + $hr; $rbi = $_POST['rbi'][$id]; $allrbi = $all['rbi'] + $rbi; $queryUpdateAll = " UPDATE stats_all SET hit = '$allhit' , ab = '$allab', bb = '$allbb', 2b = 'all2b', 3b = 'all3b', hr = '$allhr', rbi = '$allrbi' WHERE playerID = '$player' "; $updateAll = mysql_query($queryUpdateAll) or die("<p class='style5'>Update query failed: " . mysql_error()) . "</p>"; } ?> This doesn't seem to be working. ???
  2. Hi there, Barand! foreach ($_POST['hits'] as $playerID => $hit) For example, I have $_POST['hits'], $_POST['ab'], $_POST['bb']. Each of these are arrays (containing the number of hits for each playerID, the number of at bats for each playerID, and the number of walks for each playerID). Each has its own column in my db table. playerID is also a column and I want to store the values for each playerID. <?php # inserting stats for new tourny $player = $_POST['playerID']; foreach ($player as $order => $playerID){ $queryStatsPer = " INSERT into stats_per_tourny (playerID, tournyID, hit, ab, bb) VALUES ( '$playerID', '".$_POST['tournyID']."', '$hit', '$ab', '$bb' )"; $insertStatsPer = mysql_query($queryStatsPer) or die("<p class='style5'>Insert query failed: " . mysql_error()) . "</p>"; } ?> Thanks in advance.
  3. Is there a way to do something like this: <?php foreach ($_POST['hits'] as $playerID => $hit, $_POST['ab'] as $playerID => $ab , $_POST['bb'] as $playerID => $bb) { } ?>
  4. Ok I think this is how it's supposed to be. I do have a problem somewhere, though. I just haven't figured out what it is yet. LOL! Will let you guys know.
  5. akitchin, it's getting there! I named all of the inputs as arrays, ie. hits[]. Now my information is stored within the POST array for each input. The problem I have now is that the playerID is not associating itself with the input. Instead of having say (for playerID# 5): [hits] => Array ([5] => 3 I have: [hits] => Array ([0] => 3 It increments from 0 to 16. I know I must associate the playerID somehow with each input but I'm not sure how to go about that. I'm sure there is some trick.
  6. Hopefully, this will be a quick and painless answer. The values for the the last playerID in the db table are the only values passed in the POST array. I would like to have values for all 17 playerIDs passed and not just the 17th. Thanks in advance. <?php $queryPlayers = " SELECT playerID, player FROM players $playerResults = mysql_query($queryPlayers) or die('Find players query failed: ' . mysql_error()); while ($player = mysql_fetch_array($playerResults)) { echo "<input name='playerID' type='hidden' value='" . $player['playerID'] . "'"; echo "<tr>"; ?> <td align='center'><input name="hits" type="text" size="3" maxlength="3" value="0" class="style3" /></td> <td align='center'><input name="ab" type="text" size="3" maxlength="3" value="0" class="style3" /></td> <td align='center'><input name="bb" type="text" size="3" maxlength="3" value="0" class="style3" /></td> <td align='center'><input name="2b" type="text" size="3" maxlength="3" value="0" class="style3" /></td> <td align='center'><input name="3b" type="text" size="3" maxlength="3" value="0" class="style3" /></td> <td align='center'><input name="hr" type="text" size="3" maxlength="3" value="0" class="style3" /></td> <td align='center'><input name="rbi" type="text" size="3" maxlength="3" value="0" class="style3" /></td> </tr> <?php } ?>
  7. Awesome, awesome, awesome! Thanks so much!! That small change works perfectly. Again, thanks for sticking with me.
  8. Sure: <?php include 'dbConnect.php'; $queryPosts = " SELECT t.name, t.subject, t.timestamp FROM onetable t INNER JOIN (SELECT subjectID, MIN(actionID) as id FROM onetable GROUP BY subjectID UNION SELECT subjectID, MAX(actionID) as id FROM onetable GROUP BY subjectID ) as a ON t.subjectID = a.subjectID and t.actionID = a.id ORDER BY t.subjectID DESC "; $postResults = mysql_query($queryPosts) or die('The post query failed: ' . mysql_error()); echo "<form name='form_display' method='POST' action='forumDetail.php'>"; echo "<table width='100%' border='0' cellspacing='2' cellpadding='2'> <tr bgcolor='#616161'><td width='8%'><input name='view' type='submit' class='style3' value='view'></td> <td class='style6'>Message</td><td class='style6'>Started by</td><td class='style6'>Date & Time Started</td></tr>"; while ($post = mysql_fetch_array($postResults)) { $prevSubject = $post['subjectID']; if ($post['subjectID'] != $prevSubject) { echo "<tr><td align='center' class='style3'>"; ?> <input type='radio' name='selected' value='<?php echo $post['subjectID'];?>'> <?php echo "</td>"; } else { echo "<tr><td align='center' class='style3'> </td>"; } echo "<td class='style8'>"; echo $post['subject']; echo "</td><td class='style3'>"; echo $post['name']; echo "</td><td class='style3'>"; echo $post['timestamp']; echo "</td></tr>"; } echo "</table>"; echo "</form>"; mysql_close; ?>
  9. I thought that may have been the case. I tried that and I get rbs before every subject. How would $prevSubject know whether or not to get the subjectID from the MIN or MAX? I've attached a screencap: [attachment deleted by admin]
  10. Ah. $subjectID is not yet stored in the POST array. This is the first page in the process. It just displays all of the current threads and a glimpse of the last reply to each thread. I have to find a way to set $prevSubject. I hope I am following you.
  11. Good morning, Barand. I get the general idea except for the $prevSubject variable. I'm not sure how I would set it: <?php $prevSubject = ''; while ($post = mysql_fetch_array($postResults)) { if ($post['subjectID'] != $prevSubject) { echo "<tr><td align='center' class='style3'>"; ?> <input type='radio' name='selected' value='<?php echo $post['subjectID'];?>'> <?php echo "</td>"; } else { echo "<tr><td align='center' class='style3'> </td>"; } echo "<td class='style8'>"; echo $post['subject']; echo "</td><td class='style3'>"; echo $post['name']; echo "</td><td class='style3'>"; echo $post['timestamp']; echo "</td></tr>"; } # close while ?>
  12. I'm sorry, I was assuming that the t. and a. were referencing separate tables. I was being stubborn about that. Here was my attempt at this join: <?php $queryPosts = " SELECT t.name, t.subject, t.timestamp FROM onetable t INNER JOIN (SELECT subjectID, MIN(actionID) as id FROM onetable GROUP BY subjectID UNION SELECT subjectID, MAX(actionID) as id FROM onetable GROUP BY subjectID ) as a ON t.subjectID = a.subjectID and t.actionID = a.id ORDER BY t.subjectID DESC "; $postResults = mysql_query($queryPosts) or die('The get posts query failed: ' . mysql_error()); echo "<form name='form_display' method='POST' action='forumDetail.php'>"; echo "<table width='100%' border='0' cellspacing='2' cellpadding='2'> <tr bgcolor='#616161'><td width='8%'><input name='view' type='submit' class='style3' value='view'></td> <td class='style6'>Message</td><td class='style6'>Started by</td><td class='style6'>Date & Time Started</td></tr>"; while ($post = mysql_fetch_array($postResults)) { echo "<tr><td align='center' class='style3'>"; ?> <input type='radio' name='selected' value='<?php echo $post['subjectID'];?>'> <?php echo "</td><td class='style8'>"; echo $post['subject']; echo "</td><td class='style3'>"; echo $post['name']; echo "</td><td class='style3'>"; echo $post['timestamp']; echo "</td></tr>"; } echo "</table>"; echo "</form>"; ?> This gives the results that it is indeed asking for. This type of query is new to me so I'm still trying to wrap my brain around it. I only have a small problem, now, of trying to think up a cosmetic trick. Of course, I would like first and last posts to be grouped together with an indention before the last post. Also, all of the posts have radiobuttons in front of them and I'd like for only the first post to have a radiobutton. I'm not sure of how I can achieve these effects since they are being displayed within a loop. ???
  13. I did try this. However, since the result was nowhere close to working I reverted back to what seemed to be very close to working. ON t.subject= a.subject and t.timestamp = a.date I have only one table so am not sure how to approach this part of the query. Also, I am finding the MIN/MAX actionID instead of timestamp/date.
  14. Good afternoon! My queries are here: http://www.phpfreaks.com/forums/index.php/topic,136600.msg581456.html#msg581456 Again, $queryLastReply is functioning properly. My table structure is here: http://www.phpfreaks.com/forums/index.php/topic,136600.msg577549.html#msg577549
  15. Hi Barand! I have only one table. I have tried implementing this idea, though, with no luck.
  16. Thanks for sticking with me. This gives me a completely blank loop. Echoing the query gives me Resource id #7.
  17. This was on the 3rd or 4th page and I see boo_lolly on today.
  18. I've managed to get the results that I would like for $queryLastReply: <?php # this query groups subjects together and displays the last post of each thread to show the last reply $queryLastReply = " SELECT actionID, name, subjectID, subject, timestamp FROM onetable WHERE subjectID = '". $first['subjectID'] ."' ORDER BY actionID DESC LIMIT 1 "; ?> This successfully gives me the last post of each thread. However, I'm having trouble with consistently getting the first post for each thread with $queryFirst. Most show the first post in the thread but a few will show the last post. I cannot find the common denominator between those threads: <?php # this query groups subjects together and displays the first post of each thread $queryFirst = " SELECT MIN(actionID), name, subjectID, subject, timestamp FROM onetable GROUP BY subjectID ORDER BY subjectID DESC "; ?>
  19. Good morning! I've been on vacation since last Thursday afternoon so I'm sorry for the delayed reply. I get the same result using DISTINCT ... the empty "last reply: ".
  20. In my many desperate attempts, I did add the GROUP BY clause. I just tried it a second time and it does not echo any values. I just get "last reply: ". Since I'm not getting the "by" or "at" that are in the 2nd while statement I assume the problem is still in $queryLastReply. :'(
  21. Thanks for your continued help, mpharo I've tried your method and the fetch_array does not seem to work at any point with my db structure. I see where you are heading but I don't think this method will work with the type of data I'm trying to extract.
  22. If you are offering your help I'd like to be as clear as possible. It must be annoying to read such vague posts. I've tried this method with the timestamp and again, without the GROUP BY clause I get: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause *reading mpharo's post*
  23. boo_lolly, I studied the other thread and incorporated a nested while loop into my code: <?php include 'shared/dbConnect.php'; # this query groups subjects together and displays the first post of each thread $queryFirst = " SELECT MIN(actionID), name, subjectID, subject, timestamp FROM onetable GROUP by subjectID ORDER by timestamp DESC "; $firstResults = mysql_query($queryFirst) or die('The first query failed: ' . mysql_error()); echo "<form name='form_display' method='POST' action='forumDetail.php'>"; echo "<table width='100%' border='0' cellspacing='2' cellpadding='2'> <tr bgcolor='#616161'><td width='8%'><input name='view' type='submit' class='style3' value='view'></td> <td class='style6'>Message</td><td class='style6'>Started by</td><td class='style6'>Date & Time Started</td></tr>"; while ($first = mysql_fetch_array($firstResults)) { echo "<tr><td align='center' class='style3'>"; ?> <input type='radio' name='selected' value='<?php echo $first['subjectID'];?>'> <?php echo "</td><td class='style8'>"; echo $first['subject']; echo "</td><td class='style3'>"; echo $first['name']; echo "</td><td class='style3'>"; echo $first['timestamp']; echo "</td></tr>"; echo "<tr><td colspan='4' align='right' class='style3'><span class='style7'>"; # setting up nested while # this query groups subjects together and displays the last post of each thread to show the last reply $queryLastReply = " SELECT MAX(actionID), name, subjectID, subject, timestamp FROM onetable WHERE subjectID = '". $first['subjectID'] ."' GROUP BY subjectID "; $lastResults = mysql_query($queryLastReply) or die('The last reply query failed: ' . mysql_error()); while ($last = mysql_fetch_array($lastResults)) { $reply = "<b>" . $last['subject'] . "</b> by " . $last['name'] . " at " . $last['timestamp']; } echo "last reply: </span>$reply</td></tr>"; echo "<tr><td></td></tr>"; } echo "</table>"; echo "</form>"; mysql_close; ?> Now, both $queryFirst & $queryLastReply give me the last reply. Please note the example in example_messagedisplay.jpg. [attachment deleted by admin]
  24. I'd like to display the last reply for each individual subject under that subject. [attachment deleted by admin]
×
×
  • 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.