saya xpaham...... :(
3 replies [Last post]
does not have a status.
User offline. Last seen 3 years 13 weeks ago. Offline
Joined: 08/16/2009
Points: 35

ni coding untuk dropdown menu saya

<?php
$conn
= mysql_connect('localhost','root','');

mysql_select_db("subs_060312_5j7ii",$conn);

$sql = "SELECT DISTINCT ItemDesc FROM salesreportdata Order By ItemDesc";
$item = mysql_query($sql) or die (mysql_error()."<hr><pre>$query</pre><hr>");


$sql1 = "SELECT Name1 FROM cu_customer Order By Name1";
$customer = mysql_query($sql1) or die (mysql_error()."<hr><pre>$query</pre><hr>"); 


echo
'
<body>
<p><div align="center"><b><font size=5>Stock Category & Customer Total Quantity Sales </b></div></p>
<p><div align="center"><b><font size=4>Please Enter the Year you want to Review
</font></b></div></p>

<form  method="post" action="custbrandqty.php? companyname1='
.$_GET['Companyname1'].'">

<table border=1>

<tr><td>Stock Category :&nbsp;
<select name="ItemDesc">
      <option value="All">All</option>
'
;
    
    
   while(
$row = mysql_fetch_assoc($item)){

    echo
"<option value='{$row['ItemDesc']}'>";
    echo
$row['ItemDesc']."\n";
    echo
"</option>";
}

echo
'
</select></td></tr>

<tr><td>
Customer Name :
<select name="CustomerName">
      <option value="All">All</option>
'
;


while(
$row = mysql_fetch_assoc($customer)){

   echo
"<option value='{$row['Name1']}'>";
   echo
$row['Name1']."\n";
   echo
"</option>";
}
echo
'
</select></td></tr>
<tr><td>Invoice From : &nbsp;&nbsp;&nbsp;&nbsp;
<select name="fdate">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</Select>-
<select name="fmonth">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>-
<select name="fyear">
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option selected value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
</select>
</tr>
<tr><td>Invoice To : &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<select name="tdate">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</Select>-
<select name="tmonth">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>-
<select name="tyear">
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option selected value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
</select>
</tr>
<tr><td>
<input type="submit" name="Submit" value="Submit"></td></tr>
</form>
</body>
'
;
mysql_close($conn);
?>

yang ini pulak untuk show list after click button submit.

<?php
$conn
= mysql_connect('localhost','root','');

mysql_select_db("subs_060312_5j7ii",$conn);

$com=$_GET['companyname1'];
$fdate=$_POST['fdate'];
$tdate=$_POST['tdate'];
$fmonth=$_POST['fmonth'];
$tmonth=$_POST['tmonth'];
$fyear=$_POST['fyear'];
$tyear=$_POST['tyear'];

if ((
checkdate($fmonth,$fdate,$fyear)!=1) or (checkdate($tmonth,$tdate,$tyear)!=1))
{
echo
'The Review Date is wrong, please try again';
}
$com=$_GET['companyname1'];
$CustomerName=$_POST['CustomerName'];
$ItemDesc=$_POST['ItemDesc'];





if (
$ItemDesc!='All' and $CustomerName!='All') {
$sql4 ="SELECT CustomerName, ItemDesc,Quantity,Total
FROM salesreportdata WHERE CustomerName ='$CustomerName'
AND ItemDesc = '$ItemDesc'
AND DocDate = '$fyear-$fmonth-$fdate'
AND ItemDesc = '$ItemDesc'
AND CustomerName ='$CustomerName'
GROUP BY ItemDesc,Customername
ORDER BY ItemDesc,CustomerName"
;

}


  
$rs4=mysql_query($sql4);
        while (
$row = mysql_fetch_row($rs4)){
       
$CustomerName[] = $row['CustomerName'];
           
$ItemDesc[] = $row['ItemDesc'];
           
$Quantity[] = $row['Quantity'];
              
$Total[] = $row['Total'];   
              
   
}

echo
"$CustomerName<br>";
echo
"$ItemDesc<br>";
echo
"$Quantity<br>";
echo
"$Total<p>";


mysql_close($conn);
?>

yang ini pulak output......

BRAND DYNAMICS SDN BHD
AMBY B/SPRAY-ENERGIZING 125ml MAL05081986KS

Notice: Undefined variable: Quantity in C:\xampp\htdocs\ubs\custbrandqty.php on line 53

Notice: Undefined variable: Total in C:\xampp\htdocs\ubs\custbrandqty.php on line 54

persoalannya?

1) kenapa bila select by itemdesc dia xshow all data yang berkaitan dng brand ini
2)undefine variable.........itu macmana and kenapa...sb dalam database ada table tu and ada data....
3)sistem yang saya tgh buat ni semua nak show n preview data sahaja sb data2 ni semua sudah ada n digunakan secara live oleh user - sistem acounting sistem....

