473,735 Members | 11,175 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Nested array loop problem

Hello

I am new to php & MySQL - I am trying to retrieve some records from a MySQL
table and redisplay them. The data in list form looks like this:

Sample_ID Marker_ID Variation

G23_NA17192.fsa rs7374540 A/C

I23_Control.fsa rs7374540 C/C

C03_NA17110.fsa rs7428779 C/C

E21_NA17183.fsa rs6788899 G/G

K15_NA17162.fsa rs6599223 C/C

M15_NA17163.fsa rs6599223 C/C

M15_NA17163.fsa rs312451 A/C

I'd like to redisplay them as such:

Marker_ID

Sample_ID rs7374540 rs7428779 rs6788899 rs6599223 rs31245

G23_NA17192.fsa A/C

I23_Control.fsa C/C

C03_NA17110.fsa C/C

E21_NA17183.fsa G/G

K15_NA17162.fsa C/C

M15_NA17163.fsa C/C A/C
The code passes the parser but repeats thru the entire loop 7 times (once
for each line of the results). So I must be not placing the while loop in
the correct block.

Also, all the Marker_IDs are displayed for each Sample_ID, not just the
Marker_IDs specific to each Sample_ID.

I'll work on the formatting of the display once I know the appropriate
results are returned. Thanks much. Code and Results follow.

Charles

-- Code ---
<?php

// DB specific info
DEFINE (DB_USER, "mysql");
DEFINE (DB_PASSWORD, "vil43nrt") ;
DEFINE (DB_HOST, "localhost" );
DEFINE (DB_NAME, "snplexdb_proto type");

//Connect to MySQL

$db_connect = (mysql_connect (DB_HOST, DB_USER, DB_PASSWORD));

//Select DB

mysql_select_db (DB_NAME);

//get the full results from the MySQL table

$db_query = "SELECT sample_id,snpid xref,var FROM sampleresults GROUP BY
sample_id, snpidxref ORDER BY sample_id, snpidxref";
$db_result = mysql_query($db _query, $db_connect);
$no_of_rows = mysql_num_rows( $db_result);
echo $no_of_rows;
echo "</br>";
echo "Now on to next block";
echo "<p>";
//work on this part!!

while ($results_array = mysql_fetch_arr ay($db_result)) {
echo "Start Outer Loop";
echo "</br>";
echo "Loop In";

//logic for each sample_id
//get unique sample ids

$sample_query = "SELECT DISTINCT sample_id FROM sampleresults ORDER
BY sample_id";
$sample_ids = mysql_query($sa mple_query, $db_connect);

while ($sample_array = mysql_fetch_arr ay($sample_ids) ) {
echo "</br>";
echo "Start Inner Loop";
echo "</br>";
echo "now we evaluate iter";
echo "</br>";
if ($results_array[sample_id] == $sample_array[sample_id]);
echo "</br>";
echo $sample_array[sample_id];
echo "</br>";

$snp_query = "SELECT DISTINCT snpidxref FROM sampleresults ORDER BY
snpidxref";
$snp_ids = mysql_query($sn p_query, $db_connect);

while ($snp_array = mysql_fetch_arr ay($snp_ids)) {
if ($results_array[snpidxref] == $snp_array[snpidxref]);
echo "</br>";
echo $snp_array[snpidxref];
echo "</br>";
}

echo "End Inner Loop";
echo "</br>";

}

//}
echo "Loop Out";
echo "</br>";
echo "</br>";
//}
//}
echo "End Outer Loop";
}

mysql_close($db _connect);
?>

Results are now displayed as such:

7
Now on to next block

Start Outer Loop
Loop In
Start Inner Loop
now we evaluate iter

C03_NA17110.fsa

rs312451

rs6599223

rs6788899

rs7374540

rs7428779
End Inner Loop

Start Inner Loop
now we evaluate iter

E21_NA17183.fsa

rs312451

rs6599223

rs6788899

rs7374540

rs7428779
End Inner Loop

Start Inner Loop
now we evaluate iter

G23_NA17192.fsa

rs312451

rs6599223

rs6788899

rs7374540

rs7428779
End Inner Loop

Start Inner Loop
now we evaluate iter

I23_Control.fsa

rs312451

