-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
So there are. Guess we need clarification from Webdev. Could do with some regarding what he's actually trying to do too. I confess to being confused about his requirements. So far I am assuming he is looking for repetitions of 3 balls drawn in sequence
-
If I were a DBA I'd prefer all the tools that come SQL Server. As a developer I prefer a DBMS built by developers for developers viz. MySQL. For example, SQL Server's date handling functions are not a patch on the datetime function library that MySQL provides. In practice I've also found MySQL to to be much faster than SQL Server. For example a database with millions of records of bus times at all bus stops throughout Greater Manchester plus dozens of other joined tables. The application retrieved the times of all buses in the next hour from local stops. In a city centre there are many dozen local stops. With SQL Server the search radius had to be limited to 100 metres to stop it timing out (30 secs). With MySQL it would happily search a radius of 5km retrieving data for hundreds of stops. For a front end for server admin you can download MySQL Workbench for free. My 0.02 worth
-
I'm assuming the first on each row is the ID
-
SELECT A , B, '' as C FROM table1 UNION SELECT '', '', C FROM table2
-
Update is inserting information into wrong id
Barand replied to AshleighCo's topic in PHP Coding Help
I don't see session_start() at top of the update page. -
You could select 21 fields in each select statement, defining their names with column aliases in the first select and aligning them with the blank fields in the others
-
As I said, you have one continuous result set. The ten column names in the result set are not suddenly going to change part way through the results. So, for example, as MANU_name is in the first column selected in that SELECT clause it will be in $row['CUST_ID'] as that will be the name of the first column in the results. There will be no $row['MANU_name'] and that goes for others too.
-
A union of two or more queries returns a continuous result set from those queries. Therefore the individual queries must retrieve the same number of columns and corresponding columns must be of the same type. WRONG SELECT A, B FROM table1 UNION SELECT C FROM table2 OK SELECT A, B FROM table1 UNION SELECT C, null FROM table2
-
Syntax should be WHERE (col1 LIKE '%X%') OR (col2 LIKE '%X%') OR (col3 LIKE '%X%') OR ... etc
-
You might want to add HAVING occurence > 1 ORDER BY occurence DESC at the end of the query
-
Getting a users rank from a mysql table with PDO
Barand replied to mediabob's topic in PHP Coding Help
My rank there is 8, there are 7 with a higher score. You only have 2 with a higher score -
Getting a users rank from a mysql table with PDO
Barand replied to mediabob's topic in PHP Coding Help
Fred 99 Joe 90 Mary 80 Jane 80 Paul 80 Peter 80 Jazzman 80 Jazzman, if you use >= then your rank is now 7 instead of 3= -
Getting a users rank from a mysql table with PDO
Barand replied to mediabob's topic in PHP Coding Help
And don't forget to add 1 to the count to get the rank (if count is 0, rank is 1) -
The structure and processes could be greatly simplified if every company had at least one branch ( where that single branch may be the head office in many instances) Then it's simply Company | +----< Branch | +----< Contact
-
What is your table structure?
-
Then remove the WHERE clause
-
or, if the order is significant SELECT balls, COUNT(*) as occurence FROM ( SELECT CONCAT_WS(',', Ball1, Ball2, Ball3) as balls, Ball1 as `A`, Ball2 as `B`, Ball3 as `C` FROM random UNION SELECT CONCAT_WS(',', Ball2, Ball3, Ball4) as balls, Ball2 as `A`, Ball3 as `B`, Ball4 as `C` FROM random UNION SELECT CONCAT_WS(',', Ball3, Ball4, Ball5) as balls, Ball3 as `A`, Ball4 as `B`, Ball5 as `C` FROM random UNION SELECT CONCAT_WS(',', Ball4, Ball5, Ball6) as balls, Ball4 as `A`, Ball5 as `B`, Ball6 as `C` FROM random ) x WHERE `A` IN ( $ball1, $ball2, $ball3, $ball4, $ball5, $ball6) AND `B` IN ( $ball1, $ball2, $ball3, $ball4, $ball5, $ball6) AND `C` IN ( $ball1, $ball2, $ball3, $ball4, $ball5, $ball6) GROUP BY balls HAVING occurence > 1
-
Is this what you are after? SELECT balls, COUNT(*) as occurence FROM ( SELECT id, , GROUP_CONCAT(ball ORDER BY ball) balls FROM ( SELECT id Ball1 ball FROM random UNION SELECT id,Ball2 ball FROM random UNION SELECT id, Ball3 ball FROM random UNION SELECT id, Ball4 ball FROM random UNION SELECT id, Ball5 ball FROM random UNION SELECT id, Ball6 ball FROM random ) x WHERE ball IN ( $ball1, $ball2, $ball3, $ball4, $ball5, $ball6) GROUP BY id HAVING COUNT(*) = 3 ) y GROUP BY balls HAVING occurence > 1
-
Are the records that appear the ones that have an empty string value in one or more of those four columns? Use the wildcard character "%" with LIKE. That way if $brand is empty then all values are matched. $sql = "SELECT * FROM units WHERE Brand LIKE '%$brand%' OR Model LIKE '%$brand%' OR Capacity LIKE '%$brand%' OR Type LIKE '%$brand%'";
-
Instead of normalizing the data he is using the six unioned queries to simulate the normalized table. Go figure!
-
It's only efficient if it works, and date arithmetic will not work with d/m/y date formats Yes. ... WHERE CURDATE() = STR_TO_DATE(ukDate, '%d/%m/%Y') + INTERVAL 30 DAY
-
That date format is totally useless for databases. You can't compare date ranges, you can't sort and you can't make use of the dozens of dat/time functions without converting it first to the correcty YYYY-MM-DD format. Use STR_TO_DATE() function to convert to DATE format then you can add INTERVAL 30 DAY to the result.
-
Help with database design - complex relationship
Barand replied to dhirajkumar41's topic in MySQL Help
You wouldn't store rank. That is derived data and you can find the rank with a query when required -
Help with database design - complex relationship
Barand replied to dhirajkumar41's topic in MySQL Help
The player_points table in my version will enable you to find the winning user this week / this month / this season etc. If, as in the second version, you accumulate the points in the player record then you lose the time element and at some time you have the overhead of having to reset them all to zero (and lose any historical player performance data) The second version's user_team table enables users to have more than one team if that is a requirement. -
The matchsort() custom sort function will sort the array by sportname - tournamentname - matchname. $matches = Array ( 0 => Array ( 'sportname' => 'Football', 'tournamentname' => 'Crown League', 'thetime' => 201308021600, 'matchname' => 'Reds vs Whites', 'linkset' => Array ( 'link' => 'link1.html' ) ) , 1 => Array ( 'sportname' => 'Football', 'tournamentname' => 'Prince League', 'thetime' => 201308021130, 'matchname' => 'Blues vs Yellows', 'linkset' => Array ( 'link' => 'link2.html' ) ), 2 => Array ( 'sportname' => 'Football', 'tournamentname' => 'Crown League', 'thetime' => 201308021000, 'matchname' => 'Greys vs Whites', 'linkset' => Array ( 'link' => 'link3.html' ) ) ); usort($matches, 'matchsort'); echo '<pre>',print_r($matches, true),'</pre>'; function matchsort ($a, $b) { $x = strcmp($a['sportname'], $b['sportname']); if ($x==0) { $y = strcmp($a['tournamentname'], $b['tournamentname']); if ($y==0) { return strcmp($a['matchname'], $b['matchname']); } else{ return $y; } } else { return $x; } } OUTPUT Array ( [0] => Array ( [sportname] => Football [tournamentname] => Crown League [thetime] => 201308021000 [matchname] => Greys vs Whites [linkset] => Array ( [link] => link3.html ) ) [1] => Array ( [sportname] => Football [tournamentname] => Crown League [thetime] => 201308021600 [matchname] => Reds vs Whites [linkset] => Array ( [link] => link1.html ) ) [2] => Array ( [sportname] => Football [tournamentname] => Prince League [thetime] => 201308021130 [matchname] => Blues vs Yellows [linkset] => Array ( [link] => link2.html ) ) )