PHP - Counting Instances And Then Displaying A Result.
Hi
I am building a product search engine using MySql and PHP (Jquery / AJAX). As i am getting the search results i wondered is it possible to count the instances of a category? For example: If i search for "Dell Laptops" i get 400+ results back because it has lots of laptops and accessories. What i am aiming for it to do is while looping through look at the categories and if its the first instanc eof it i want it to begin a count. until it has finished looping and then i can display it. Results: 436 [ Laptops(127) - Accesories (244) - Components(65) ] Im not even sure where to start here so any advice will be helpful Here is the code im using to generate the search: $id = str_replace(" ", "%", "$id"); $q = "SELECT * FROM products WHERE prod_name LIKE '%$id%' order by fee asc LIMIT 20"; Similar TutorialsPHP/MYSQL - - - Thank you in advance for any help. Quick question. I am calc'ing whether each line db output is a win/loss/tie below. Outputting $res in each line. Is there a simple way to COUNT the number of instances where $ res = "win" or loss or tie? I'd like to put an "overall" record at the top of the output. For example, for a given query, this chosen team's record is x WINS, Y Losses, Z TIES. Win/Loss/Tie is NOT a field in the db table. I know how to pull the total # of records pulled, but not this. Example User pulled a certain team to see game scores. 7 - 3 - 2 is their record. is what i'm trying to figure out Game Result Score Score opp Date game10 WIN * 7 2 blah game11 LOSS* 2 3 .... .... Code: [Select] //winloss begin works * above is a result of this code if ($row['sch_uba_score'] > $row['sch_opp_score']) $res = 'Win'; elseif ($row['sch_uba_score'] < $row['sch_opp_score']) $res = 'Loss'; else $res = 'Tie'; // winloss end works I am using this code to search my database plus it has a paginate which all works fine. The problem is i have a row count which for some reason counts all records in the database and not just the ones returned from the search query. How to i fix this. Code: [Select] $term = $_GET['term']; $cat = $_GET['cat']; //max display per page $per_page = 4; //get start variable $start = $_GET['start']; // cout records $record_count = mysql_num_rows(mysql_query("SELECT * FROM Table WHERE productname like '%$term%' and category like '%$cat%'")); //count max pages $max_pages = $record_count / $per_page; //may count as decimal if (!$start) $start =0; $sql="SELECT * FROM table WHERE productname like '%$term%' and category like '%$cat%' LIMIT $start, $per_page"; $result = mysql_query($sql); $sql = mysql_query ("SELECT COUNT(*) FROM table"); list($number) = mysql_fetch_row($sql); if (!mysql_num_rows($result)) { die("NO RECORD FOUND") ; exit; } else { echo "Your Search for: <b>$term</b> in <b>$cat</b><br><br>"; } while ($row = mysql_fetch_array($result)){ $num_rows = mysql_num_rows($number); if (!$i++) echo "Total records $number"; ?> <br /> <br /> <?php echo 'ID: '.$row['id']; ?> <br /> <?php echo '<br/> Product Name: '.$row['productname'];?> <br /> <?php echo '<br/> Price: '.$row['price']; ?><br /> <?php echo '<br/> category: '.$row['category']; ?> <br /> <?php } ?> <?php //setup prev and next variables $prev = $start - $per_page; $next = $start + $per_page; // show prev button if(!($start<=0)) echo " <a href='ttr.php?start=$prev'>Prev </a>"; //set var for first page $i=1; for ($x=0;$x<$record_count;$x=$x+$per_page) { if ($start!=$x) echo "<a href='ttr.php?start=$x'>$i</a> "; else echo "<a href='ttr.php?start=$x'><b>$i</b></a> "; $i++; } //show next button if (!($start>=$record_count-$per_page)) echo " <a href='ttr.php?start=$next'>Next</a>"; ?> Alright, I need to find a way to display the top ten duplicated rows for a table in my database. I have tried multiple methods but I have failed. Can you please assist me with this problem. I currently run a query in phpmyadmin to get the result, but i cant figure out how to properly code the php script. i have it set up so the user picks the year and session and then the database shows all the games in that specific year and session and then displays them with a link to their photo galleria and also shows the record(wins - losses - ties) but the way i have it know its not displaying the first result here is the code Code: [Select] <?php //declares $y as year played and $s as session $y = ' '; $s = ' '; //handles submition of form for picking year and session if (isset($_POST['submit'])) { $data = mysql_real_escape_string($_POST['session']); $exploeded = explode(",", $data); $y = $exploeded[0]; $s = $exploeded[1]; } //Query for the selection menu $squery = "SELECT DISTINCT(Year_Played), Sessions FROM pinkpanther_games"; $sresults = mysql_query($squery) or die("squery failed ($squery) - " . mysql_error()); //checks $y and $s to see if their is a vaule if ($y == ' '){$y = '20112012';} if ($s == ' '){$s = '2';} //Query for getting record and for getting all the appropriate info for displaying the games $query = " SELECT (SELECT COUNT(id) FROM pinkpanther_games WHERE Year_Played = $y AND Sessions = $s AND Win_Loss = 'Tie' ) AS 'Tie', (SELECT COUNT(id) FROM pinkpanther_games WHERE Year_Played = $y AND Sessions = $s AND Win_Loss = 'Win') AS 'Win', (SELECT COUNT(id) FROM pinkpanther_games WHERE Year_Played = $y AND Sessions = $s AND Win_Loss = 'Loss') AS 'Lose', Opponent AS Opponent, Score AS Score, Gallery_no AS Gal, Win_Loss AS Record FROM pinkpanther_games WHERE Year_Played = $y AND Sessions = $s"; $results = mysql_query($query) or die("Query failed ($query) - " . mysql_error()); $row_a = mysql_fetch_assoc($results); //Set record variables $wins = $row_a['Win']; $loss = $row_a['Lose']; $tie = $row_a['Tie']; //creates from and selection menu for year and session echo "<tr><td colspan='2'><form method='post' action=''><select name='session' class='txtbox2'>"; while ($srow = mysql_fetch_assoc($sresults)){ echo "<option value='" . $srow['Year_Played'] . "," . $srow['Sessions'] . "'>" . $srow['Year_Played'] . " Session " . $srow['Sessions'] . "</option>"; } echo "</select><input type='submit' name='submit' value='Go' class='txtbox2' /></form></td></tr>"; //displays record echo "<tr><td colspan='2'>" .$wins . " - " . $loss . " - " . $tie . "</td></tr>"; echo "<tr></tr>"; //displays games and scores in appropriate year and session while ($row = mysql_fetch_assoc($results)){ $opp = $row['Opponent']; $score = $row['Score']; $gal = $row['Gal']; $wlt = $row['Record']; //styles games acording to if win lose or tie if ($wlt == 'Win'){ echo "<tr><td class='win'>"; echo "<a href='galleries.php?g=$gal'" . $gal . " >" . $opp . "</a>"; echo "</td><td class='win'>"; echo $score . ""; echo "</td></tr>"; } if ($wlt == 'Loss'){ echo "<tr><td class='loss'>"; echo "<a href='galleries.php?g=$gal'" . $gal . " >" . $opp . "</a>"; echo "</td><td class='loss'>"; echo $score . ""; echo "</td></tr>"; } if ($wlt == 'Tie'){ echo "<tr><td class='tie'>"; echo "<a href='galleries.php?g=$gal'" . $gal . " >" . $opp . "</a>"; echo "</td><td class='tie'>"; echo $score . ""; echo "</td></tr>"; } } ?> i cannot figure out why my first result is not displaying properly it successfully shows all results but me first myurl.com/other.php?id=2 now showing any thing kindly help to solved this problem! it seems like problem is in variable $http$ids but dunno how to combine them to get result $Ids always b numeric number <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $http = "myurl.com/other.php?id=" ; $conn=odbc_connect('greeting','',''); if (!$conn) {exit("Connection Failed: " . $conn);} $sql="SELECT * FROM mytable"; $rs=odbc_exec($conn,$sql); if (!$rs) {exit("Error in SQL");} echo "<table border= 1><tr>"; echo "<th>ID</th>"; echo "<th>Like</th>"; echo "<th>title</th></tr>"; while (odbc_fetch_row($rs)) { $ids=odbc_result($rs,"ID"); $title=odbc_result($rs,"title"); echo "<tr><td>$ids</td>"; echo "<td><fb:like href=\"$http$ids\" layout=\"button_count\" show_faces=\"false\" width=\"100\" font=\"tahoma\" colorscheme=\"dark\"></fb:like> </td>"; echo "<td>$title</td></tr>"; } echo "</table>"; odbc_close($conn); ?> Hi! I want the image of my site to be clickable so that it shows the next image contained in the result set of the sql query. Code: [Select] <?php require_once('includes/connection.inc.php'); $conn = dbConnect(); $sql = 'SELECT filename FROM images ORDER BY image_id DESC LIMIT 1'; $msg = ''; if(!$sql) { echo "Something went wrong with the query. Please try again."; } $result = $conn->query($sql) or die(mysqli_error()); if(mysqli_num_rows($result) == 0) { header('Location: empty_blog.php'); $conn->close(); } else { $row = $result->fetch_row(); $image = $row[0]; } ?> <?php include('header.php'); ?> <div class="content main"> <img id="image" src="images/<?php echo $image; ?>"/> </div> <?php include('includes/footer.inc.php'); ?> All the filenames of the images are contained correctly in the $result variable, all I need to do now is to fetch the next image in the set. How would I go about this? Any help is greatly appreciated! Hello! I am busy developing a script that returns all users that have the cell "Available" set to 1 but I am unsure how to do this, I am familiar with basic SQL and I have made this: $sql = "SELECT * FROM `clans` WHERE `available` =1 LIMIT 0 , 30"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo ($row['name']); but it only displays information from the first row found, and I want it to display all the rows found, how can I do this? Thanks - GreenFanta Hi, I am new to php but not to programming. I created a script on a windows platform which connects to the mysql database and returns the results of a table. A very basic script which I wrote to simply test my connection worked. The script works fine on my windows machine but not on my new mac. On the mac it simply does not display any records at all. I know that the database connection has been established because there is no error but I can not see why the result set is not being displayed on screen, as I said it worked fine on my windows machine. The Mac has mysql (with data) and apache running for php. Please could someone help as I have no idea what to do now? Script below: Code: [Select] $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'root'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'test'; mysql_select_db($dbname); mysql_select_db("test", $conn); $result = mysql_query("SELECT * FROM new_table"); while($row = mysql_fetch_array($result)) { echo $row['test1'] . " " . $row['test2'] . " " . $row['test3']; echo "<br />"; } mysql_close($con); This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=330221.0 Hello all,
Am trying to calculate some data and display the result of the current month in a chart form. i just don't know how to get the current month. this is not working..
<?php include('mysql_connect.php'); $date = 'MONTH(CURRENT_DATE())'; $status = 'paid'; //mysql_select_db("hyprops", $con); $query = mysql_query("SELECT sum(amount) 'amount', department FROM requisition WHERE status = '$status' AND date='$date' "); $category = array(); $category['name'] = 'department'; //$series1 = array(); //$series1['name'] = 'actual'; $series2 = array(); $series2['name'] = 'amount'; //$series3 = array(); //$series3['name'] = 'Highcharts'; while($r = mysql_fetch_array($query)) { $category['data'][] = $r['department']; // $series1['data'][] = $r['actual']; $series2['data'][] = $r['amount']; // $series3['data'][] = $r['highcharts']; } $result = array(); array_push($result,$category); //array_push($result,$series1); array_push($result,$series2); //array_push($result,$series3); print json_encode($result, JSON_NUMERIC_CHECK); mysql_close($con); ?>Please how can i solve this issue? Thanks in advance Hello - Suppose I had a MySQL result set that was something like this: ITEM: COLOR: ball red ball blue book red book green book black If I were to use the code: Code: [Select] do { echo $row_myQuery['item'] . " - " . echo $row_myQuery['color'] . "<br />"; } while ($row_myQuery= mysql_fetch_assoc($myQuery)); Then I end up with this: Code: [Select] ball - red ball - blue book - red book - green book - black MY QUESTION: What I'd like to know is, how could I re-write that php code so that I could get an output like this?: Code: [Select] ball - red, blue book - red, green, black Thanks! I have a loop creating a block_vars array for displaying records from a database. (In this case auction listings). The following code creates this array: // get random selection of 6 items for home page display $query = "SELECT id, title, current_bid, pict_url, ends, num_bids, minimum_bid, bn_only, buy_now, subtitle, starts, ends, reserve_price FROM " . $DBPrefix . "auctions WHERE closed = 0 AND suspended = 0 AND starts <= " . $NOW . " ORDER BY RAND() DESC LIMIT 6"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); $showendtime = false; $has_ended = false; $k = 0; while($row = mysql_fetch_assoc($res)) { $ends = $row['ends']; $difference = $ends - time(); if ($difference > 0) { $ends_string = FormatTimeLeft($difference); } else { $ends_string = $MSG['911']; } $high_bid = ($row['num_bids'] == 0) ? $row['minimum_bid'] : $row['current_bid']; $high_bid = ($row['bn_only'] == 'y') ? $row['buy_now'] : $high_bid; //determine whether the auction has a Buy Now price, show if appropriate. if($row['buy_now'] == '0.0000') { $bnamount = ""; } else { $bnamount = "<a href='" . $system->SETTINGS['siteurl'] . "buy_now.php?id=" . $row['id'] ."'>$" . substr($row['buy_now'], 0, -2) . "<br />" . "Buy Now</a>"; } //determine if the auction has a reserve set and if it has been met. display appropriate symbol if($row['reserve_price'] == '0.0000' && $row['bn_only'] == 'n' && ($row['current_bid'] < $row['minimum_bid'])) { $flag = '<img src="images/noreserve.gif" alt="No Reserve">'; $flagdesc = " No Reserve!"; $bnonly = "Current Bid<br />"; } else { if($row['current_bid'] >= $row['reserve_price']) { $flag = '<img src="images/reservemet.gif" alt="Reserve Met">'; $flagdesc = " Reserve Met!"; $bnonly = "Current Bid<br />"; } else { $flag = '<img src="images/noflag.gif">'; $flagdesc = ""; $bnonly = "Current Bid<br />"; } } if($row['reserve_price'] == '0.0000' && $row['bn_only'] == 'y') { $flag = '<img src="images/noflag.gif">'; $flagdesc = ""; $bnonly = "Asking Price "; $bnamount = ""; } $template->assign_block_vars('randomitems', array( 'ID' => $row['id'], 'BID' => $bnonly . "$" . substr($high_bid, 0, -2), 'IMAGE' => (!empty($row['pict_url'])) ? 'getthumb.php?w=' . $system->SETTINGS['thumb_show'] . '&fromfile=' . $uploaded_path . $row['id'] . '/' . $row['pict_url'] : 'images/email_alerts/default_item_img.jpg', 'TITLE' => $row['title'], 'BUY_NOW' => $bnamount, 'SUBTITLE' => $row['subtitle'], 'TIMELEFT' => $ends_string, 'NUMBIDS' => $row['num_bids'], 'FLAG' => $flag, 'FLAGDESC' => $flagdesc )); $k++; } Pretty straightforward. You will see I have a TIMELEFT value which will show on my home page as no.days, no.hours, no.mins until it closes etc. Here is the html in the tpl file: Code: [Select] <!-- BEGIN randomitems --> <div style="float:left;display:block;width:99%;border-bottom:#CCCCCC 1px solid;padding:2px;"> <div style="display:block;"> <table width="100%"> <tr> <td align="center" style="vertical-align:middle;width:120px" > <a href="{SITEURL}item.php?id={randomitems.ID}"><img src="{randomitems.IMAGE}" alt="{randomitems.TITLE}" style="border: none;width:120px"></a> </td> <td align="left" width="40%"> <table style="width:100%; vertical-align:middle; margin:0 auto"> <tr> <td><a id="itemdesc" href="{SITEURL}item.php?id={randomitems.ID}">{randomitems.TITLE}</a><br /> {randomitems.SUBTITLE}</td> </tr> <tr> <td id="closes">Closes in:{randomitems.TIMELEFT}</td> </tr> <tr> <td>{randomitems.FLAG}{randomitems.FLAGDESC}</td> </tr> </table> </td> <td id="buynow" align="center" width="15%"> {randomitems.BUY_NOW} </td> <td id="currentbid" align="center" width="25%"> {randomitems.BID} </td> </tr> </table> </div> </div> <!-- END randomitems --> This works quite nicely for me. What I want, and cannot manage thus far is to have the TIMELEFT value count down. The closest I have come is using a function like this: Code: [Select] <script type="text/javascript"> $(document).ready(function() { var currenttime = '{randomitems.TIMELEFT}'; function padlength(what) { var output=(what.toString().length == 1)? '0' + what : what; return output; } function displaytime() { currenttime -= 1; if (currenttime > 0){ var hours = Math.floor(currenttime / 3600); var mins = Math.floor((currenttime - (hours * 3600)) / 60); var secs = Math.floor(currenttime - (hours * 3600) - (mins * 60)); var timestring = padlength(hours) + ':' + padlength(mins) + ':' + padlength(secs); $("#ending_counter").html(timestring); setTimeout(displaytime, 1000); } else { $("#ending_counter").html('<span class="errfont">{L_911}</span>'); } } setTimeout(displaytime, 1000); }); </script> This code is placed in the tpl file and I simply give an html element the appropriate ID. The problem with this is that it would only show a countdown timer for the first item returned, which is no good as there are always six items returned. Can anyone offer a suggestion on how I could go about this? I can PM anyone with suggestions with a link to my development site so you know what I am raving about. I'm trying to get a count of how many topics someone starts in a forum. I use XenForo, and they only count Posts, but I can order Posts by post_id and group those posts by thread_id to determine the initial instance of that topic. The problem I'm having is output. I'm getting the right User info, but the output is offset by one row: User 1 | 0 topics (because $c=0) User 2 | 128 topics (but those are User 1's #) User 3 | 0 topics (but those are User 2's #) User 4 | 141 topics (but those are User 3's #) etc
I realize as I play through the logic of the code, it's printing in that order. I can't seem to get the right order. I've tried various ways, with a couple of extra IF statements in there too.
$query = "select thread_id,user_id,username from ( select * from xf_post order by post_id ) x group by thread_id order by username,thread_id"; $results = mysqli_query($con,$query); echo mysqli_error($con); $c=0; $currentID = false; while($line = mysqli_fetch_assoc($results)) { if ($currentID != $line['user_id']) { echo '<div>' . $line['username'] . ', ' . $c; $currentID = $line['user_id']; $c=0; } else { $c++; } }
I am using mod_php with Apache/2.4.6 (CentOS). I currently do not have multiple versions of PHP running on my server, but wish to do so now. Will I need to use php-fpm? Even if multiple instances can be accomplished with mod_php, is it typically preferred to use php-fpm? Any unusual gotcha's that I should be aware of? Will I need to uninstall mod_php before installing php-fpm? I previously used remi-php73 repo. Better to install from source? Thanks Edited August 25, 2019 by NotionCommotionI 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? We have a 10 year old system that has 100's of php files that all connect to a central database using a single shared php include file that does a mysql_connect before any other code executes
include_once("db_connect.php");
mysql_query(...);
We never used the returned connection id (link identifier) from the mysql_connect function call as it was always implied in every subsequent mysql_query statement etc.
Now we've moved some of our bigger tables to a separate server, so we have to update small areas of some files that need to connect to this other system and send the old existing query to the new server instead of to the main server and process the results
So, going back through hundreds of files and converting mysql_query($string) to mysql_query($string, $connection1) is not practical
Possible solution one: anytime I need to use the new server I do this
------------------------------------------------------------------------------
mysql_connect(NEW_SERVER_IP,"...",""");
mysql_query($string);
...
// get back to normal
mysql_connect(OLD_SERVER_IP,"...","");
Possible solution two: modify the master include file
------------------------------------------------------------------------------
//add a new line ABOVE the existing mysql_connect statement...
$new_server=mysql_connect(NEW_SERVER_IP,"...",""");
mysql_connect(OLD_SERVER_IP,"...","");
and then anytime I need to use the new database I have to go back and modify all of the mysql_query,mysql_affected_rows, etc to reference the $new_server link identifier
solution one seems much simpler, but all of the mysql_connect reconnections I assume will be extremely inefficient
solution two seems cleaner but if I miss one mysql_ statement that needs the new connection object as a reference, the code will completely break or worse yet it will produce unexpected results
Example: If I miss converting a mysql_errno() function that really needs to now be mysql_errno($new_server) it would cause major issues.
So, I'm wondering if others have faced this dilema of migrating single mysql_connect code to multi mysql_connect mode and if there is a better way of going about implementing it.
Thanks in advance for any help
Steve
I'm pretty sure this is really simple to do using the count function, but I am having a hard time finding examples on how to count the number of times a "SPECIFIC" word occurs in a file. For example, I just want to display how many times "this-word" occurs in "http://www.mysite.com/logfile.log". Any help would be appreciated. Hi guys, For a project I made sort of a custom cron database. Database has 4 columns: ID (auto increment), TaskID, DateTime, Locked. I'm running a 1 minute cron in the form of a php script. The script itself starts with a query that loads a task with 'Locked != 'Y' and DateTime < NOW( ). It then locks the task (by flagging the 'Locked' field in the db) and launches another script that finishes it. That last script deletes the task when finished from the cron database. Problem is, at certain peek hours, the system would get laggy, there'd be a bunch of tasks stacking up and it would get behind on the schedule. In order to combat that, I made an extra 1 minute cron, launching the same script. Now, my problem: mysql is too slow In principle, there shouldn't be any problem: all tasks picked up by either instance of the script would be locked so the other instance wouldn't be able to pick up the same task. The problem occurs when both instances are booted at the same time (well, one after the other but with a minuscule time difference between them) and they both at the same time run the query to get a 'free' task from the database: the system will give them both the same task before either of the script instances has the time to lock it up. I'm trying to think of some solutions but I'd like your feedback on what solution would be best. - Putting an exclusive lock on the php file is not an option for me since I still want to run the script, I just need it to pick up an exclusive task. - Other option: having the script open with a random sleep of (1, 10) seconds, it will have the script instances pick up a task at a different time, giving the other instance time to lock it up. Obvious disadvantage: I'm losing time. - Using a file as a flag. Set a directory and create a file in it. Check if this is the only file in the dir, if yes: start right away. Otherwise: go to sleep for 2 seconds (should be plenty of time to run 2 queries in the other instance). What is the fastest method of doing a directory scan though, glob()? My question: what's the fastest/best way to solve this? Thanks! I have an array that looks like this:
array(5642) { [0]=> string(19) "2021-02-10 09:04:48" [1]=> string(19) "2021-02-10 09:04:54" [2]=> string(19) "2021-02-10 09:05:00" [3]=> string(19) "2021-02-10 09:05:06" [4]=> string(19) "2021-02-10 09:05:12" [5]=> string(19) "2021-02-10 09:05:18" [6]=> string(19) "2021-02-10 09:06:18" [7]=> string(19) "2021-02-10 09:06:24" }
I need to group the instances any time there is more than a 6 second gap between elements. So 0 =>5 would be one array and 6 and 7 would be a new array.
Ive been able to produce the following but its not ideal
array(5642) { [0]=> string(19) "2021-02-10 09:04:48" [1]=> string(19) "2021-02-10 09:04:54" [2]=> string(19) "2021-02-10 09:05:00" [3]=> string(19) "2021-02-10 09:05:06" [4]=> string(19) "2021-02-10 09:05:12" [5]=> string(19) "2021-02-10 09:05:18" [6]=> string(19) "end" [7]=> string(19) "2021-02-10 09:06:18" [8]=> string(19) "2021-02-10 09:06:24" }
$burner_time = array(); foreach($Burner_Control_Alm as $new_burner){ $burner_time[] = strtotime($new_burner); } $repl = 'end'; for ($i=1; $i<count($burner_time); $i++) { $value_second = $burner_time[$i]; $value_first = $burner_time[$i-1] === $repl ? $burner_time[$i-2] : $burner_time[$i-1]; if ($value_second > $value_first + 6) { array_splice($burner_time, $i++, 0, $repl); } print_r($burner_time); } I have a table in my database named order, and i want to count the quantity sold. i have the basic query already setup like: Code: [Select] $sql = "SELECT SQL_CALC_FOUND_ROWS deal.id, deal.title, deal.min_qty, deal.start_date, deal.end_date, deal.status, deal.secondary, count(o.id) as orders_cnt FROM deals as deal LEFT JOIN orders as o on o.d_id = deal.id WHERE start_date >= '".$beg."' AND start_date <= '".$end."' GROUP BY o.d_id, deal.id ORDER BY start_date LIMIT ".AwsPager::getCurrentIndex().", ".AwsPager::getLimit(); Which would theoretically work, but in the orders table, there is a column named quantity, and its those numbers that i need to add together and store in the array as orders_cnt.. any clue how i can do that? |