-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
+1 You are going to have to change from mysql_* functions at some point. The sooner you change the less you will have to rewrite when they stop working completely (which will be when you upgrade to PHPv5.5 or later)
-
super slow relational query -- because: math
Barand replied to michaellunsford's topic in MySQL Help
I'd start by using an explicit join syntax and ensure that subscriberid was indexed in both tables and an index on the date field SELECT `name`, `email`, `subscribe_date`, FROM `subscriber` INNER JOIN `list` ON `subscriber`.`subscriberid` = -`list`.`subscriberid` WHERE `unsubscribe_date` = '0000-00-00 00:00:00' AND `confirmed` = 1 LIMIT 0, 20 -
As it is CHAR( 8 ) and not VARCHAR() I was wondering if the space padding would make a difference. I altered mine to be CHAR and it made no difference - still works without changing the query
-
The FIELD() function in the manuals is unchanged from v3.23 through to v5.7. There is a similar function FIND_IN_SET(). Any luck with that one? eg mysql> SELECT * FROM sort_test -> ORDER BY FIND_IN_SET(status,'open,rejected,closed'); +-------------+----------+ | idsort_test | status | +-------------+----------+ | 1 | open | | 4 | open | | 7 | open | | 2 | rejected | | 5 | rejected | | 8 | rejected | | 3 | closed | | 6 | closed | | 9 | closed | +-------------+----------+ How is "status" defined in your table?
-
Custom PHP calendar - Integer to Month String?
Barand replied to PHP Learner's topic in PHP Coding Help
Here's an alternative method <?php function makeCalendar($dateStart) { $dateEnd = new DateTime($dateStart->format('Y-m-t')); $dateEnd->modify('+1 days'); $dp = new DatePeriod($dateStart, new DateInterval('P1D'), $dateEnd); $calArray = array_fill(0,7,''); echo '<div class="month">'; echo "<h4>" . $dateStart->format('F Y') . "<h4>"; echo "<table border='1' style='border-collapse:collapse'>"; $days = array('Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'); echo "<tr><th>" . join('</th><th>', $days) . '</th></tr>'; foreach ($dp as $d) { $dow = $d->format('w'); $calArray[$dow] = $d->format('j'); if ($dow==6) { echo '<tr><td>' . join('</td><td>', $calArray).'</td></tr>'; $calArray = array_fill(0,7,''); } } if ($dow!= 6) echo '<tr><td>' . join('</td><td>', $calArray).'</td></tr>'; echo "</table></div>\n"; } ?> <html> <head> <style type="text/css"> th,td { width: 23px; font-family: sans-serif; font-size: 9pt; text-align: center; } h4 { font-family: sans-serif; font-size: 9pt; } div.month { float:left; width:24%; height: 180px; margin:0px 0px 7px 7px; } </style> </head> <body> <?php $dt1 = new DateTime('first day of this month'); $dp1 = new DatePeriod($dt1, new DateInterval('P1M'), 11); foreach ($dp1 as $month) { makeCalendar($month); } ?> </body> </html> -
works for me mysql> SELECT * FROM sort_test; +-------------+----------+ | idsort_test | status | +-------------+----------+ | 1 | open | | 2 | rejected | | 3 | closed | | 4 | open | | 5 | rejected | | 6 | closed | | 7 | open | | 8 | rejected | | 9 | closed | +-------------+----------+ mysql> SELECT * FROM monty.sort_test ORDER BY FIELD(status,'open','rejected','closed'); +-------------+----------+ | idsort_test | status | +-------------+----------+ | 1 | open | | 4 | open | | 7 | open | | 2 | rejected | | 5 | rejected | | 8 | rejected | | 3 | closed | | 6 | closed | | 9 | closed | +-------------+----------+ It shouldn't affect the sort but your query has no join condition on those tables
-
using checkbox[] array to update a string not working
Barand replied to jacko_162's topic in PHP Coding Help
Where is $submit being set? -
You had two occurrences of "WHERE" in the query. SELECT s.user_id , u.email FROM parts_tbl_users u INNER JOIN parts_tbl_shop s ON u.user_id = s.user_id WHERE s.trade_directory_id IN (12,25) I restructured the query layout and used table aliases to improve readability. I also used an explicit JOIN syntax to separate the query structure from the selection criteria in the WHERE clause.
-
Remove an element from a multi-dimensional array
Barand replied to BerbBrown's topic in PHP Coding Help
if they are string value 'VOID' foreach ($data as $arr) { $newdata[] = array_values(array_filter($arr, function($a){return $a != 'VOID';})); } $newdata = array_filter($newdata); -
List all users in a database in a drop-down menu
Barand replied to Willpool's topic in PHP Coding Help
Not surprising, you moved it all outside the loop echo "<select name='cpuser'>"; while($row = mysql_fetch_assoc($query)) { $users = $row['username']; echo "<option value='$users'>$users</option>" } echo "</select>"; -
What you need is WHERE trade_directory_id IN (12, 25) And don't hijack other peoples posts
-
here's my 0.02 worth <?php $rows = 5; $cols = 5; $bounds = array(0, 0, $cols-1, $rows-1); $dx = -1; $dy = 0; $dir = 0; $results = array_fill_keys(range(0,$rows*$cols-1),''); $x = $bounds[2]; $y = $bounds[3]; for ($i=1; $i<=$rows*$cols; $i++) { if ($i>1) { switch ($dir%4) { case 0: if ($x==$bounds[0]) { $dx = 0; $dy = -1; $bounds[3]--; $dir++; } break; case 1: if ($y==$bounds[1]) { $dx = 1; $dy = 0; $bounds[0]++; $dir++; } break; case 2: if ($x==$bounds[2]) { $dx = 0; $dy = 1; $bounds[1]++; $dir++; } break; case 3: if ($y==$bounds[3]) { $dx = -1; $dy = 0; $bounds[2]--; $dir++; } break; } $x += $dx; $y += $dy; } $pos = $y*$cols+$x; $results[$pos] = $i; } $output = array_chunk($results, $cols); echo "<table border='1'>\n"; foreach ($output as $row) { echo "<tr><td>" . join('</td><td>', $row) . "</td></tr>\n"; } echo "</table>\n"; ?>
-
Firstly, get rid of those ridiculous if() statements $age = 18; echo '$age'; // output the string $age echo $age; // output the value 18 So using single quotes the two are never equal. And if it did work, what is the point of testing if 18 = 18? The only relevant bit is the if($sex == 'All). As you have been told before, if all sexes are required then leave the "Sex" field out of the WHERE clause completely. Another thing you have been told is to use AND instead of OR in the WHERE clause. If you use OR you get all female plus any one in the district regardless of sex. Read the replies and you might get somewhere.
-
Move the WHERE conditions to the JOIN ON conditions for their respective table. WHERE on LEFT JOINed tables results in INNER JOIN behaviour $query1 = "SELECT DISTINCT Airline_Aircraft.airline_id , Airlines.airline_id , Airlines.name , Airline_Aircraft.besteld , Airline_Aircraft.aircraft_id , Aircraft_id1 , Aircraft.name1 , d7ul5_categories.id , d7ul5_categories.path , d7ul5_content.id , d7ul5_content.title , d7ul5_content.alias , d7ul5_content.state , d7ul5_content.catid FROM Airline_Aircraft LEFT JOIN Aircraft ON Airline_Aircraft.aircraft_id = Aircraft.aircraft_id1 LEFT JOIN Airlines ON Airline_Aircraft.airline_id = Airlines.airline_id AND Airlines.name = '$title_artikel' LEFT JOIN d7ul5_content ON Aircraft.name1 = d7ul5_content.title AND d7ul5_content.state = 1 LEFT JOIN d7ul5_categories ON d7ul5_content.catid = d7ul5_categories.id ORDER BY Aircraft.name1 ASC" ; Are you sure you need all LEFT JOINS? They are much slower than INNER JOINS and only required when there may not be a matching row in the joined table
-
$d1 = new DateTime('2013-12-25'); $dp = new DatePeriod($d1, new DateInterval('P1Y'), 7); foreach ($dp as $dt) { echo $dt->format('jS F Y') . '<br>'; } /* OUTPUT ***** 25th December 2013 25th December 2014 25th December 2015 25th December 2016 25th December 2017 25th December 2018 25th December 2019 25th December 2020 */
-
Which is the correct column name, "point" or "points"?
-
It is now working as normal again. !?!?
-
tried restarting Firefox - no effect.
-
Several of these: Unexpected value xMidYmid meet parsing preserveAspectRatio attribute. ...\["\\\/b-u]/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE]...
-
Because you were using mysql which is deprecated. I am using mysqli (as you should be)
-
you need to define the mysqli $db object first $db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); // use your credentials
-
-
try public function get_staff_current_month($staff_id) { $db = new sql(); $sql = "SELECT SUM(amount) as total FROM $this->tablename WHERE staff_id = $staff_id AND YEAR(date_added) = YEAR(CURDATE()) AND MONTH(date_added) = MONTH(CURDATE()) ORDER BY id ASC"; $db->query($sql); $row = $db->fetch_array(); return $row['total']; } Create the connection to the database once. Pass it as a parameter to the functions that need it
-
try $sql = "SELECT colno, num, COUNT(*) AS CT FROM ( SELECT 1 as colno, Number1 as num FROM Draws UNION ALL SELECT 2 as colno, Number2 as num FROM Draws UNION ALL SELECT 3 as colno, Number3 as num FROM Draws UNION ALL SELECT 4 as colno, Number4 as num FROM Draws UNION ALL SELECT 5 as colno, Number5 as num FROM Draws UNION ALL SELECT 6 as colno, Number6 as num FROM Draws ) as balls GROUP BY colno, num ORDER BY num, colno"; echo "<h3>Frequency table</h3> <table border='1' style='border-collapse:collapse'> <tr><th></th><th>Number1</th><th>Number2</th><th>Number3</th><th>Number4</th><th>Number5</th><th>Number6</th></tr>\n"; $res = $db->query($sql); $currNum = 0; while (list($col,$num,$ct) = $res->fetch_row()) { if ($num != $currNum) { if ($currNum) { echo "<tr><th>$currNum</th><td>" . join('</td><td>',$freqs) . "</td></tr>\n"; } $freqs = array_fill_keys(range(1,6),0); $currNum = $num; } $freqs[$col] = $ct; } echo "<tr><th>$currNum</th><td>" . join('</td><td>',$freqs) . "</td></tr>\n"; echo "</table>\n"