Solved

insert values to one field

Posted on 2012-12-21
3
164 Views
Last Modified: 2012-12-26
HI
i have this code with test,and i want to insert for example channel with values that can be p11,p22,p33 or p44 look the code and the same for usage can be v1 v2 v3 or v4
any help please
$pdf=" SELECT DATE(tran_date) as dateiy,unit_serial,account_no,
      SUM(case when pulse_channel = 1 then unit_qty else 0 end) as val1,
      SUM(case when pulse_channel = 2 then unit_qty else 0 end) as val2,
      SUM(case when pulse_channel = 3 then unit_qty else 0 end) as val3,
      SUM(case when pulse_channel = 4 then unit_qty else 0 end) as val4,
      SUM(unit_qty) as Total
  from count_transactions
  WHERE  DATE(tran_date) BETWEEN '".$start."' AND '".$end."'
  GROUP BY unit_serial";
$result=mysql_query($pdf) or die('Could not connect: ' . mysql_error());
$num=mysql_num_rows($result);
//echo $num;

while($rows = mysql_fetch_array($result)) { 
       $account=$rows['account_no'];
       $unit=$rows['unit_serial'];
       $h1=$rows['val1'];
       $h2=$rows['val2'];
       $h3=$rows['val3'];
       $h4=$rows['val4'];

//print var_dump($rows);
$query2="select * from net_watch_units
         where serial_no=$unit  ";
         $result3=mysql_query($query2);
         $record3=mysql_fetch_assoc($result3);
         $unite=$record3['UnitName'];
         $p1=$record3['pulser1_name'];
         $p2=$record3['pulser2_name'];
         $p3=$record3['pulser3_name'];
         $p4=$record3['pulser4_name'];
         $low1=$record3['pulser1_daily_alarm_low'];
         $low2=$record3['pulser2_daily_alarm_low'];
         $low3=$record3['pulser3_daily_alarm_low'];
         $low4=$record3['pulser4_daily_alarm_low']; 
         $high1=$record3['pulser1_daily_alarm_high'];
         $high2=$record3['pulser2_daily_alarm_high'];
         $high3=$record3['pulser3_daily_alarm_high'];
         $high4=$record3['pulser4_daily_alarm_high'];

$q2="SELECT account_name FROM account_details WHERE auto_id=$account";
                   $res2=mysql_query($q2);
                   $r2=mysql_fetch_array($res2);
                   $noms=$r2['account_name'];  
                   

if($h1>$high1){
   $mes='High usage alarm detected'
   $v1=$h1;
   $p11=$p1;
}
elseif($h2>$high2){
   $mes='High usage alarm detected'
   $v2=$h2;
   $p22=$p2;
}
elseif($h3>$high3){
   $mes='High usage alarm detected'
   $v3=$h3;
   $p33=$p3;
}
elseif($h4>$high4){
   $mes='High usage alarm detected'
   $v4=$h4;
}
elseif($h1>$low1){
   $mes='Low usage alarm detected'
   $v1=$h1;
   $p44=$p4;
}
elseif($h2>$low2){
   $mes='Low usage alarm detected'
   $v2=$h2;
}
elseif($h3>$low3){
   $mes='Low usage alarm detected'
   $v3=$h3;
}
elseif($h4>$low4){
   $mes='Low usage alarm detected'
   $v4=$h4;
}
$sql="INSERT INTO `alarm` (account, unitname, channel, usage, details)
VALUES
('$noms','$unite','$......";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

Open in new window

0
Comment
Question by:asaidi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 38712777
What is the question?  I can see that line 85 does not make any sense, but I don't know what to say except that you might want to add some LIMIT clauses to your queries, and you might want to test the queries for success and show the failures with something like this:
$res2=mysql_query($q2);
if (!$res2) die("FAIL: $q2 BECAUSE: " . mysql_error());

Open in new window

0
 

Author Comment

by:asaidi
ID: 38712827
the line 85 only a test i did not finish it only to show
0
 
LVL 7

Accepted Solution

by:
jkdt0077 earned 500 total points
ID: 38712995
You just want to put the insert statement inside each of the if statements, along with the relavent channel/usage/message..

if($h1>$high1){
   $mes='High usage alarm detected'
   $v1=$h1;
   $p11=$p1;
   $sql="INSERT INTO `alarm` (account, unitname, channel, usage, details)
VALUES
($noms,$unite,$p11,$v1,$mes)";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

Open in new window


And do the same for all the rest?
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question