rbragg
Members-
Posts
176 -
Joined
-
Last visited
Never
Everything posted by rbragg
-
I have a field (PK) in a table called callID that increments. This is what I would like to use for counting. So, with your logic would I do something like this? <?php while($all = mysql_fetch_array( $allResults )) { $countNew++; $countLast = $all['callID']; if $countLast < $countNew { $countNew = $countLast; echo 'encode sound'; } }?> Am I getting what you're saying?
-
I haven't any yet other than my select statement and display: <?php $queryAll = " SELECT * FROM vigil_student, vigil_operator, vigil_call WHERE vigil_student.studentID = vigil_call.studentID AND vigil_operator.operatorID = vigil_call.operatorID ORDER by time DESC "; $allResults = mysql_query($queryAll) or die( "All query failed: " . mysql_error() ); # count for alternate colors $countRows = 0; while($all = mysql_fetch_array( $allResults )) { # alternate colors for every row if ($countRows++ % 2 == 0){ $style = "background-color: #F9F9F9;"; } else { $style = "background-color: #FFFFFF;"; } $time = $all['time']; echo "<tr class='style1' style='$style'><td>" . date("M j, y @ h:i a", strtotime($time) ) . "</td>"; echo "<td>" . $all['first'] . " " . $all['last'] . "</td>"; echo "<td>" . $all['hall'] . "</td>"; echo "<td>" . $all['room'] . "</td>"; echo "<td><img src='images/" . $all['status'] . ".gif'></td>"; echo "<td><a href='displayDetails.php?call=" . $all['callID'] . "'>details</a></td></tr>"; } mysql_close; ?>
-
I have a call center page with a meta tag to refresh every 60 seconds. So, every 60 seconds the page checks for new records in my db. I would like to have a sound play upon refresh only if a new record is found and displayed. I imagine that I would start at the top of the page with some sort of record count. My page uses sessions, so if there is a larger count than at the last check then the sound would play. Am I heading in the right direction? Could someone help me get started? Thanks in advance.
-
We were right. Changing the type gave the result I needed. Thanks everyone for your help.
-
I'm not dabbling with the time at all: <?php $queryUpdate = " UPDATE vigil_call SET status = '$status' WHERE callID = '$callID' "; $update = mysql_query($queryUpdate); ?> I imagine my problem is that the column need not be the timestamp type?
-
This question will probably sound really stupid: I am storing the date and time of an insertion into the db using now(). However, if I update any other fields/columns in the db later - that date/time is also updated. How can I prevent this? Thanks in advance!
-
It made good sense. This was successful in echoing the contents of the array. However, on the form it would not display $unitName (the name next to the checkbox) unless I did as that previous helper suggested and add: $_POST['cbUnit'] = array(); Also, since the array is no longer stored as a string I am no longer able to implode it for db insertion" $cbUnitString = implode(", ",$unit); Is there a way around this?
-
Sure! The only form element I'm posting is the cbUnit array to keep you from scrolling to China. Page 1 (user enters info): <?php session_start(); if( $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['confirm']) ) { foreach ($_POST as $key => $value) { if ($key != "confirm") { $_SESSION[$key] = strip_tags($value); } } include 'shared/validate.php'; } ?> <form name="application" method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <?php $cbUnitName = array('Talon', 'Star', 'Cater', 'Landrum'); foreach($cbUnitName as $key => $unitName) { echo "<input type='checkbox' name='cbUnit[]' value='" . $unitName . "'"; if (isset($_POST['cbUnit']) && is_array($_POST['cbUnit']) ) { foreach($_POST['cbUnit'] as $index => $checkedUnit) { echo (($unitName == $checkedUnit) ? (' checked="yes"') : (''));; } echo ">" . $unitName . "<br>"; } else { echo 'Did not enter array'; # just for testing purposes. } }?> <input type="submit" name="confirm" id="confirm" value="confirm" class="style1"> </form> Page 2 (info is echoed): <?php session_start(); echo "<pre>". print_r($_SESSION, true) ."</pre>\n"; $cbUnit = $_SESSION['cbUnit']; foreach($cbUnit as $key => $unit) { echo $unit . "<br>"; }?> The problem is that the array values are not displayed when echoing. Only [cbUnit] => Array and the Warning: Invalid argument supplied for foreach() error. Please don't find something very simple and make me feel like an idiot. I'm very sensitive today.
-
Thank you for your help. I used your last example and still have the same problem. :'( The empty array idea was suggested by a helper earlier in this thread. Also, the extra single quote was only mistyped here and is not represented in my code. Hmmm... I'm running out of things to change. LOL!
-
I still get [cbUnit] => Array. :-X All other values that are not arrays are passed successfully. I have another array from a checkbox group that is doing the same thing. Could this not be caused by the foreach statements in my form?
-
Hi! This still gives me: [cbUnit] => Array and: Warning: Invalid argument supplied for foreach()
-
I have another problem pertaining to this thread. <?php $cbUnitName = array(''Talon', 'Star', 'Cater', 'Landrum'); foreach($cbUnitName as $key => $unitName) { echo "<input type='checkbox' name='cbUnit[]' value='" . $unitName . "'"; if ( !isset($_POST['cbUnit']) ) $_POST['cbUnit'] = array(); { foreach($_POST['cbUnit'] as $index => $checkedUnit) { echo (($unitName == $checkedUnit) ? (' checked="yes"') : (''));; } echo ">" . $unitName . "<br>"; } } ?> When I submit the form, cbUnit is stored in the Sessions array. However, I can't get the values (if there are any) to echo on the next page. I move to that next page and print what is stored in the Sessions array. For cbUnit I get: [cbUnit] => Array In the space where I would like to echo the values I do this: <?php $cbUnit = $_SESSION['cbUnit']; foreach($cbUnit as $key => $unit) { echo $unit . "<br>"; }?> I get the "Warning: Invalid argument supplied for foreach()" error.
-
Thanks very much.
-
Thank you sasa! This worked. I know you put a condition in there to see if the box was checked but please explain what it does specifically. I'll then mark this thread as solved.
-
Ok thanks for sticking with me guys. I think I understand this method and now I have this: <?php $cbUnitName = array('Talon', 'Star', 'Cater', 'Landrum'); foreach($cbUnitName as $key => $unitName) { echo "<input type='checkbox' name='cbUnit[]' value='" . $unitName . "'"; echo "unit name: " . $unitName . "\n"; # added to see if $unitName is being set foreach($_POST['cbUnit'] as $index => $checkedUnit) { echo (($unitName == $checkedUnit) ? (' checked="yes"') : ('')); } echo ">" . $unitName . "\n"; } ?> For every item in the array, I get: Warning: Invalid argument supplied for foreach() in /food_test/ea_form.php on line 139 >Talon Line 139 is the second foreach construct. When I try to echo the $unitName I don't get anything ... not even the "unit name: ". So, I'm guessing that the first foreach is not functioning? I did also copy what you had here directly and had the same warning.
-
Yes. I would think moving the values from the POST to the SESSION array is redundant since I am already doing that upon submission (using $key => value). Right?
-
Everything is posted above except for the other form elements, which are unrelated to the checkboxes.
-
Hi boo_lolly! I tried this: <?php $sticky_cbUnit = (in_array('cbUnit', $unitNames) )?' checked="checked" ':' '; echo '<input type="checkbox" ' . $sticky_cbUnit . ' name="cbUnit[]" value="Talon" />'; ?>Talon<br> The boxes still aren't sticky. I also tried 'cbUnit[]'. Some background info - this page submits to itself and stores the values in the $_SESSION array. <?php session_start(); if( $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['confirm']) ) # only if form is submitted { foreach ($_POST as $key => $value) # put the values into session variables { if ($key != "confirm") { $_SESSION[$key] = strip_tags($value); } } include 'shared/validate.php'; } ?> If there is an error found at validate.php then it will return. My radiobuttons use the $_SESSION array and are successfully sticky: <?php $sticky_rbStart = ( (isset($_SESSION['rbStart'])) && ($_SESSION['rbStart'] == 'Spring') )?' checked="checked" ':' '; echo '<input name="rbStart" id="rbStart" type="radio" value="Spring" ' . $sticky_rbStart . '/> '; ?>Spring
-
I'd imagine the error is because the second parameter, 'Talon', is not seen as an array. I tried to store the values in an array: $unitNames = array('Talon', 'Star', 'Cater', 'Landrum'); Then, <?php $sticky_cbUnit = (in_array($_SESSION['cbUnit'], $unitNames) )?' checked="checked" ':' '; echo '<input type="checkbox" ' . $sticky_cbUnit . ' name="cbUnit[]" value="Talon" />'; ?>Talon<br> The datatype error goes away but I don't have sticky checkboxes.
-
Thanks for your help. I have this: <?php $sticky_cbUnit = (in_array($_SESSION['cbUnit'],'Talon') )?' checked="checked" ':' '; echo '<input type="checkbox" ' . $sticky_cbUnit . ' name="cbUnit[]" value="Talon" />'; ?>Talon<br> After receiving a parse error I removed an opening "(" in front of in_array. Now, I get this error: Warning: in_array(): Wrong datatype for second argument in /food_test/ea_form.php on line 132
-
Oh yes. All of the other form elements on the page (droplists, radiobuttons, textfields) are functioning and sticky EXCEPT for the checkboxes. *EDITED* to add "except for the checkboxes" because someone erroneously marked this topic as solved.
-
I have a group of checkboxes that I would like to be sticky. I want the checkboxes that the user has checked to remain checked upon returning to the page from a validation error. <?php <input name="cbUnit[]" type="checkbox" value="Talon">Talon<br> <input name="cbUnit[]" type="checkbox" value="Star">Star<br> <input name="cbUnit[]" type="checkbox" value="Cater">Cater<br> <input name="cbUnit[]" type="checkbox" value="Landrum">Landrum<br> ?> I've tried this: <?php $sticky_cbUnit = ( (isset($_SESSION['cbUnit'])) && ($_SESSION['cbUnit'] == 'Talon') )?' checked="checked" ':' '; echo '<input type="checkbox" ' . $sticky_cbUnit . ' name="cbUnit[]" value="Talon" />'; ?>Talon<br> I'm guessing the array [] is giving me the problem but it WILL be an array so I need it. ???
-
You know I have to make things more complicated than they really are. The operation works fine outside of the query. <?php $decimal = @($hit / $ab); # @ prevents division by zero error $avg = round($decimal,3); # round to 3 decimal places $queryUpdateAll = " UPDATE stats_all SET hit = hit + '$hit', ab = ab + '$ab', bb = bb + '$bb', 2b = 2b + '$secondb', 3b = 3b + '$thirdb', hr = hr + '$hr', rbi = rbi + '$rbi', avg = '$avg' WHERE playerID = '$playerID' "; ?> This works perfectly fine. Thanks for all of your help as usual.
-
I understand what you've done. Thank you. Can you perform only limited operations within a query? Before, I was calculating an average outside of the query like this: <?php $decimal = @($hit / $ab); # @ prevents division by zero error $avg = round($decimal,3); # round to 3 decimal places ?> I'm trying this: SET avg = round( @($hit/$ab),3 ) ... and of course I get an error.
-
I wouldn't use the $all fetch_array from the original select query?