473,396 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Iterating through two MYSQL Tables

Table1

Bill
billno
P001
P002


Table2
Patient
Patno service amount
P001 s1 100
P002 zz 200
P001 s2 400


....

(1)if more then one Patno exists for a particular billno then add all the services(concatenate) and add all the amount .

(2)if only one result ...then simply print that.

(3)This is how i am doing it.....
Expand|Select|Wrap|Line Numbers
  1.    for(traversing all the billno values one by one)
  2.       {
  3.          check=0;
  4.           while($row = mysql_fetch_array($execute_query,MYSQL_NUM))
  5.                  {
  6.                        if(billno == Patno)
  7.                         {
  8.                            service = service + $row[1];
  9.                            amt      = amt + $row[2] ;
  10.                            check=1;
  11.                         }
  12.                  }
  13.  
  14.             if(check=1) /*make sure there is atleast one match*/
  15.              {  
  16.                  print the table as desired.
  17.              }
  18.      }
(4)My problem is that it works fine for printing the first row as shown in the table below.But does not move forward for the second row.During the second iteration of for loop it does not enter the while loop .Why does it not enter the while loop second time.I want to make it enter the while loop.Then only will my problem will be solved.

(5)Any other way of getting the result i want ..that you can give.


How i want the results...............
billno service amount
P001 s1,s2 500
P002 zz 200
...
...
...
Mar 25 '10 #1
2 1641
Hello,

Go through ID insert id field in your database and make it auto increment.
And link through ID.

Thanks & Regards,
Mayur Bhayani
Mar 27 '10 #2
well i got the solution to the problem......

Just before the while loop starts $execute_query=mysql_query($query);

What actually happens,fist time while loop runs perfectly.On second run of for loop ...we don't eneter the while loop again.This is because after the first iteration of While Loop ...the pointer is at the end of the query value ie ==NULL.

So if within for loop we excute the query ...there will be no problem.
Mar 29 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
6
by: jacob nikom | last post by:
I would like to create data model for a group of stores. All stores in this group are very similar to each other, so it is natural to allocate one MySQL database per store. Each database is going...
0
by: Mark Adams | last post by:
I am a relative newbie to MySQL. I had a Postfix+Courier+MySQL mail server running for several months. It took me a week or so to get it up and running in September. Now, I did a clean upgrade to...
0
by: Mark Adams | last post by:
I am a relative newbie to MySQL. I had a Postfix+Courier+MySQL mail server running for several months. It took me a week or so to get it up and running in September. Now, I did a clean upgrade to...
0
by: Mark Adams | last post by:
I really need some help with this. MySQL will not start on boot despite everything I've done to make sure that it is set to do so. When I start it as root from a terminal with...
11
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time...
1
by: Good Man | last post by:
Hi there I've noticed some very weird things happening with my current MySQL setup on my XP Laptop, a development machine. For a while, I have been trying to get the MySQL cache to work....
4
by: Vanessa | last post by:
Hi there I am an Access developer, and I have written applications for a 30 telephone call center, using the standard multiuser jet engine, it all works fine, but I want to move our systems onto...
1
by: PowerLifter1450 | last post by:
I've been having a very rough time installinig mySQL on Linux. I have been following the instructions form here: http://www.hostlibrary.com/installing_apache_mysql_php_on_linux Everytime I get to...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.