-
Posts
24,565 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
I am assuming you data looks something like this mysql> SELECT * FROM goal; +---------+-----------+------+-------+------+--------------+ | goal_id | season | day | month | year | goals_scored | +---------+-----------+------+-------+------+--------------+ | 1 | 2002-2003 | 1 | 8 | 2002 | 5 | | 2 | 2002-2003 | 31 | 10 | 2002 | 8 | | 3 | 2002-2003 | 1 | 11 | 2002 | 9 | | 4 | 2002-2003 | 31 | 1 | 2003 | 4 | | 5 | 2002-2003 | 1 | 2 | 2003 | 8 | | 6 | 2002-2003 | 30 | 4 | 2003 | 10 | | 7 | 2002-2003 | 1 | 5 | 2003 | 9 | | 8 | 2002-2003 | 31 | 7 | 2003 | 12 | | 9 | 2003-2004 | 10 | 8 | 2003 | 15 | | 10 | 2003-2004 | 5 | 11 | 2003 | 10 | | 11 | 2003-2004 | 1 | 7 | 2004 | 6 | +---------+-----------+------+-------+------+--------------+ Set up a second table to define which months are in each quarter mysql> SELECT * FROM quarter; +------------+---------+-------+ | quarter_id | quarter | month | +------------+---------+-------+ | 1 | Q1 | 8 | | 2 | Q1 | 9 | | 3 | Q1 | 10 | | 4 | Q2 | 11 | | 5 | Q2 | 12 | | 6 | Q2 | 1 | | 7 | Q3 | 2 | | 8 | Q3 | 3 | | 9 | Q3 | 4 | | 10 | Q4 | 5 | | 11 | Q4 | 6 | | 12 | Q4 | 7 | +------------+---------+-------+ Then you can run a query to get your quarter totals SELECT g.season , q.quarter , SUM(g.goals_scored) as goals FROM goal g INNER JOIN quarter q USING (month) GROUP BY season, quarter Giving +-----------+---------+-------+ | season | quarter | goals | +-----------+---------+-------+ | 2002-2003 | Q1 | 13 | | 2002-2003 | Q2 | 13 | | 2002-2003 | Q3 | 18 | | 2002-2003 | Q4 | 21 | | 2003-2004 | Q1 | 15 | | 2003-2004 | Q2 | 10 | | 2003-2004 | Q4 | 6 | +-----------+---------+-------+
-
Mysql column to array with batches what am I doing wrong?
Barand replied to cobusbo's topic in PHP Coding Help
jcbones, check out array_chunk cobusbo, Shouldn't you be sending $list in the send__message and not $batches -
You are already inside a PHP block (shown in blue) so the red elements should not be there. You need to echo the <option> line echo "<option value='$row[0]'>$row[1] $row[2]</option>"; // assuming $row[0] is the attendee id Don't use "select * ", specify just the three columns you need
-
Which table is which in your query? Which field identifies a site? Should you be grouping by url, perhaps? If you are joining on link_id, why is it text type in one table and int in the other?
-
What are you table structures. SELECT * obscures everything as well as being inefficient
-
In that case you need ... GROUP BY site_id
-
The query syntax is correct but I don't believe that is what you want. COUNT(link_id) with GROUP BY link_id will give every count total = 1. But as I said, there is no way of my knowing exactly what you are trying to achieve.
-
That single line on its own will not do what you say it does. You need to read the content into variable, increment it put the content back. It will be text but php's automatic type conversion will allow you to process it as int. What's wrong with a db table? All you need then is UPDATE mycounts SET count=count+1 WHERE button = 'A'
-
how to handle errors in mysqli prepared statements efficiently
Barand replied to ajoo's topic in PHP Coding Help
Better to assume that if something could wrong then, at some time, it will and handle such errors gracefully in your code. if you set report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT; then exceptions will be thrown try { $query = "SELECT Id, User, Pass, FROM $table WHERE User = ?"; $stmt = $con->prepare($query); $stmt->bind_param('s',$user); $stmt->execute(); $stmt->bind_result($db_id,$db_user,$db_pw); $stmt->fetch(); } catch (Exception $e) { // handle errors } -
how to handle errors in mysqli prepared statements efficiently
Barand replied to ajoo's topic in PHP Coding Help
In production you would turn off error display and turn on error logging instead. -
Use SQL function SUM(). Can't tell you much more from what you've given us.
-
how to handle errors in mysqli prepared statements efficiently
Barand replied to ajoo's topic in PHP Coding Help
Is the concept of "testing" alien to you? -
how to handle errors in mysqli prepared statements efficiently
Barand replied to ajoo's topic in PHP Coding Help
or you could $mysqli_driver = new mysqli_driver(); $mysqli_driver->report_mode = MYSQLI_REPORT_ERROR; $con = new mysqli(HOST, USERNAME, PASSWORD, DATABASE); $query = "SELECT Id, User, Pass, FROM $table WHERE User = ?"; $stmt = $con->prepare($query); $stmt->bind_param('s',$user); $stmt->execute(); $stmt->bind_result($db_id,$db_user,$db_pw); $stmt->fetch(); -
php function to show value of one table column from another table column
Barand replied to HalRau's topic in PHP Coding Help
You should be using mysqli or PDO functions and not the deprecated mysql function. You don't show your first query but piecing together what I can see it shou look something like this $db = new mysqli(HOST, USERNAME, PASSWORD, DATABASE); $sql = "SELECT sub_lastname , sub_firstname , sub_address , sub_city , sub_state , sub_zip , sub_paidbycheck , sub_tranxID , sub_payment_amount , sub_nopaper , sub_date , d.amount as donation FROM subscriber s LEFT JOIN dc_donations d ON d.transaction_id = s.sub_tranxID "; $smt = $db->prepare($sql); $smt->execute(); $smt->bind_result($ln,$fn,$add,$cty,$state,$zip,$pbc,$stid,$amt,$nopaper,$date,$donation); while ($smt->fetch() ) { $chk_pbc = $pbc==1 ? 'checked="checked"' : ''; $chk_nop = $nopaper==1 ? 'checked="checked"' : ''; echo "tr> <td>$ln,$fn,$add,$cty,$state,$zip<td> <td><input $chk_pbc name='Sub_paidbycheck' type='checkbox' value='1'></td> <td>$amt</td> <td>$stid</td> <td>$donation</td> <td>$date</td> <td><input $chk_nop name='Sub_nppaper' type='checkbox' value='1'></td> <td> </td> </tr>"; } ?> -
php function to show value of one table column from another table column
Barand replied to HalRau's topic in PHP Coding Help
I don't see where you attempt to output the amount anywhere in that code . And instead of a second query to get the amount you should be using a JOIN in the original query -
To execute php, rename "thankyou.html" to "thankyou.php"
-
php function to show value of one table column from another table column
Barand replied to HalRau's topic in PHP Coding Help
you are missing the ; from end of 223 -
That's right. Each subscriber record would contain circle_id subscriber_id Make the primary key (circle_id, subscriber_id) then you can't add the same subscriber twice for a circle. To add a new subscriber for a circle you then just add a record to this table which is a lot easier than what you were trying to do originally.
-
Need Help generating an answer for a guessing game
Barand replied to Harasume's topic in PHP Coding Help
Should of! Evidently should have gone to English class more -
In a relational database you don't store multiple delimited values in a single column, you normalize your data and problems like this go away. http://forums.phpfreaks.com/topic/273634-best-way-to-set-up-tables-when-multiple-values/?do=findComment&comment=1408360
-
Are you passing $previous time as a string value to your function? Your code expects a DateTime object. Hint: $today = new DateTime(); will give the current date time without any argument.
-
You read the answers to the same question you have just asked in another topic http://forums.phpfreaks.com/topic/294924-how-to-find-duplicates/?do=findComment&comment=1506922
-
You need to put the string inside double quotes to expand variable values echo "<td><a href='showthumb.php?thumb=$clientthumb'><img src='{$row['thumb']}' /></a></td>"; see http://php.net/manual/en/language.types.string.php
-
This how you might use levenshtein. As in the last result you could get false positives but you could probably lessen the occurence by taking zip into account also. mysql> SELECT * FROM table1 ORDER BY address; +----+-------------------------+ | id | address | +----+-------------------------+ | 4 | 100 main st suite 100 | | 3 | 100 main street ste 100 | | 2 | 1000 somewhere St | | 1 | 1000 somewhere Street | | 5 | 150 Granby Avenue | | 6 | 206 Station Road | | 7 | 306 Station Road | +----+-------------------------+ $threshold = 6; // change to alter the sensitivity $results = array(); $sql = "SELECT id, address FROM table1 ORDER BY address"; $res = $db->query($sql); $prev = $previd = ''; while (list($id, $add) = $res->fetch_row()) { if (levenshtein($prev,$add) <= $threshold) { $results[] = array( $previd=>$prev, $id=>$add ); } $prev = $add; $previd = $id; } echo '<pre>',print_r($results, true),'</pre>'; Results Array ( [0] => Array ( [4] => 100 main st suite 100 [3] => 100 main street ste 100 ) [1] => Array ( [2] => 1000 somewhere St [1] => 1000 somewhere Street ) [2] => Array ( [6] => 206 Station Road [7] => 306 Station Road ) )