Ada sape2 nak offer keje freelance x?sile skype saye amaleena123. TQ
amalina.iwan's picture
User offline. Last seen 1 year 24 weeks ago. Offline
Joined: 07/26/2010
Points: 265

Bila guna macam ini...

<?php

            $CustomerName
[] = $row['CustomerName'];
           
$ItemDesc[] = $row['ItemDesc'];
           
$Quantity[] = $row['Quantity'];
              
$Total[] = $row['Total'];   
?>


semua kat atas ni dia simpan dalam Array.
bile guna Array, nak tunjuk result dia tak boleh guna 'echo'.
maka bile dia guna echo $CustomerName mcm ini, akan tunjuk satu data aje la.

jadi nak cerita pasal Array ni, memang panjang lebar lah nak paham concept dia. Awal2 saya nak belajar, nak paham Array pun makan masa. Bile dah hari2 pakai, baru tau mcm mana.

Jadi, sebenarnya nak paparkan data ni mcm mana ek... dalam bentuk table?

Pe2pun bile guna $CustomerName[] mcm ini...kena tulis mcm ini

<?php
//Lepas kuar dari loop while tu, saya assuming akan kuar data macam ini
$CustomerName = array('A','B','C','D');
      foreach(
$CustomerName as $value){
           echo
"Nama Pelanggan: ".$value."<br />";
      }

//Output daripada ini adalah:
//   Nama Pelanggan: A
//   Nama Pelanggan: B
//   Nama Pelanggan: C
?>

----------------------------------------------------------------------------------------------------------

Cara lain plak :
Kalau nak tunjuk semua data tu dalam satu barisan demi satu barisan saje, saya akan buat mcm ini:

<?php

$rs4
=mysql_query($sql4);
$detail = array(); //Initialize
while ($row = mysql_fetch_row($rs4)){
      
$detail[] = array($row['CustomerName'], $row['ItemDesc'], $row['Quantity'],$row['Total']);  
}

foreach(
$detail as $value){
       echo
$value[0]."  ". $value[1]."  ". $value[2]."  ". $value[3]."<br />";
}


?>


Ni yg boleh tolong wat masa nih..
Kalau tak menjadi, cuba lagi.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Notice: Undefined variable: Quantity in C:\xampp\htdocs\ubs\custbrandqty.php on line 53
Notice: Undefined variable: Total in C:\xampp\htdocs\ubs\custbrandqty.php on line 54

Tang atas ni sebab tak letak permulaan variable atau lebih dikenali sebagai 'initialize'
kena tulis mcm ini sblm nak pakai yg seterus (jika tiada nama variable digunakan dalam coding tu)
contoh:
$Quantity = array();
$Total = array();

does not have a status.
User offline. Last seen 3 years 13 weeks ago. Offline
Joined: 08/16/2009
Points: 35

salam awak

bila saya buat mcm ni

while($row = mysql_fetch_array($result)){

echo $row['DocDate'];
echo $row['CustomerName'];
echo $row['ItemDesc'];
echo $row['Quantity'];
echo"
";
echo $row['Total'];
echo"
";
}

datanya keluar

2012-01-16 13:54:41CARING PHARMACY SDN BHDQUICK TOUCH 1M H/C-10 N/BLK 48
4039.2
2012-01-16 13:54:41CARING PHARMACY SDN BHDQUICK TOUCH 1M H/C-10 N/BLK 6
4039.2
2012-02-03 13:41:21CARING PHARMACY SDN BHDQUICK TOUCH 1M H/C-10 N/BLK 88
6732
2012-02-03 13:41:21CARING PHARMACY SDN BHDQUICK TOUCH 1M H/C-10 N/BLK 11
6732
2012-03-01 15:04:43CARING PHARMACY SDN BHDQUICK TOUCH 1M H/C-10 N/BLK 80
7031.2
2012-03-01 15:04:43CARING PHARMACY SDN BHDQUICK TOUCH 1M H/C-10 N/BLK 10
7031.2
2012-03-21 15:04:43CARING PHARMACY SDN BHDQUICK TOUCH 1M H/C-10 N/BLK 120
8976
2012-03-21 15:04:43CARING PHARMACY SDN BHDQUICK TOUCH 1M H/C-10 N/BLK 15
8976

