473,382 Members | 1,726 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,382 software developers and data experts.

Loop

Hello,

I created a Linq query which returns a table has follows:

root_name down1_name down2_name down3_name
animal birdie NULL NULL
animal doggie companion chihuahua
animal doggie companion poodle
animal gerbil NULL NULL
mineral feldspar NULL NULL
mineral silica NULL NULL
vegetable carrot NULL NULL

I need to transform this table in a list as follows:

animal
birdie
doggie
companion
chihuahua
poodle
gerbil
mineral
feldspar
silica
vegetable
carrot

The list can be formed with ul and li ...

My first problem is how to find distinct values in root_name to create
the root items.
Then going fow from there ...

Could someone help me out with this?

Thanks,
Miguel
Jun 27 '08 #1
2 1213
shapper wrote:
Hello,

I created a Linq query which returns a table has follows:

root_name down1_name down2_name down3_name
animal birdie NULL NULL
animal doggie companion chihuahua
animal doggie companion poodle
animal gerbil NULL NULL
mineral feldspar NULL NULL
mineral silica NULL NULL
vegetable carrot NULL NULL

I need to transform this table in a list as follows:

animal
birdie
doggie
companion
chihuahua
poodle
gerbil
mineral
feldspar
silica
vegetable
carrot

The list can be formed with ul and li ...

My first problem is how to find distinct values in root_name to create
the root items.
Then going fow from there ...

Could someone help me out with this?

Thanks,
Miguel
If you made sure that the records are sorted on the root_name, you can
just keep track of the current name. Like:

string currentRoot = null;
foreach (something item in someList) {
if (currentRoot != item.root_name) {
if (currentRoot != null) {
// output end of ul tag
}
currentRoot = item.root_name;
// output currentRoot
// output start of ul tag
}
// output li tags
}
if (currentRoot != null) {
// output end of ul tag
}
--
Göran Andersson
_____
http://www.guffa.com
Jun 27 '08 #2
On Jun 26, 11:08*am, Göran Andersson <gu...@guffa.comwrote:
shapper wrote:
Hello,
I created a Linq query which returns a table has follows:
root_name * * down1_name * down2_name * down3_name
animal * * * * birdie * * * * * * *NULL * * * * *NULL
animal * * * *doggie * * * * * * * companion * * * * * * chihuahua
animal * * * *doggie * * * * * * * companion * * * poodle
animal * * * *gerbil * * * * * * * NULL * * * * * NULL
mineral * * * feldspar * * * * * * NULL * * * * * NULL
mineral * * * silica * * * * * * * NULL * * ** * NULL
vegetable * * carrot * * * * * * * NULL * * * * * NULL
I need to transform this table in a list as follows:
animal
* * birdie
* * doggie
* * * * companion
* * * * * * chihuahua
* * * * * * *poodle
* * gerbil
mineral
* * feldspar
* * silica
vegetable
* * carrot
The list can be formed with ul and li ...
My first problem is how to find distinct values in root_name to create
the root items.
Then going fow from there ...
Could someone help me out with this?
Thanks,
Miguel

If you made sure that the records are sorted on the root_name, you can
just keep track of the current name. Like:

string currentRoot = null;
foreach (something item in someList) {
* * if (currentRoot != item.root_name) {
* * * *if (currentRoot != null) {
* * * * * // output end of ul tag
* * * *}
* * * *currentRoot = item.root_name;
* * * *// output currentRoot
* * * *// output start of ul tag
* * }
* * // output li tags}

if (currentRoot != null) {
* * // output end of ul tag

}

--
Göran Andersson
_____http://www.guffa.com
Hi,

Well, in my Linq query I have ordered it by root_name.

Let me explain what I am doing. I am implementing in C# using LINQ the
adjacency model to hold some categories and subcategories:
http://www.sqllessons.com/categories.html

I need to create the following, which I think it will have the same
implementation:

1. Create a SelectList where each list item is filled with:
Name = Node Name (root_name, down1_name, ...)
Value = Node Id (root_id, down1_id, ...)

If the node is on root its name is as it is.
If the node is first level one @nbsp; should be added to the
beginning of its name.
If the node is second level two @nbsp; should be added to the
beginning of its name.

This is similar to what WordPress uses in Category selection.

2. Create an unordered list to display a site map.

I am adding the ID so I can edit categories.

Anyway, I already created the LINQ query which I think it is ok:

var categories = from root in database.Categories
where root.parentid = null
orderby root.name, down1.name, down2.name,
down3.name
join down1 in database.Categories on
down1.parentid equals root.id
join down2 in database.Categories on
down2.parentid equals down1.id
join down3 in database.Categories on
down3.parentid equals down2.id
select new {
root_id = root.id,
root_name = root.name,
down1_id = down1.id,
down1_name = down1.name,
down2_id = down2.id,
down2_name = down2.name,
down3_id = down3.id,
down3_name = down3.name
};

In this moment I am having problems with the loop.

I hope this time I explained everything well ... :-)

Any help is welcome.

Thanks,
Miguel
Jun 27 '08 #3

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

Similar topics

0
by: Charles Alexander | last post by:
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 ...
3
by: Anand Pillai | last post by:
This is for folks who are familiar with asynchronous event handling in Python using the asyncore module. If you have ever used the asyncore module, you will realize that it's event loop does not...
43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
5
by: Martin Schou | last post by:
Please ignore the extreme simplicity of the task :-) I'm new to C, which explains why I'm doing an exercise like this. In the following tripple nested loop: int digit1 = 1; int digit2 = 0;...
32
by: Toby Newman | last post by:
At the page: http://www.strath.ac.uk/IT/Docs/Ccourse/subsection3_8_3.html#SECTION0008300000000000000 or http://tinyurl.com/4ptzs the author warns: "The for loop is frequently used, usually...
2
by: Alex | last post by:
Compiler - Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland Linker - Turbo Incremental Link 5.65 Copyright (c) 1997-2002 Borland Platform - Win32 (XP) Quite by accident I stumbled...
3
by: Ben R. | last post by:
In an article I was reading (http://www.ftponline.com/vsm/2005_06/magazine/columns/desktopdeveloper/), I read the following: "The ending condition of a VB.NET for loop is evaluated only once,...
32
by: cj | last post by:
When I'm inside a do while loop sometimes it's necessary to jump out of the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my...
16
by: Claudio Grondi | last post by:
Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of...
2
ADezii
by: ADezii | last post by:
If you are executing a code segment for a fixed number of iterations, always use a For...Next Loop instead of a Do...Loop, since it is significantly faster. Each pass through a Do...Loop that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.