Jump to content

Recommended Posts

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 ...

 

 

 

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

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`))....

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...

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.

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.
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.