web_master Posted January 13, 2009 Share Posted January 13, 2009 hi, Talkin about a Newspaper where the authors written the texts in every number of Newspaper. 5 (or more) persons write some texts. How can I Summary how many characters written each person (author) per Newspaper. <?php $query_textcount = mysql_query("SELECT * FROM `text` WHERE `news_nr` = '".$_POST['news_nr']."' "); ?> The textCounter is: strlen(strip_tags(html_entity_decode($CharS)) where "$Chars" is `Text` column from dBase Table. Table contain `Text ID` `authors ID` `Text` In table this looks like this: Author id 1 written 522 chars Author id 2 written 324 chars Author id 3 written 400 chars Author id 1 written 114 chars Author id 3 written 55 char I need to see in "while": John Miles (id 1) written summary 636 chars Peter Bolen (id 2) written summary 324 chars Mila Jovovich (id 3) written summary 455 chars ... Quote Link to comment https://forums.phpfreaks.com/topic/140637-solved-written-character-counter-by-user/ Share on other sites More sharing options...
xtopolis Posted January 13, 2009 Share Posted January 13, 2009 Probably something along the lines of: $sql = "SELECT *,SUM(`Text`) FROM `test` WHERE `news_nr` = '".$_POST['news_nr']."' GROUP BY `Text ID`"; $result = mysql_query($sql); while(list($id,$name,$chars) = mysql_fetch_array($result)){ echo "$name (id $id) written summary $chars chars<br />"; } You will have to fix it to match your column names/order because I can't tell where you pull out the actual names.. etc Quote Link to comment https://forums.phpfreaks.com/topic/140637-solved-written-character-counter-by-user/#findComment-735993 Share on other sites More sharing options...
fenway Posted January 13, 2009 Share Posted January 13, 2009 You CANNOT mix * and GROUP BY!!! Quote Link to comment https://forums.phpfreaks.com/topic/140637-solved-written-character-counter-by-user/#findComment-736034 Share on other sites More sharing options...
xtopolis Posted January 13, 2009 Share Posted January 13, 2009 Yea, I guess I should have left it out, I didn't know 100% that you could have *... but I didn't know which columns referred to what so I hoped he would infer that he would have to add his own columns in place of *. My bad. Quote Link to comment https://forums.phpfreaks.com/topic/140637-solved-written-character-counter-by-user/#findComment-736047 Share on other sites More sharing options...
fenway Posted January 13, 2009 Share Posted January 13, 2009 so I hoped he would infer that he would have to add his own columns in place of *. My bad. But that's just the point... there's no "choice"... only Text ID can be in the column list with the other aggregate functions. And I think you mean SUM(CHARLENGHT(`text`)).... Quote Link to comment https://forums.phpfreaks.com/topic/140637-solved-written-character-counter-by-user/#findComment-736119 Share on other sites More sharing options...
web_master Posted January 13, 2009 Author Share Posted January 13, 2009 Hm, well, I dont understand ... and I dont have a solution for now... well, I will try once more: table: text_table columns: id user_id text news_nr I want to list the user_id-s where news_nr = 6 and in meantime I want the summary of the characters written in column text where id = number of texts written for a news nr 6 So its must to looks like Monika johnson written summary 6368 characters in news Nr 6. Brigitte Millson written summary 12987 characters in news Nr 6. (Maybe Monica and Brigitte written more than 1 texts: id 1 is a Monicas text, id 3 is a Monicas text, id 26 is a Monicas text ...) well I hope its clearly... Quote Link to comment https://forums.phpfreaks.com/topic/140637-solved-written-character-counter-by-user/#findComment-736211 Share on other sites More sharing options...
web_master Posted January 13, 2009 Author Share Posted January 13, 2009 Maybe Ill try help in "PHP-Help"? Quote Link to comment https://forums.phpfreaks.com/topic/140637-solved-written-character-counter-by-user/#findComment-736249 Share on other sites More sharing options...
xtopolis Posted January 13, 2009 Share Posted January 13, 2009 You're changing your table structure from the your first post... are there two separate tables now or what? How do you expect us to help you without all the information. I have offered advice and fenway has corrected it. As you can see you will select your column and depending on how your character count is, SUM() it or SUM(CHARLENGTH(column)) it and then group by the unique identifier column. Quote Link to comment https://forums.phpfreaks.com/topic/140637-solved-written-character-counter-by-user/#findComment-736415 Share on other sites More sharing options...
web_master Posted January 13, 2009 Author Share Posted January 13, 2009 No, Im not change the table, nothing is changed, just trry to explain with more informations. If that mismach You, Im sorry. Quote Link to comment https://forums.phpfreaks.com/topic/140637-solved-written-character-counter-by-user/#findComment-736466 Share on other sites More sharing options...
xtopolis Posted January 13, 2009 Share Posted January 13, 2009 Try something like: $sql = "SELECT user_id, SUM(CHARACTER_LENGTH(`text`)) FROM text_table WHERE news_nr = 6 GROUP BY user_id"; $result = mysql_query($sql); while(list($name,$chars) = mysql_fetch_array($result)){ echo "$name has written summary $chars characters in news Nr 6. } Quote Link to comment https://forums.phpfreaks.com/topic/140637-solved-written-character-counter-by-user/#findComment-736483 Share on other sites More sharing options...
web_master Posted January 14, 2009 Author Share Posted January 14, 2009 hi, Its work now, only I need to Join table with "users" table to see names on place of user_id. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/140637-solved-written-character-counter-by-user/#findComment-736805 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.