mikosiko
Members-
Posts
1,327 -
Joined
-
Last visited
-
Days Won
1
Everything posted by mikosiko
-
mySQL sum of multiple fields in two different tables
mikosiko replied to Roland_D's topic in MySQL Help
Hmm... but this is better and simple (just needed more coffee in my blod) SELECT users.user_id, users.username, users.views, SUM(pictures.views) as picviews, users.views + SUM(pictures.views) AS totalviews FROM users JOIN pictures ON pictures.pic_user_id = users.user_id GROUP BY users.user_id ORDER BY users.user_id; // or ORDER BY totalviews (ASC/DESC) if you prefer and just to answer your last question with the previous query... you can have the name also in this way in that select (but better use that ^^) SELECT X.user_id, SUM(X.views) as totalviews FROM (SELECT users.user_id, users.username,users.views FROM users UNION SELECT pictures.pic_user_id, '.' AS username, pictures.views FROM pictures) AS X // '.' could be any string GROUP BY X.user_id ORDER BY X.user_id; // or ORDER BY totalviews (ASC/DESC) if you prefer -
mySQL sum of multiple fields in two different tables
mikosiko replied to Roland_D's topic in MySQL Help
yup... my select is stupidly wrong too.... this is one way to obtain the right result SELECT X.user_id, SUM(X.views) as totalviews FROM (SELECT users.user_id, users.views FROM users UNION SELECT pictures.pic_user_id, pictures.views FROM pictures) AS X GROUP BY X.user_id ORDER BY X.user_id; // or ORDER BY totalviews (ASC/DESC) if you prefer -
mySQL sum of multiple fields in two different tables
mikosiko replied to Roland_D's topic in MySQL Help
easy... because the select #1 is totally incorrect based in your original post objectives. and based on the fact that select grouping is very... very wrong. -
mySQL sum of multiple fields in two different tables
mikosiko replied to Roland_D's topic in MySQL Help
more like this: SELECT users.id, users.username, SUM(users.views + pictures.views) as totalviews FROM users JOIN pictures ON pictures.pic_user_id = users.user_id GROUP BY users.id ORDER BY users.id; // or ORDER BY totalviews (ASC/DESC) if you prefer -
select value in multiple fields and multiple tables
mikosiko replied to cybernalle's topic in MySQL Help
$result = mysql_query("SELECT * FROM pages, lists, links, text WHERE text, keywords, content, description LIKE $search"); Step #1 for your long journey... familiarize yourself with how a SELECT works... several examples there... also be sure to visit the "JOIN Syntax" and "UNION Syntax" links in the same page... after study those pages and adjust your code properly come back with your doubts/questions and we will glad to help more. -
where in that code are you connecting to the DB? also: - take rid of that "@" ... your are suppressing possibles error there... not good.. best if you control the errors. - include the 2 lines in my signature immediately after your <?php line to control the errors display during development. - Don't do the DELETE in the while loop... just store the affected ID's in the loop and make just one DELETE by the end of the loop... more efficient. -And in top of everything... why are you doing all of that if you can do the same just with the DELETE clause? http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_datediff
-
LOAD DATA [LOCAL] INFILE could be your solution
-
-
What is the easiest way to make this function
mikosiko replied to Bl4ckMaj1k's topic in PHP Coding Help
just as complementary information for the OP... this '?:' $quantity = (!empty($_POST['quantity'][$key])) ? intval($_POST['quantity'][$key]) : 0; is called ternary operator , more info is here -
in the most simplest design... 1 table 2 columns thedate DATE, amount DECIMAL week and day can be obtained from the "thedate" column
-
the fact that the final query has a variable (dynamic) number of fields to be selected (the sum by month) make no possible (imho) to build it using only direct queries... you must build the final query in some way... either manually or with some kind of programming... other alternatives to do this using only Mysql resources is use Stored Procedures or Functions
-
that is why I pointed you first to page 5.... there is an example showing how to do that... the example use Perl... but the important thing are the concepts about how to build the query dynamically ... page 4 shows how to use CONCAT to build part of the query.... you can develop the same concept in PHP or in whatever you feel comfortable.
-
What is the easiest way to make this function
mikosiko replied to Bl4ckMaj1k's topic in PHP Coding Help
your final form will be POSTing at least 2 arrays: - resource_form_label[] .... most likely corresponding to the "item" name and - quantity[] in your processing form script just var_dump($_POST) and you will see the posted values... the rest is just a matter of process those arrays to construct your INSERT -
I was trying Left Joins, Inner Joins, Outer Joins and all kinds of other Joins but with no luck. why?... show the code that you used. a JOIN should do the job... short example: SELECT a.post_id, .... .... FROM ec3_schedule AS a JOIN posts AS b ON a.post_id = b.post_id AND b.post_status = 'publish' WHERE.... ....
-
old... but good source to solve your issue. http://dev.mysql.com/tech-resources/articles/wizard/page5.html (read pages 4 and 5)
-
doesnt work with: id int NOT NULL AUTO_INCREMENT,
mikosiko replied to clankill3r's topic in MySQL Help
what error message are you receiving ? ... if you don't see any error message enable error reporting/display adding this 2 lines after the <?php line error_reporting(E_ALL); ini_set("display_errors", "1"); -
COUNT (or any aggregation function) AND GROUP BY work together... please read the info in the provided links SELECT shipname, COUNT(shipname) FROM ship GROUP BY shipname; SELECT class, COUNT(class) FROM ship GROUP BY shipname;
-
COUNT() and GROUP BY
-
in that case, if you are going to pass the attributes that you want as parameters to the query a simple modification to the third select that I gave you previously should work SELECT product, GROUP_CONCAT(attribute ORDER BY attribute) AS gp FROM ProdAts GROUP BY product HAVING gp = CONCAT_WS(',',23,45); // or replace here for the attributes that you want ordered asc. that select produce this results: 234, '23,45' 568, '23,45'
-
Help on getting avg time between timestamps of entire table
mikosiko replied to TOA's topic in MySQL Help
I don't see a clear way to solve your request with a straight query... I see 2 options : - Write a MYSQL stored procedure or function to return the average. - Load the data in an PHP array and post-process it to get the average. both options should work in a similar way... choose the one that you feel more comfortable with. -
and what have you done to debug your code?
-
is a typo here ? #foreach ($categorias[$clave]['lista_referencias'] as $referencia) { $referencia = $categorias[$clave]['lista_referencias'][$i]; p($categorias[$clave]['lista_referencias'][$i]); /// is this other function or should be pe ?? $id_ref = $referencia[1]; and even with that fix (if an error) the Undefined Index error pointed by PFMAbisMad still there
-
take the @ out of your calls to functions as was suggested. in the code that you posted...is there a copy/paste problem?.. you have the function getUser() twice why?... details...
-
short answer for your specific question... NO your question was clear from the beginning, and you got 2 very good answers... Pikachu was very clear answering you this: and there is your big conceptual design mistake.... a relational DB is not a spreadsheet.. PFMAbisMad gave you a suggestion regarding which could be a better way to design your table. Storing calculated fields in a table (also knows as dependent fields) is not a good practice/modeling technic ... you can always use any aggregate function to produce those values at display time (assuming that your table has been designed correctly).
-
Getting count of how many different data there is on a mysql database.
mikosiko replied to 00stuff's topic in PHP Coding Help
double loop... no wonder