The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
![]()
Say I have the following setup:
Code:
| table: athlete | +--------------------------------+ | id | name | sports +--------------------------------+ | 1 | 'John' | '1, 2' | table: sport | +----------------+ | id | title +----------------+ | 1 | 'soccer' +----------------+ | 2 | 'track' PHP Code:
Code:
John enjoys soccer & track If I had only 1 sport, say soccer, inside the `sports` field for row 1 of table `athlete`, I could do the following: PHP Code:
Code:
John enjoys soccer Maybe return a subarray containing the values? I understand I could easily insert the names of the sports into the `athlete` table, but in my real code things are much more complicated, and I might have the sport title change, therefore I would have to search every row in the `athletes` table that contains the prior sport name(s) and update it to the new name. Sorry if my wording is confusing, the actual concept isn't, and hopefully there is a way to simply this process to my needs. ![]() [originally posted at Sitepoint] |
#2
|
||||
|
||||
![]()
Why not have both queries and loop through them and create an array. Then work with it from there..?
|
#3
|
||||
|
||||
![]()
Well, that's what I'm doing in the first example. I'm just wondering if there is a way to do it in 1 query. :[]
|
#4
|
||||
|
||||
![]()
You're doing a query loop there. For every row you're running two queries. What I meant was to run both queries. Loop through them both and place their contents in two arrays. That way you have two queries?
|
#5
|
||||
|
||||
![]()
Why don't you use just one table instead of having 2 tables? That way you could pull all the info with 1 query.
![]() |
#6
|
||||
|
||||
![]()
In my real code, the tables are much more complex and so is how the data is handled. One table wouldn't work at all.
As for creating two arrays from two loops, that would lead me to having arrays with arrays with arrays in them, and all sorts of messy goodness. A suggestion by a member of Sitepoint (http://www.sitepoint.com/forums/show....php?p=1149531) was to create a 3rd table for containing the relations, and then using 1 query to access all the required data through an inner join. |
![]() |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|