Jump to content

Recommended Posts

Hello,

 

I have following two tables

 

report_story

 

id  story_id  story_name  userid   

1    12        abc        9       

1    23        xdf        7       

1    45        dfdf        9       

1    12        abc        15   

 

user_details

 

id  userid    name

1      9    meera

2      13    Geeta

3      15    rahul

 

now i want to show my result somthing like this

 

Story name : abc

repoted users: meera,rahul

 

 

I don't want to show unnecessarily two rows here.

 

So i was trying the following queries which are not working

 

 

select *,count(*)as cnt from user_details a JOIN report_story r ON a.id = r.userid GROUP BY r.id ORDER BY r.id DESC LIMIT $start, $limit_value");

if(mysql_num_rows($sqlpage) > 0){ ?>
<tr>
  <td width="100%" align="left"><h1 class="pageTitle">Story Report</h1>
  <p>Total <b><?=$total_records;?></b>listing</p>
  </td>
</tr>
<tr>
<td width="100%">

  	 <?  while($row = $op->select($sqlpage)){

      ?>
        

     <tr bgcolor="#FEF9E6">
         <tr bgcolor="#FEF9E6"> <td width="25%" class="loginText">Title </td>
		       <td width="75%" class="Text"><a href="<?=$row['story_name'];?>" title="<?=stripslashes($row['story_name']);?>" ><?=stripslashes($row['story_name']);?></a></td>
       </tr>

      </tr>
      
      <tr bgcolor="#FDFAEE"> <?
      echo "SELECT a.username, r. * FROM user_details a JOIN story_report r ON a.id = r.id WHERE r.id='".$row['id']."'";
     	        $sqlrpt = $op->runsql("SELECT a.username, r. * FROM user_details a JOIN story_report r ON a.id = r.id WHERE r.id='".$row['id']."'");

    if(mysql_num_rows($sqlrpt) > 0){
    while($row1 = $op->select($sqlrpt)){
   $reportedby.= $row1['username'].", ";
    }
    }	?>
      
      <tr bgcolor="#FEF9E6">
  	  <td width="25%" class="loginText">Reported by</td> <? $reportedby =substr($reportedby, 0, -2); ?>
  	  <td width="75%" class="blogText" valign="top"><?=$reportedby; $reportedby="";?></td>
  </tr>
      <tr>
      <td colspan="3" width="100%"> </td>
      </tr></table>
       </div>
      <?
       } }?>
</td>
</tr>

 

Can anyone please see this and tell me how can i achieve the exact result?

 

Thanks in advance.

 

Link to comment
https://forums.phpfreaks.com/topic/186142-show-result-with-count-query/
Share on other sites

Got the count as well!!

see the query-

 

 $sqlpage = $op->runsql("select *,count(*) as cnt  story_name, GROUP_CONCAT(a.name) from user_details a JOIN report_story r ON a.userid = r.userid group by story_name ORDER BY r.userid DESC LIMIT $start, $limit_value");

 

GROUP_CONCAT is really new Aggregate function  for me.

 

Once again thanks a lot rajiv.

 

Marry Christmas! :D

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.