Jump to content

Query Problem.


edwardoit

Recommended Posts

Actually this is part of my code:

 

<?php

$hournum = range(0, 23);

$query = mysql_query('SELECT caller from test_table GROUP BY caller');

while ($rs = mysql_fetch_assoc($query)) {

echo '<tr>';

# phone number
echo '<td>' . $rs['caller'] . '</td>';

# loop hours
foreach ($hournum as $hour) {

	$sql2   = 'SELECT
		  duration, LEFT(time_call, 2) hour, time_call, date_call
		  FROM test_table
		  WHERE LEFT(time_call, 2) = ' . $hour;
	$query2 = mysql_query($sql) or die(mysql_error());

	while ($rs2 = mysql_fetch_assoc($query2)) {

		echo '<td>';

		        # display call at specific hour
          echo $rs['time_call'];
		            echo '<br />';
		echo '</td>';

	}



}

echo '</tr>';

}

?>

 

 

But im having problem with the result. The hours displayed on the first phone number was the same

on the next phone number(repeating).

I want to display call summary on evry specific hour of each phone number(caller).

I cant figure out if it was on the query or with the loop.

Link to comment
Share on other sites

Hi,

 

I have re-written your query so you can see how to correctly put it into a table. I only just figured out this myself, so am not an expert. There may be some errors in this (be warned) but the most important thing is you can see the structure of how the query can be displayed into a table correctly and the code you need:

 

<?php

 

$hournum = range(0, 23);

 

$query = mysql_query("SELECT caller from test_table GROUP BY caller");

 

$sql2   = "SELECT duration, LEFT(time_call, 2) hour, time_call, date_call

  FROM test_table WHERE LEFT(time_call, 2) =.$hour";

 

$query2 = mysql_query($sql);

 

while($rs = mysql_fetch_array($query, MYSQL_ASSOC)) {

 

foreach($row as $k=>$v) // This is the code you need

$$k = $v;

 

 

?>

 

   

        <td width="26%" class="normal_caps"><? echo $rs['caller']?></td>  // Your table

        <td width="21%" class="normal_caps"><? echo $rs['time_call'] ?></td>

</td>

      </tr> <?

++$i; // Your code for displaying/looping those results in the table.

}

echo "";

 

?>

    </table>

  </div>

 

I hope this helps a little. If you would like me to send my original code so you can adapt it - let me know.

 

Hope you get it sorted.

 

Paul.

Link to comment
Share on other sites

I'm glad to have your original code.

I can't follow the code you provided here.

I'm no expert also.  :D

 

Do we have the same logic here? Mine is I want to display the phone number and the time calls were made so I can see if it really falls to the specific time. Uhmmm... if it works well, then I will change the code from displaying the specific time to total calls made on that specific time.

 

 

 

This is actually a simple view of  what I want to display. But if you guys know how to display call history per hour much better...I'll just revise it to achieve my need. 8)

 

 

 

+--------+----+----+----+------+

| fone #  | 00  | 01  | 02 | ...23  |   00 -> 23 hours

+--------+----+----+----+------+

| 123323 |  5   | 01  | 62 |   0    |

+--------+----+----+----+------+

| 534513 |  1   | 9   | 3   |   5    |

+--------+----+----+----+------+

| 34522   | 0   | 1    | 54 |   1    |

+--------+----+----+----+------+

| 45678   | 7   | 0    | 0   |  4     |

+--------+----+----+----+------+

 

 

but i got this...

+--------+----+----+----+------+

| fone #  | 00  | 01  | 02 | ...23  |  00 -> 23 hours

+--------+----+----+----+------+

| 123323 |  5  | 01  | 62 |  0    |

+--------+----+----+----+------+

| 223324 |  5  | 01  | 62 |  0    |

+--------+----+----+----+------+

| 323325 |  5  | 01  | 62 |  0    |

+--------+----+----+----+------+

| 423326 |  5  | 01  | 62 |  0    |

+--------+----+----+----+------+

 

 

 

 

Link to comment
Share on other sites

  • 3 weeks later...
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.