473,405 Members | 2,379 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,405 software developers and data experts.

Best way to handle One-To-Many resultset

bilibytes
128 100+
Hi,

I have a database with a one to many relationship and i was wondering what was the best way to parse the resultset.

this post explains exactly what my situation:
http://stackoverflow.com/questions/5...o-many-results

I don't have PDO neither MySQLi

So if you go to the post, you'll see that there are 2 solutions.

the first solves the problem in MySQL with Concat()
and the second solves it in PHP. it puts if() conditions in a while() loop.

I would finally like an array like this:

Expand|Select|Wrap|Line Numbers
  1. $elements = array(
  2.                                   0=>array(
  3.                                          'url_id'=>'id_1',
  4.                                          'categories'=> array(
  5.                                                              0=>'category1',
  6.                                                              1=>'category2'
  7.                                                               )
  8.                                          )
  9.                                   1=>array(
  10.                                          'url_id'=>'id_2',
  11.                                          'categories'=> array(
  12.                                                              0=>'category1',
  13.                                                              1=>'category2'
  14.                                                               )
  15.                                          )
  16.                                   ...
  17.                                )
  18.  
As you can see i don't want to concat. If i used concat() in MySQL i would then have to explode the string.
but i woudn't have to put conditions in my while() loop.

What do you think would be faster?

If you have any experience doing it,
please let me know it would save my some time in testing

Thank you very much

Regards
Jul 19 '09 #1
2 2030
wizardry
201 100+
you will want to use concat on both the app and database. how ever if you have the option to use functions, procedures, triggers on your server then to answer your next question the app will run faster if its coded into the database.

but their is only so much you can do with mysql database. I love oracle!

i will give you this much: a true web application is ran from the database and vice versa.

hope this helps!
Jul 21 '09 #2
bilibytes
128 100+
thanks for your answer,

but i have to admit i dont really understand what you mean.

why should i concat on both sides (in database and in the app)?

if i concat in the database then there is nothing to concat in the app...?

i mean if i have many records and use concat() AS concatenatedRows, i then get something like this:

Expand|Select|Wrap|Line Numbers
  1. while($row = mysql_fetch_array(...)){
  2.    ( $row['url_id'] == 'id1'
  3.     $row['concatenatedRow'] == 'row1 row2 row3 row4')
  4.  
  5.     $rowsArray[] = $row;
  6. }
and here there is nothing to concat, i would need to explode the 'concatenatedRow' string to get what i want:

Expand|Select|Wrap|Line Numbers
  1. while($row = mysql_fetch_array(...)){
  2.    ( $row['url_id'] == 'id1'
  3.     $row['concatenatedRow'] == 'row1 row2 row3 row4')
  4.     $row['concatenatedRow'] = explode(' ', $row['concatenatedRow'])
  5.     $rowsArray[] = $row;
  6. }
thus getting the array i showed you in my first post.

so i don't understand what you would like to concat.

However i would be pleased to know what you mean.

thank you again


bilibytes
Jul 23 '09 #3

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

Similar topics

7
by: Gemini | last post by:
Hello I am looking for the best content/article manager software, perferred open source, php, mysql backend.. can anyone recommend me one? I think that the best discussion is phpbb, the...
4
by: matt cook | last post by:
Which existing directory script is the best one?
12
by: python | last post by:
In a file there can be several dictionaries like this {Key11: Value11 Key12: Value12 Key13: Value13, .... .... Key1n:Value1n} {Key21: Value21 Key22: Value22 Key23: Value23,
1
by: Matthew Houseman | last post by:
All, What's the accepted best practice for persisting data? Commit by the PL/SQL or commit by the caller (C#, Java, VB, etc.). I believe that if the caller starts a transaction and calls...
1
by: ctfilter | last post by:
I'm looking for an open source app. that can handle reverse and dutch auctions. Preferably something with user friendly UI. Ideas??? Thanks! -- Paul
0
by: kiplring | last post by:
I'm using managed directx. I made a KeyFrameInterpolator object. And get a exception above. I think it is because GC reconize KeyFrameInterpolator object as Pinned object. So I added next line....
2
by: Jon | last post by:
Hi I've created a HANDLE in a managed class: pHandle = new HANDLE; where pHandle is HANDLE* defined in my __gc class Is this an unamanged or a managed pointer? I would have thought it...
0
by: Jay | last post by:
Hey There, When I run the code below, I get the error "The handle is invalid." .. This is output in the 2nd fprintf. The first one gives me a success message. What could be causing this? -Jay...
1
by: subrahmanya | last post by:
Hi All A process spawns another process and it inherits all the parent process handles. While the child process is existing if parent process closes a file handle will the corresponding handle...
5
by: Joe | last post by:
We're looking for a fully functional RTF/HTML editor for our WinForms application. We need a control with the following features: 1. Supports image 2. Supports hyperlinks (auto detects) and...
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?
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
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...

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.