Butterbean Posted January 10, 2015 Share Posted January 10, 2015 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 335Notice: Undefined variable: raw_material_price in C:\xampp1\htdocs\Utrack\invoice.php on line 335Notice: Undefined variable: basic_charge in C:\xampp1\htdocs\Utrack\invoice.php on line 335Notice: Undefined variable: peak_rate in C:\xampp1\htdocs\Utrack\invoice.php on line 335Notice: Undefined variable: intermediate_rate in C:\xampp1\htdocs\Utrack\invoice.php on line 335Notice: Undefined variable: energy_charge in C:\xampp1\htdocs\Utrack\invoice.php on line 335Notice: Undefined variable: base_rate in C:\xampp1\htdocs\Utrack\invoice.php on line 335 Link to comment https://forums.phpfreaks.com/topic/293822-defining-a-variable-in-php/ Share on other sites More sharing options...
ginerjm Posted January 11, 2015 Share Posted January 11, 2015 You can't concatenate to a variable without creating it first. So - before your loop you must initialize the vars Link to comment https://forums.phpfreaks.com/topic/293822-defining-a-variable-in-php/#findComment-1502474 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.