473,473 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

mysql fetch array not iterating through the records

1 New Member
Hi, i have a small script to display records from two tables. Table 1 keeps track of teams and table 2 keeps track of the members.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $dl = mysql_connect ("localhost","nitin_nick","test1234");
  3. $db = mysql_select_db("nitin_registration",$dl);
  4.  
  5. echo "<table border='0' width='986' align='center' cellspacing='1' cellpadding='5'>";
  6. echo "<tr>";
  7.  
  8. echo "<th>Team Name</th>";
  9. echo "<th>Team Contact</th>";
  10. echo "<th>Member Name</th>";
  11. echo "<th>Member Email</th>";
  12. echo "<th>Mobile Phone</th>";
  13. echo "<th>College</th>";
  14. echo "</tr>";
  15. $result1="";
  16. $result2="";
  17. $query1 = "SELECT * FROM team ";
  18. $q1_set = mysql_query($query1,$dl);
  19.  
  20. while ($result1 = mysql_fetch_array($q1_set)) {
  21.    $team_id = $result1['id'];
  22.    echo "<tr>";
  23.    echo "<td>".$result1['name']."</td>";
  24.    echo "<td>".$result1['contact']."</td>";
  25.    echo "<td>".""."</td>";
  26.    echo "<td>".""."</td>";
  27.    echo "<td>".""."</td>";
  28.    echo "<td>".""."</td>";
  29.    echo "</tr>";
  30.    $query2 = "SELECT * FROM member WHERE team_id={$team_id} LIMIT 3";
  31.  
  32.    $q2_set = mysql_query($query2,$dl) ;
  33.  
  34.    $result2 = mysql_fetch_array($q2_set);
  35.      $count=0;
  36.  
  37.    while ($result2 && $count<3)  {   //The index of $result2 is not incrementing
  38.         echo "<tr>";
  39.         echo "<td>".""."</td>";
  40.         echo "<td>".""."</td>";
  41.         echo "<td>".$result2['name']."</td>";
  42.         echo "<td>".$result2['email']."</td>";
  43.         echo "<td>".$result2['phone']."</td>";
  44.         echo "<td>".$result2['college']."</td>";
  45.         echo "</tr>";
  46.         $count++ ;
  47.  
  48.    } 
  49. }
  50.  
  51.  
  52. echo "</table>";
  53.  
  54. ?>
  55.  
The second query where i am trying to pull members with the team id, the result of mysql_fetch_array() is not incrementing the index of the array. When i run the script its goes into a infinite loop,( the second while loop) It just has the first record . Have i done something wrong here? Kindly help me out. Thanks.
Dec 22 '09 #1
1 3200
Dormilich
8,658 Recognized Expert Moderator Expert
yepp, you do your second loop inside the first loop, thus the variable of the first loop is not incremented, as long as the second loop didn’t finish.
Dec 23 '09 #2

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

Similar topics

4
by: Bob | last post by:
Hi, I am having trouble registering a row from a mysql query so far I have the mysql part working : while ( $val = mysql_fetch_array( $result )) { print("<tr><td>$val</td> <td>$val</td>...
9
by: Börni | last post by:
Hi, I have an sql query like this: SELECT column FROM table WHERE column1="3" AND column2="1" This query works perfectly if i run it in the command line, to be exactly it return two results. But...
9
by: frizzle | last post by:
Hi there, Short question: Is there any way, to reverse the result of a mysql query? Explanation: If i have eg. 20 records, all with their own id of course, select 5 with limit, and order...
4
by: rass.elma | last post by:
Hi all I fetch the following value from a string (VCAHR(250))colmun in a MySql table: "300000000000000000000000000000000000000000000000000" When I write it out using echo() I get : 3E+50 ...
6
by: onnodb | last post by:
Hi all, While working on an Access UI to a MySQL database (which should be a reasonable, low-cost, flexible interface to the DB, better than web-based, much less costly than a full-fledged .NET...
2
by: | last post by:
Perhaps posted it on wrong forums initially as I got only one response (which was helpful but I was looking for more). Please help if you can! =============================================== ...
7
by: asenthil | last post by:
Hai to all, this is senthil... i'm now working in the field of VC++... i want to connect a mysql database... just now tried to retrieve rows from a simple mysql database by using VC++ My...
4
by: dac | last post by:
I am quietly going insane on this project. I've never worked on a project like this one before. All my previous sticky forms were for data entry, not editing. I don't know how to display the form...
4
by: TechnoAtif | last post by:
Hi ALL I have entered some array values using checkboxes into mysql database through a form. Next iam creating a searchpage where all those cateogories inserted through checkboxes has to be...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.