Jump to content

Defining a variable in PHP


Butterbean
Go to solution Solved by ginerjm,

Recommended Posts

I know that I have posted a similar question to this but I am still having some confusion that I hoped I could clear up.  Thank you all for being patient with and helping me clean up this mess.

 

Below is the code that is spitting out the bottom error messages.  So, I understand that the way to define a variable which uses += and not send it into a loop, generating a notice is this..

 

Using the top example

 

$meter_multiplier=0;

while ($row5 = sqlsrv_fetch_array($query5)){
meter_multiplier += $row5['meter_multiplier'];
}

 

versus... 

 

$meter_multiplier += $row5['meter_multiplier'];

 

how can I implement this type of statment below.  Should the php be called another name and reference sql that way, so the names are different?

 

example    

 

$meter_multiplier=0;

while ($row5 = sqlsrv_fetch_array($query5)){

meter_multiplier += $row5['meter_mult'];

<?php
$sql5 = "select meter_id, subaccount_number, service_name, service_address, service_address2, service_city, service_st, service_zip, service_contact, basic_charge, energy_charge, base_rate, intermediate_rate, peak_rate, meter_multiplier, raw_material_price FROM [radiogates].[dbo].[ops_invoice] where meter_id ='$comm_id' and subaccount_number='$session_id'";$query5 = sqlsrv_query($conn, $sql5);if ($query5 === false){  exit("<pre>".print_r(sqlsrv_errors(), true));}while ($row5 = sqlsrv_fetch_array($query5)){  	

$meter_multiplier += $row5['meter_multiplier']; 
$raw_material_price += $row5['raw_material_price']; 
$basic_charge += $row5['basic_charge'];
$peak_rate += $row5['peak_rate']; 
$intermediate_rate += $row5['intermediate_rate']; 
$energy_charge += $row5['energy_charge'];
$base_rate += $row5['base_rate']; 
$account_number = $row5['meter_id']; 
$service_name = $row5['service_name']; 
$service_address = $row5['service_address'];
$service_address2 = $row5['service_address2']; 
$service_city = $row5['service_city']; 
$service_st = $row5['service_st']; 
$service_zip = $row5['service_zip'];} 
sqlsrv_free_stmt($query5);
?> 

Notice: Undefined variable: meter_multiplier in C:\xampp1\htdocs\Utrack\invoice.php on line 335

Notice: Undefined variable: raw_material_price in C:\xampp1\htdocs\Utrack\invoice.php on line 335

Notice: Undefined variable: basic_charge in C:\xampp1\htdocs\Utrack\invoice.php on line 335

Notice: Undefined variable: peak_rate in C:\xampp1\htdocs\Utrack\invoice.php on line 335

Notice: Undefined variable: intermediate_rate in C:\xampp1\htdocs\Utrack\invoice.php on line 335

Notice: Undefined variable: energy_charge in C:\xampp1\htdocs\Utrack\invoice.php on line 335

Notice: Undefined variable: base_rate in C:\xampp1\htdocs\Utrack\invoice.php on line 335

Edited by Butterbean
Link to comment
Share on other sites

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.