rs6599223

rs6788899

rs7374540

rs7428779
End Inner Loop

Start Inner Loop
now we evaluate iter

K15_NA17162.fsa

rs312451

rs6599223

rs6788899

rs7374540

rs7428779
End Inner Loop

Start Inner Loop
now we evaluate iter

M15_NA17163.fsa

rs312451

rs6599223

rs6788899

rs7374540

rs7428779
End Inner Loop
Loop Out

(Except the above loop repeats 6 more times and the rs#s are for the entire
set and not just for the specific .fsa Ids).

Jul 17 '05 #1
0 2938

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4353
by: John Wilson | last post by:
Hello, I have the following code which populates as table data from a SQL Server 2000 stored proc (RSByDemoID2). Below that is the view and stored procedure which takes @DemoID as input to match to the event_id. For Q? and Comments I am viewing/updating in a different table than I am question and how_to_answer. The stored proc is populated by a view that I'm using to get all these values from two tables. My quandry is, I am getting the...
0
1767
by: mark | last post by:
My problem is I need to have a "nested" repeater. I have an array which I load into a hashtable - that part works great. I can setup the second repeater to work just fine, as long as it's not nested within the first repeater. If it is nested within the first repeater, I don't get any data. If I put the second repeater as a separate repeater, not nested, it works fine. Here's my actual code, showing data pulled from the array within a...
5
2208
by: Blankdraw | last post by:
I can't get this nested loop to break the outer loop at the 5th data value so control can proceed to the next array col and continue pigeon-holing the next 5 in its own column. Why can I not get this nested loop to make sense? This is the last holdup to completion of my silly project. Explaining it from the inside - out, I want to fill a 120-col X 40-row array with data from a file containing 120 data records of 5 2-digit entries per...
46
9929
by: Neptune | last post by:
Hello. I am working my way through Zhang's "Teach yourself C in 24 hrs (2e)" (Sam's series), and for nested loops, he writes (p116) "It's often necessary to create a loop even when you are already in a loop." Then he goes on to portray a contrived example that doesn't tell me under what conditions a nested loop might be favoured as a solution? i.e. what are nested loops useful for? What kinds of algorithms are served by nested loops?...
2
1909
by: mark | last post by:
(not sure if this is the correct group) My problem is I need to have a "nested" repeater. I have an array which I load into a hashtable - that part works great. I can setup the second repeater to work just fine, as long as it's not nested within the first repeater. If it is nested within the first repeater, I don't get any data. If I put the second repeater as a separate repeater, not nested, it works fine. Here's my actual code,...
8
1995
by: richardveitch77 | last post by:
I'm writting a peice of code for the numerical reconstruction of digital holograms. I have carried out a two dimensional fft using fftw. The output of which is stored in an array of fftw_complex. After the fft I need to manipulate the output array so I have used a nested for loop to cycle through the values. My code for the loop looks like this double intensity_array ; for (int xx=0 ; xx < width ; xx++)
77
5226
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop. Is this because .NET is inherently slower or does the C# compiler merely produce code that is not as well optimized as the C++ compiler?
5
2984
by: BMeyer | last post by:
I have been losing my mind trying to parse an XML document (with nested child elements, not all of which appear in each parent node) into a DataGrid object. What I want to do is "flatten" the XML document into a text document with a single row for each parent node (that has all of the values from all of the child nodes for that row) The DataView within VS 2005 IDE displays my 15 or so child tables - and knows that some parent rows...
7
5199
by: lawpoop | last post by:
Hello all - Is there a way to get a nested array in a $_POST variable? I have a form where there are several questions, each one corresponding to a database row. On submission of the form, I loop through the $_POST array, and update the database appropriately. So my post variable looks like this:
3
4486
by: numlock00 | last post by:
I have a nested 'while' loop that won't repeat, no matter how many times the outer loop repeats. The outer loop reads through an array of elements; the inner loop Ithe 'while' loop) is supposed to apply each of these elements while reading an input file. The outer loop is working fine. It will run through every element of the array. The inner loop, however, only runs once. Even though the outer loop finishes inormally, the inner loop does not...
0
8962
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8785
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9463
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9327
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9200
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6747
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4559
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2739
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2188
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.