PHP - How To Get Total Value Result From A Column
I get all the results displayed but how can I echo the total value for for all rows found for under column 'duration' which only contains numbers (seconds).
$query = "SELECT * FROM asterisk_cdr WHERE calldate LIKE '%$calldate%' AND channel LIKE '%$channel%' AND duration";
$result = mysqli_query($dbcon, $query) or die('Error getting data'); $num_rows = mysqli_num_rows($result); Similar TutorialsHello I am very new to php and programming and I need a grand total of "$Total = odbc_result($result, "total");" but not sure of how to create it. I've been searching around for this for a while and nothing seems to be working properly. On my website I track who is online at the time (within the past 15 minutes). My database contains important information like ip addresses and page views during the visit. It also contains a column for two digit country codes (US, NL, CA, GB, etc.) It works great. But I'd like to display to my visitors how many countries people are visiting from at the time. I might have ten people from the US, three from England, and one from Canada. I'd like it to say we have visitors from 3 countries. My hope this could be accomplished with a simple query. Here's the code I have ended up with. But it's not working. Each visitor has one row in the table. "cCode" is the column name and "onlinenow" is the table name. I would have changed the names in my code below but I wanted to post my code exactly as is. Code: [Select] $cDiff = mysql_query("SELECT cCode, COUNT(cCode) AS number FROM onlinenow"); I also tried.... Code: [Select] $cDiff = mysql_query("SELECT cCode, COUNT(DISTINCT cCode) AS number FROM onlinenow"); It results in returning "Resource id#30" for the value of cDiff. What am I doing wrong. I am self taught and please forgive me if I didn't use the correct lingo. Thank You In Advance. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=330840.0 <html> <head> <title>Sum Html Textbox Values using jQuery/JavaScript</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script> $(function() { $(document).on('blur keyup', '.add, .sub', function(e) { var sum = 0; $('.add, .sub').each(function(i) { if (!isNaN(this.value) && this.value.length != 0) { if ($(this).hasClass('add')) { sum += parseFloat(this.value); } else { sum -= parseFloat(this.value); } } }); $('#total').text(sum.toFixed(2)); }) }) </script> </head> <body> <form method="post" action="calc.php"> Addition: <br/> Field 1: <input type="text" class="add" name="1" value="7500"/><br/> Field 2: <input type="text" class="add" name="2" value=""/><br/> Field 3: <input type="text" class="add" name="3" value=""/><br/> Field 4: <input type="text" class="add" name="4" value=""/><br/><br/> Total Addition: <br/><br/> Substraction: <br/> Field 1: <input type="text" class="sub" name="5" value=""/><br/> Field 2: <input type="text" class="sub" name="6" value=""/><br/> Field 3: <input type="text" class="sub" name="7" value=""/><br/> Field 4: <input type="text" class="sub" name="8" value=""/><br/><br/> Total Substraction: <br/><br/> Grand Total: <div id="total"></div> <input type="submit" value="submit" /> </form> </body> </html> Hello all, thanks for everything you do! I used a php from generator to make the form seen on this page: http://www.firstpresgreenville.org/forms/retirementform/retirementform-alt.html I need to be able to click on the check boxes and get a dollar amount total in the total field....So if you checked "single", the total field would read $40, and if you checked on "couple", the field would read $50...simple as that... Is there anyway to make that happen? This is the code I am working with now.... <?php # This block must be placed at the very top of page. # -------------------------------------------------- require_once( dirname(__FILE__).'/form.lib.php' ); phpfmg_display_form(); # -------------------------------------------------- function phpfmg_form( $sErr = false ){ $style=" class='form_text' "; ?> <form name="frmFormMail" action='' method='post' enctype='multipart/form-data' onsubmit='return fmgHandler.onsubmit();'> <input type='hidden' name='formmail_submit' value='Y'> <div id='err_required' class="form_error" style='display:none;'> <label class='form_error_title'>Please check the required fields</label> </div> <ol class='phpfmg_form' > <li class='field_block' id='field_0_div'><div class='col_label'> <label class='form_field'>Full Name(s)</label> <label class='form_required' >*</label> </div> <div class='col_field'> <input type="text" name="field_0" id="field_0" value="<?php phpfmg_hsc("field_0"); ?>" class='text_box'> <div id='field_0_tip' class='instruction'></div> </div> </li> <li class='field_block' id='field_1_div'><div class='col_label'> <label class='form_field'>Street Address</label> <label class='form_required' >*</label> </div> <div class='col_field'> <input type="text" name="field_1" id="field_1" value="<?php phpfmg_hsc("field_1"); ?>" class='text_box'> <div id='field_1_tip' class='instruction'></div> </div> </li> <li class='field_block' id='field_2_div'><div class='col_label'> <label class='form_field'>City</label> <label class='form_required' >*</label> </div> <div class='col_field'> <input type="text" name="field_2" id="field_2" value="<?php phpfmg_hsc("field_2"); ?>" class='text_box'> <div id='field_2_tip' class='instruction'></div> </div> </li> <li class='field_block' id='field_3_div'><div class='col_label'> <label class='form_field'>State</label> <label class='form_required' >*</label> </div> <div class='col_field'> <input type="text" name="field_3" id="field_3" value="<?php phpfmg_hsc("field_3"); ?>" class='text_box'> <div id='field_3_tip' class='instruction'></div> </div> </li> <li class='field_block' id='field_4_div'><div class='col_label'> <label class='form_field'>Zip Code</label> <label class='form_required' >*</label> </div> <div class='col_field'> <input type="text" name="field_4" id="field_4" value="<?php phpfmg_hsc("field_4"); ?>" class='text_box'> <div id='field_4_tip' class='instruction'></div> </div> </li> <li class='field_block' id='field_5_div'><div class='col_label'> <label class='form_field'>Phone</label> <label class='form_required' >*</label> </div> <div class='col_field'> <input type="text" name="field_5" id="field_5" value="<?php phpfmg_hsc("field_5"); ?>" class='text_box'> <div id='field_5_tip' class='instruction'>(###) ###-####</div> </div> </li> <li class='field_block' id='field_6_div'><div class='col_label'> <label class='form_field'>Email</label> <label class='form_required' >*</label> </div> <div class='col_field'> <input type="text" name="field_6" id="field_6" value="<?php phpfmg_hsc("field_6"); ?>" class='text_box'> <div id='field_6_tip' class='instruction'></div> </div> </li> <li class='field_block' id='field_7_div'><div class='col_label'> <label class='form_field'>Number of Attendees</label> <label class='form_required' >*</label> </div> <div class='col_field'> <input type="text" name="field_7" id="field_7" value="<?php phpfmg_hsc("field_7"); ?>" class='text_box'> <div id='field_7_tip' class='instruction'></div> </div> </li> <li class='field_block' id='field_8_div'><div class='col_label'> <label class='form_field'>Single or Couple?</label> <label class='form_required' >*</label> </div> <div class='col_field'> <?php phpfmg_checkboxes( 'field_8', "Single|Couple" );?> <div id='field_8_tip' class='instruction'></div> </div> </li> <li class='field_block' id='field_9_div'><div class='col_label'> <label class='form_field'>Amount Due</label> <label class='form_required' >*</label> </div> <div class='col_field'> <input type="text" name="field_9" id="field_9" value="<?php phpfmg_hsc("field_9"); ?>" class='text_box'> <div id='field_9_tip' class='instruction'>$40/ single or $50/couple (Includes one book and lunch)</div> </div> </li> <li class='field_block' id='field_10_div'><div class='col_label'> <label class='form_field'>Additional Comments</label> <label class='form_required' > </label> </div> <div class='col_field'> <textarea name="field_10" id="field_10" rows=4 cols=25 class='text_area'><?php phpfmg_hsc("field_10"); ?></textarea> <div id='field_10_tip' class='instruction'></div> </div> </li> <?php phpfmg_dependent_dropdown( 'field_11' );?> <li> <div class='col_label'> </div> <div class='form_submit_block col_field'> <input type='submit' value='Submit' class='form_button'> <span id='phpfmg_processing' style='display:none;'> <img id='phpfmg_processing_gif' src='<?php echo PHPFMG_ADMIN_URL . '?mod=image&func=processing' ;?>' border=0 alt='Processing...'> <label id='phpfmg_processing_dots'></label> </span> </div> </li> </ol> </form> <?php phpfmg_javascript($sErr); } # end of form function phpfmg_form_css(){ ?> Thanks so much! I am really lost here with this date issue of mine. The below code is the last part of a query: Code: [Select] $defendercheck_3 = $row_checkifattacked3['atdate']; $defendercheck1_3 = strtotime("$defendercheck_3"); $defendercheck2_3 = date("D", $defendercheck1_3); The query does not return any results as expected, but when echoing the various steps I get following: echo "$defendercheck3"; = nothing (as expected) echo "$defendercheck1_3"; = nothing (as expected) echo "$defendercheck2_3"; = result! (NOT expected) why does it return anything on "date("D", $defendercheck1_3)" when "$defendercheck1_3" is blank? My Php Buddies, I have mysql tbl columns these:
id: Now, I want to display their row data by excluded a few columns. Want to exclude these columns: date_&_time account_activation_code account_activation_status id_verification_video_file_url password
So, the User's (eg. your's) homepage inside his account should display labels like these where labels match the column names but the underscores are removed and each words' first chars CAPITALISED:
Id: 1
For your convenience only PART 1 works. Need help on Part 2 My attempted code:
PART 1 <?php // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Query to get columns from table $query = $conn->query("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'members' AND TABLE_NAME = 'users'"); while($row = $query->fetch_assoc()){ $result[] = $row; } // Array of all column names $columnArr = array_column($result, 'COLUMN_NAME'); foreach ($columnArr as $value) { echo "<b>$value</b>: ";?><br><?php } ?> PART 2 <?php //Display User Account Details echo "<h3>User: <a href=\"user.php?user=$user\">$user</a> Details</h3>";?><br> <?php $excluded_columns = array("date_&_time","account_activation_code","account_activation_status","id_verification_video_file_url","password"); foreach ($excluded_columns as $value2) { echo "Excluded Column: <b>$value2</b><br>"; } foreach ($columnArr as $value) { if($value != "$value2") { $label = str_replace("_"," ","$value"); $label = ucwords("$label"); //echo "<b>$label</b>: "; echo "$_SESSION[$value]";?><br><?php echo "<b>$label</b>: "; echo "${$value}";?><br><?php } } ?> PROBLEM: Columns from the excluded list still get displayed. Edited November 19, 2018 by phpsanehi all I have this can someone help me I'm trying to get a total cost <?php //inventory report printable total value in stock $connect = mysql_connect('*******') or die (mysql_error()); mysql_select_db('fminventory') or die (mysql_error()); $query = mysql_query("SELECT SUM(cost) FROM cars"); $query2 = mysql_fetch_array($query); echo $query2; ?> Hi All Newbie question. I'm trying to add a total of the $scores in a scoreboard at the bottom of the table. Can anyone help please ? This is what i have so far function leaderboard() { $scores = get_scores(); $num_scores = count( $scores ); usort( $scores, 'cmp_scores' ); $HTML = '<table id="entries">' . "\n"; $HTML .= '<thead>' . "\n"; $HTML .= '<tr>' . "\n"; $HTML .= ' <th>BDM</th>' . "\n"; $HTML .= ' <th>Attendees</th>' . "\n"; $HTML .= '</tr>' . "\n"; $HTML .= '</thead>' . "\n"; $HTML .= '<tbody>' . "\n"; for ( $i = 0; $i < $num_scores; $i++ ) { $HTML .= '<tr>' . "\n"; $HTML .= ' <td class="player">' . str_format( $scores[$i]['name'] ) . '</td>' . "\n"; $HTML .= ' <td class="player">' . $scores[$i]['points'] . '</td>' . "\n"; $HTML .= '</tr>' . "\n"; } $HTML .= '</tbody>' . "\n"; $HTML .= '<tfoot>' . "\n"; $HTML .= '<tr>' . "\n"; $HTML .= ' <th colspan="2"></th>' . "\n"; $HTML .= '</tr>' . "\n"; $HTML .= '</tfoot>' . "\n"; $HTML .= '</table>' . "\n"; return $HTML; Everything functions beautifully - apart from the total I need to show in the 'tfoot' section. Thanks in advance My code is a total failure. Any ideas? <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"] ["size"] < 4000000)) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />That means your picture is not right somehow...<br />"; } else { $i=1; while($i<=5000) { if (file_exists("./photos/" $POST['lname'] . "_" . $i . "_" . $_FILES["file"]["name"]])) { $i++; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "photos/" $POST['lname'] . "_" . $i . "_" . $_FILES["file"]["name"]); $i=5000; } } } else { echo "Invalid file... Only 4MB and jpeg/gifs allowed."; } $con = mysql_connect( 'localhost', 'root', 'password') if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("submition", $con) $sql = "INSERT INTO 'submition' ('fname','lname','address1','address2','city','stat_prov_reg','postal_zip','country','email','newsletter') VALUES ('"$POST['element_1_1']."' , '"$POST['element_1_2']."' , '"$POST['element_2_1']."' , '"$POST['element_2_2']."' , '"$POST['element_2_3']."' , '"$POST['element_2_4']."' , '"$POST['element_2_5']."' , '"$POST['element_2_6']."' , '"$POST['element_3']."' , '"$POST['element_7']."')"; mysql_query($sql) or die('Bad Query'); mysql_close($con); ?> <div align="center"> - <a href="http://apps.facebook.com/fourxfourexperience/'>Go Back</a> - </div> Hi I need assistance in finding the code to produce a total of all the subtotals in my shopping cart. Not sure how to assign an attribute to the table cell because a new row is generated each time a customer adds to cart. Attached is a pdf of a screenshot and script for the cart. Thanks I'm trying to figure out how to add up all the $qty_total that exist into an overall total. I hope I'm not oversimplifying my example.. I have this: $qty_total = $qty_insert * $d['workshop_price']; $qty_insert loops several times and I want: $overall_total = $qty_total + qty_total + ...however many.. the PHP below counts the number of items but not the total quantity (quantity_1) to calculate the value of $shipping. any ideas? link to form: http://crsecrets.com/test01/order.html FORM Code: [Select] <TD>Herbal Hair Rejuvenator, Unscented <FONT SIZE="-2">(4oz. jar)</FONT><input type="hidden" name="item_name_1" value="Herbal Hair Rejuvenator, Unscented (4oz. jar)" /> </TD> <TD align="center" id="table"><input name="quantity_1" type="text" value="" size="6" maxlength="2" /></TD> <TD align="center">$13.50<input type="hidden" name="amount_1" value="13.50" /></TD> Code: [Select] [m]<?php $products = array(); $url = "?business=*********$handling_cart=7.00"; foreach ($_POST as $k=>$v) { preg_match("/\_(\d{1,3})$/",$k,$match); $key = $match[1]; $products[$key][$k] = $v; } $i=1; foreach ($products as $k=>$v) { if ($v['quantity_'.$k] > 0) { foreach ($v as $k1=>$v1) { $key = explode("_",$k1); switch($key[0]) { case 'item': $var = "item_name_" . $i; break; case 'quantity': $var = "quantity_" . $i; break; case 'amount': $var = "amount_" . $i; break; } //get shipping for additional items above 3 if ($i <= 2) { $shipping = "0.00"; } else { $shipping = "1.00"; } $shipping = ($shipping * $v['quantity_' . $k]); $url .= "&" . $var . "=" . urlencode($v1); } $url .= "&shipping_" . $i . "=" . $shipping; $i++; } } #echo $url; header("Location: https://www.paypal.com/cgi-bin/webscr" . $url); exit; ?>[/m] How do I total unique id's with php or MySQL. For instance in MySQL I have... ID 1 1 3 4 2 1 1 3 How can I total all of the 1's, all of the twos, all of the threes and so forth. I have four 1's, one 2, two 3's and so forth... Hi,
I have a database which holds results
Name | Car | etc \ etc | Round 1 | round 2 | round 3 // etc | Total
the points are in the format of;
e.g.
100.5 // 25.6 // 35.8 // 50.0
I input the data manually using a webpage, clicking on the relevant driver, update scores, click submit. I have to manually work out the total, is there a way I can it it automatically add the values from round 1,2,3, etc.
Hiya! , I'm currently working on a script that will allow me to track the total users on my website, and how many of these user are logged in members, or guests. I need to be able to find out the total users, total logged in, and total guests within the last 15 minutes, and the total users, total logged in, and total guests for today. Ideally, I would like to user only one table for this, and would also like to group together records in the database that have the same users_id and ip_address, as there's not much point in storing this more than once. I currently have a table that contains the following fields. sid - Stores the users session ID. user_id - Stores the user id of a logged in user. 0 is stored if the user is a guest. ip_address - Stores the IP address of the user. last_updated - Stores a timestamp of when the user was last active. I look forward to reading your responses Cheers! I have an HTML table with the following columns: - Event - Price - # of Attendees - Total - Choose One The values are populated from a database, and I am using a loop to create the Table. The problem is that I have some syntax error where I am trying to calculate the Total Ticket Price?! Can someone help me figure what is wrong with my code? Code: [Select] <!-- Body --> <tbody> <?php // Fetch Comment record. $x=0; while (mysqli_stmt_fetch($stmt)){ //<!-- Row 1 --> echo ' <tr> <th scope="row" class="headerCol">'; echo $eventName . '<br />' . $eventLocation . '<br />' . $eventDate . ' </th> <td class="col2">' . $eventPrice . '<input type="hidden" name="eventCost[' . $x . ']" value="' . $eventPrice . '" /> </td> <td class="col3"> <select name="eventAttendees[' . $x . ']"> <option value="">--</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select> </td> <td class="col4">' . $eventCost*eventAttendees[$x] . '</td> <td class="col5"> <input name="eventChosen[' . $x . ']" type="submit" value="Buy Tickets" /> </td> </tr>'; } ?> </tbody> What I am trying to do/say on each row is "Take the Event Price and multiple it times the # of Attendees selected in the Row's Drop-Down field." Thanks, Debbie ok, i had some great help from this forum recently so i hope for the same outcome this time probably a rather easy question for most of you, i have a form that visitors use to input date using php (submission_date) in to db. date is then entered in db as a VARCHAR (i.e. Mar-15-2011), what i would like is to have another field which would calculate time elapsed. Since calculation can be only done on date not varchar ( i assume), i would need to have submission date also as a DATE and then passed on to a new field for calculating total time. does that make sense? lol I would really appreciate any pointers or help with this, not sure if im going in the right direction, but thats a start thank you! Aplogies for a very dumb question. Variables pulled from MySQL. $First = $First; $Last = $Last; $Member = array($Last, $First); This URL will sort by first name: www.mysite.com?sort=First ...will sort by last name: www.mysite.com?sort=Last How do I get it to sort by the complete array value? www.mysite.com?sort=Member ...not a valid MySQL result, obviously. ~Wayne |