tapi bila mcm ni

echo '


REPORT

Masegroup-Mase '.$com.' Sdn Bhd

Customer & Brand Total Quantity Sales

From '.$fdate.'-'.$fmonth.'-'.$fyear.' to '.$tdate.'-'.$tmonth.'-'.$tyear.'

';

echo '

Name

';
echo '

Stock Category

';
echo '

Quantity

';
echo '

Net Amount

';
echo ' ';

for($i=0;$i<5;$i++){

echo '

'.$CustomerName.'

';
echo '

'.$ItemDesc.'

';
echo '

'.$Quantity.'

';
echo '

'.$Total.'

';

echo ' ';
echo '

';

}

mysql_close($conn);
?>

akan keluar error ni

Notice: Undefined variable: Quantity in C:\xampp\htdocs\ubs\custbrandqty.php on line 69

Notice: Undefined variable: Total in C:\xampp\htdocs\ubs\custbrandqty.php on line 70

Notice: Undefined variable: Quantity in C:\xampp\htdocs\ubs\custbrandqty.php on line 69

Notice: Undefined variable: Total in C:\xampp\htdocs\ubs\custbrandqty.php on line 70

Notice: Undefined variable: Quantity in C:\xampp\htdocs\ubs\custbrandqty.php on line 69

Notice: Undefined variable: Total in C:\xampp\htdocs\ubs\custbrandqty.php on line 70

Notice: Undefined variable: Quantity in C:\xampp\htdocs\ubs\custbrandqty.php on line 69

Notice: Undefined variable: Total in C:\xampp\htdocs\ubs\custbrandqty.php on line 70

Notice: Undefined variable: Quantity in C:\xampp\htdocs\ubs\custbrandqty.php on line 69

Notice: Undefined variable: Total in C:\xampp\htdocs\ubs\custbrandqty.php on line 70

saya tak tahu mcmana nak letak variable untuk total tu sb yang lain dah dah list out....tinggal dua ni je

terima kasih yea

Ada sape2 nak offer keje freelance x?sile skype saye amaleena123. TQ
amalina.iwan's picture
User offline. Last seen 1 year 24 weeks ago. Offline
Joined: 07/26/2010
Points: 265

boleh letakkan tak code yg awak dah tukarkan tuh?
kalau awak perhatikan betul2...
variable $Quantity dan $Total tu awak tak initialize betul2.
setakat echo $row['Total'] dengan $row['Quantity'], tak bermakna sama dengan maksud $Total dan $Quantity.
sbb yang $row['Total'] dengan $row['Quantity'] amik value daripada database yang awak buat while loop tuh.
Jadi solution dari masalah awak tadi tuh... Saya agak awak kena buat mcm nih.

<?php
//Ini yang saya maksudkan dengan 'initialize variable'
$custname= '';
$desc= '';
$ddate = '';
$qty= '';
$ttl = '';

//while loop untuk retrieve data daripada database dan disimpan de dalam variable2 tersebut.
while($row = mysql_fetch_array($result,MYSQL_BOTH)){ //kena letak MYSQL_BOTH

$ddate $row['DocDate'];
$custname $row['CustomerName'];
$desc = $row['ItemDesc'];
$qty = $row['Quantity'];
$ttl = $row['Total'];
}

?>

Untuk pengetahuan, variable tak semestinya sama nama macam dalam table column name tuh daripada database. Jadi saya sengaja buat mcm ni supaya awak tak keliru tentang penggunaan PHP variable ni. Harap awak paham ek.

Kalau nak kuarkan output daripada yang atas sana ni, buat la mcm nih

<?php
$custname
= '';
$desc= '';
$ddate = '';
$qty= '';
$ttl = '';
echo
"Date      Name     Stock Category      Quantity         Net Amount<br />";           
while(
$row = mysql_fetch_array($result,MYSQL_BOTH)){
     
$ddate $row['DocDate'];
     
$custname $row['CustomerName'];
     
$desc = $row['ItemDesc'];
     
$qty = $row['Quantity'];
     
$ttl = $row['Total'];
     
echo
$ddate .'    '.$custname.'    '.$desc.'    '.$qty.'    '.$ttl.'<br />';
}
?>

Jadi awak tak yah la susah nak buat pakai 'for' loop.