Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
transaction.executeSql('SELECT t1.*,t2.Cust_name FROM invoice t1,customer t2 where t2.Cust_name="'+rname+'" and t1.Cust_code=t2.UserId', [],  function(transaction, result)
                                {
                                  le=result.rows.length;
                                  for (var i = 0; i < result.rows.length; i++)
                                      {
                                       var row = result.rows.item(i);
                                          rid=row.Invoice_number;
                                          console.log(rid);
                                          if(rid)
                                           document.location.href="invoice_data_list.html?rname="+rname+"&rid="+rid;
                                           console.log("s");
                                       }

                                   });

This is a code to select datas from two tables,below are the table descriptin.
table1-invoice(invoice_id,date,cust_code,amt)
table2-customer(userid,custname,bal_amt);

I have a list of invoices for the same and different customers.On clicking a particular invoice it should display the details of it in another page.That is my work here.
The problem here is:If I select a customer who has multiple invoices it displays the last invoice of the particular customer.If I click on a customer having a single invoice then it displays the correct details.
How can I get a solution please...
Posted
Updated 20-May-14 2:01am
v3
Comments
You have set document location inside for loop. So, after the Loop ends, for a multiple invoice case, it would open the next page for the last value only.
p@y@l 20-May-14 8:29am    
Yes you are right.But after keeping it out of the loop also it takes the last value.Is there any way in query that I can make changes?
Sunasara Imdadhusen 20-May-14 8:52am    
Yes, you have to correct your query
Bhavana P 27-May-14 5:57am    
the query is correct, u dont have to change it. As per the for loop condition above it will display only one invoice id data.in url u need to pass the customer id not the invoice id to get all details of the customer.
p@y@l 28-Jun-14 5:32am    
thanks for the reply bhavana di...i got it.. :)

1 solution

Hello,

Please use following query:
SQL
SELECT i.invoice_id, i.date, i.amt, c.custname, c.bal_amt FROM invoice i
INNER JOIN customer c ON i.cust_code = c.userid WHERE c.Cust_name="rname"
 
Share this answer
 
Comments
p@y@l 20-May-14 23:44pm    
Its the same result as before ,no change!!! :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900