Jump to content

Recommended Posts

It does not execute the rest of the query after the first array is done.

 

foreach(($params->dstchannel) as $b){
$c = $params->period_start;
$d = $params->period_end;
$t_dur=0;
$t_bill=0;
$totalprod1=0;
$t_duration=0;
$t_billsec=0;
$t_same=0;
$cdr->query("SELECT dst,dstchannel,duration,billsec,calldate 
			FROM `cdr` 
			WHERE (`calldate` >= '$c 00:00:01' 
			AND `calldate` <= '$d 23:59:59') 
			AND (`dstchannel` LIKE '%$b%')
			AND (`dst` NOT LIKE '9011%') 
			");

unset($row);
while ($row = $cdr->fetch_assoc()):
	$t_dst = $row['dst'];
	$t_duration += $row['duration'];
	$t_billsec += $row['billsec'];
?>
        <!--it stops executing here after the first array is done-->
        <tr style="display:none";>
		<td style="display:none";><?php $row['dst'];?></td>
		<td style="display:none";><?php $row['dstchannel'];?></td>
		<td style="display:none";><?php $row['duration'];?></td>
		<td style="display:none";><?php $row['billsec'];?></td>
		<td style="display:none";><?php $row['billsec'];?>
			<?php	$num = $row['billsec'];
					if($num % 60){
						$quotient = $num/60;
						$same = ceil($quotient);
					}else{
						$quotient = $num/60;
						$same = $quotient;
					}
					$t_same += $same;
                ?>
            </td>
	</tr>
<?php
endwhile;
?>
<table id="summary" cellspacing="0">
    	<h2>DESTINATION CHANNEL: <?php echo $b;?></h2>
            <?php if(($t_duration==0)&&($t_billsec==0)){ ?>
        <tr style="display: none";>
            </tr>
		<?php }else{?>
	<h3>US Calls</h3>
	<tr>
		<td  class="row">Destination Prefix:</td>
            <td  class="row">Destination Channel:</td>
            <td  class="row">Total Duration:</td>
            <td  class="row">Total Billsec:</td>
            <td  class="row">Total Rounded off billsec:</td>
	</tr>
        <tr class="total">
		<td><?php echo "US Call";?></td>
		<td><?php echo $b;?></td>
		<td><?php echo $t_duration; echo ' sec(s)';?></td>
		<td><?php echo $t_billsec; echo ' sec(s)';?></td>
		<td><?php echo $t_same; echo ' min(s)';?></td>
	</tr><?php }?>
</table>
    
    <h3>Country Codes</h3>
    <table id="summary" cellspacing="0">
         <tr>
            <td class="row">Country Code</td>
            <td class="row">Country</td>
            <td class="row">Destination Channel</td>
            <td class="row">Duration</td>
            <td class="row">Billsec</td>
            <td class="row">Rounded off billsec</td>
            <td class="row">Cost</td>
            <td class="row">Computed Cost</td>
        </tr>
	<?php

            unset($rowrow);
            while ($rowrow = $country->fetch_assoc()):
                $codec = $rowrow['ccode'];
                $newdb->query("SELECT dst,dstchannel,duration,billsec,calldate 
						FROM `cdr` 
						WHERE (`calldate` >= '$c 00:00:01' 
						AND `calldate` <= '$d 23:59:59') 
						AND ((`dstchannel` LIKE '%$b%'))
						AND (`dst` LIKE '9011$codec%')
						");
                ?>
            <?php
			unset($result);
                while ($result = $newdb->fetch_assoc()):
                    $var = $result['dst'];
                    $t_dur += $result['duration'];
                    $t_bill += $result['billsec'];
            ?>
					<!--COMPUTE ONLY-->
                        <tr style="display: none">
                            <td><?php $var; $b; $result['duration']; $result['billsec'];?></td>
                            <td><?php $result['billsec'];
                                        $num2 = $result['billsec'];
                                            if($num2 % 60){
                                                $quotient2 = $num2/60;
                                                echo $same2 = ceil($quotient2);
                                                echo ' min(s)';
                                            }else{
                                                $quotient2 = $num2/60;
                                                echo $same2 = $quotient2;
                                                echo ' min(s)';
                                            }
                                        $t_sam += $same2;?></td>
                        </tr>
                <?php endwhile; 					
				if(($t_dur==0)&&($t_bill==0)){
			?>
                <tr  style="display: none"></tr>
			<?php }else{?>
            <tr class="total" id="total">
                <td><?php echo $codec; ?></td>
			<td><?php echo $rowrow['cname'];;?></td>
                <td><?php echo $b;?></td>
                <td><?php echo $t_dur;echo ' sec(s)';?></td>
                <td><?php echo $t_bill;echo ' sec(s)';?></td>
                <td ><?php 	$result['billsec'];?>
                    <?php	echo $t_sam; echo ' min(s)';
                    $t_dur = 0;
                    $t_bill =0;
                    ?></td>
			<td><?php	$rates->query("SELECT cost FROM `rates` WHERE `channel`='$b' AND (`ccode`='$codec')");
						while ($call = $rates->fetch_assoc()): 
						echo $call['cost'];
						?></td>
			<td><?php echo $product1=(($call['cost'])*($t_sam)); 
						$totalprod1 += $product1; 
					endwhile;?></td>
            </tr><?php $t_sam = 0; }?>
            <?php endwhile;?>
            <tr class='black'>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td><?php echo $totalprod1;?></td>
       		</tr>
    </table>
<br />
<br />
</body>
<?php } endif; ?>

Link to comment
https://forums.phpfreaks.com/topic/238675-foreach-problemnot-executing-query/
Share on other sites

<td style="display:none";><?php $row['dst'];?></td>

<td style="display:none";><?php $row['dstchannel'];?></td>

<td style="display:none";><?php $row['duration'];?></td>

<td style="display:none";><?php $row['billsec'];?></td>

<td style="display:none";><?php $row['billsec'];?>

 

I may be wrong, but that could be a syntax error right there, try doing <?=$var;?> or <?php echo $var; ?>

 

btw, your db class kinda reminds me of the one I made a while back :) just throwing that out there.

 

furthermore, you don't need to re-initialize a new connection object everytime you want to run a seperate query, if you want to do this to keep results from one query, you could simply store the mysql resultset resource in a different variable.. opening more than 1 database connection is inefficient and unnecessary..

 

is your error reporting turned on?

SOLVED IT!

I tried putting the

$country->query("SELECT ccode,cname FROM `countrycode`");

before the while loop ad it worked perfectly fine. I don't what cause the problem because this query is placed on a differenet php file.

 

$country->query("SELECT ccode,cname FROM `countrycode`");
            while ($rowrow = $country->fetch_assoc()):
                $codec = $rowrow['ccode'];
                $newdb->query("SELECT dst,dstchannel,duration,billsec,calldate 
						FROM `cdr` 
						WHERE (`calldate` >= '$c 00:00:01' 
						AND `calldate` <= '$d 23:59:59') 
						AND ((`dstchannel` LIKE '%$b%'))
						AND (`dst` LIKE '9011$codec%')
						");

<td style="display:none";><?php $row['dst'];?></td>
         <td style="display:none";><?php $row['dstchannel'];?></td>
         <td style="display:none";><?php $row['duration'];?></td>
         <td style="display:none";><?php $row['billsec'];?></td>
         <td style="display:none";><?php $row['billsec'];?>

 

This works perfectly fine for me.  :)

 

Anyway, i solved it already.

SOLVED IT!

I tried putting the

$country->query("SELECT ccode,cname FROM `countrycode`");

before the while loop ad it worked perfectly fine. I don't what cause the problem because this query is placed on a differenet php file.

 

$country->query("SELECT ccode,cname FROM `countrycode`");
            while ($rowrow = $country->fetch_assoc()):
                $codec = $rowrow['ccode'];
                $newdb->query("SELECT dst,dstchannel,duration,billsec,calldate 
						FROM `cdr` 
						WHERE (`calldate` >= '$c 00:00:01' 
						AND `calldate` <= '$d 23:59:59') 
						AND ((`dstchannel` LIKE '%$b%'))
						AND (`dst` LIKE '9011$codec%')
						");

 

What I still don't get is why is it that if the second array is to be executed is returns no values. :)

Thanks for the advise!

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.