csabi_fl Posted October 13, 2006 Share Posted October 13, 2006 Hi guys.I need some help with my table.It looks something like this:loginid|week1|total:John|5|0John|7|0John|3|0Now in the 'total' column (where all the 0's are)I want to have the sum of 'week1'(5+7+3).I think I need the UPDATE command but I don't know how to phrase it.Something like:UPDATE * SET total=???? WHERE loginid='John'.Is that possible to have the total in only 1 row not in all 3 of them?Thank you in advance. Link to comment https://forums.phpfreaks.com/topic/23858-help-with-table/ Share on other sites More sharing options...
fenway Posted October 13, 2006 Share Posted October 13, 2006 Why would you do such a thing? This can and should be calculated on the fly... and if for some reason you need it instantly, you should make a summary table instead. Link to comment https://forums.phpfreaks.com/topic/23858-help-with-table/#findComment-108391 Share on other sites More sharing options...
csabi_fl Posted October 13, 2006 Author Share Posted October 13, 2006 I am not sure I understand.How can I do that on the fly and how do I make that summary table?I am very new to this so please explain.Thank you again. Link to comment https://forums.phpfreaks.com/topic/23858-help-with-table/#findComment-108410 Share on other sites More sharing options...
fenway Posted October 13, 2006 Share Posted October 13, 2006 It's trivial to get the sum for each login:[code]SELECT SUM(total) FROM yourTable GROUP BY loginid[/code]A summary table would simply be a place where you store the result of the above query; but in general, it's not necessary, at least for MyISAM tables. Link to comment https://forums.phpfreaks.com/topic/23858-help-with-table/#findComment-108557 Share on other sites More sharing options...
csabi_fl Posted October 14, 2006 Author Share Posted October 14, 2006 It works great,thank you.One more thing.How do I link this summary table from my webpage? Link to comment https://forums.phpfreaks.com/topic/23858-help-with-table/#findComment-108846 Share on other sites More sharing options...
fenway Posted October 14, 2006 Share Posted October 14, 2006 [quote author=csabi_fl link=topic=111401.msg451909#msg451909 date=1160849759]How do I link this summary table from my webpage?[/quote]What do you mean? Link to comment https://forums.phpfreaks.com/topic/23858-help-with-table/#findComment-108877 Share on other sites More sharing options...
csabi_fl Posted October 14, 2006 Author Share Posted October 14, 2006 I want my members to be able to click on a link that takes them to this summary table so they can check their standings.A link between my webpage and mysql table is what I am looking for.Does that make sense? Link to comment https://forums.phpfreaks.com/topic/23858-help-with-table/#findComment-108884 Share on other sites More sharing options...
fenway Posted October 15, 2006 Share Posted October 15, 2006 Not really... just issue that query, and output the results. Link to comment https://forums.phpfreaks.com/topic/23858-help-with-table/#findComment-109063 Share on other sites More sharing options...
csabi_fl Posted October 16, 2006 Author Share Posted October 16, 2006 Hi again.I am trying to output the results just like you said.I use the following code:<?phpmysql_pconnect("localhost","",""); mysql_select_db(""); $query = "SELECT loginid,SUM(week1+week2) FROM submit1 GROUP BY loginid ORDER BY 'SUM(week1)+SUM(week2)' DESC";$result = mysql_query($query);while ($list = mysql_fetch_array($result)) { echo "{$list['loginid,SUM(week1)+SUM(week2) ']}<br>";}?>I am struggling with 2 things.1)The command DESC isn't working,numbers aren't showing up in descending order.2)Inside the 'echo' statement something isn't right, I guess it is a syntax error,I want the output to be in a chart ,for example:John|75Mary|70Mike|60 and so on.Thank you very much for your help. Link to comment https://forums.phpfreaks.com/topic/23858-help-with-table/#findComment-109673 Share on other sites More sharing options...
fenway Posted October 17, 2006 Share Posted October 17, 2006 $query = "SELECT loginid, SUM(week1+week2) AS weekSum FROM submit1 GROUP BY loginid ORDER BY weekSum DESC";and then: echo "{$list['loginid']}|{$list['weekSum']}} Link to comment https://forums.phpfreaks.com/topic/23858-help-with-table/#findComment-110094 Share on other sites More sharing options...
csabi_fl Posted October 17, 2006 Author Share Posted October 17, 2006 It works great.Thank you.I want to adjust the 'echo' statement so that it will show something like this:1) John|752) Marienne|703) Michael|60 and so on.How do I get the order nr 1,2,3 and how do I line up the points 75,70 and 60 to show up in a column nice and neat under one another? Link to comment https://forums.phpfreaks.com/topic/23858-help-with-table/#findComment-110182 Share on other sites More sharing options...
fenway Posted October 17, 2006 Share Posted October 17, 2006 You can easily add a PHP counter, and output that as well; as for "nice" columns, you should really output a TABLE, if it's HTML, or padding the output for text (not as simple). Link to comment https://forums.phpfreaks.com/topic/23858-help-with-table/#findComment-110294 Share on other sites More sharing options...
csabi_fl Posted October 18, 2006 Author Share Posted October 18, 2006 I am sorry I don't really understand.I am a rookie,remember?How do I output a php counter?I am not familiar with that.Also if you look at one of the previous posts the table is not HTML ,so if you could explain a little bit in details about padding the output for text. Link to comment https://forums.phpfreaks.com/topic/23858-help-with-table/#findComment-110457 Share on other sites More sharing options...
fenway Posted October 19, 2006 Share Posted October 19, 2006 Just initialize a PHP variable to zero outside the loop, and increment it for each iteration of the loop; then you can echo this as well, with whatever formatting you desired. As for padding, it's going to be easiest if you "cheat" and assume that you won't exceed a given length, and simply prepend/append with spaces the difference between this length N and the length your name field. If you want details about PHP implementation, post another thread in the PHP help forum. We've drift far away from MySQL, so I can't really be of any more help. Link to comment https://forums.phpfreaks.com/topic/23858-help-with-table/#findComment-111367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.