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

Weird query ??

Hi there,

I have a table with items in it.
Table contents are: id, title, text, combination

Each product has a few other products with
which it can be combined. In the 'combination'-
field is an array of 3 other id's the product
can be combined with. (e.g. 78-34-94)

When i run a query, i display 20 results / page,
so results are LIMIT-ed. How can i display 20
items with title, text, and then 3 links to
corresponding items in the 'combination' collumn.
The links have to be the titles of those other items.

Thanks in advance & greetings,

Knoak

Jul 17 '05 #1
7 1612
.oO(knoak)
I have a table with items in it.
Table contents are: id, title, text, combination

Each product has a few other products with
which it can be combined. In the 'combination'-
field is an array of 3 other id's the product
can be combined with. (e.g. 78-34-94)
Broken design. Use another table for the combinations of products, don't
put multiple informations into a single field (keyword: normalization).

table products
--------------
ID
title
text

table combinations
------------------
productID
combinationID

For a product with the ID 42 and your three combinations with other
products there would be three records in the second table:

42, 78
42, 34
42, 94
When i run a query, i display 20 results / page,
so results are LIMIT-ed. How can i display 20
items with title, text, and then 3 links to
corresponding items in the 'combination' collumn.


With your current design you would have to split the combination field
with PHP and send another query to the server to get the associated
records. With a better design you should be able to get all informations
with a single query.

Micha
Jul 17 '05 #2
Could you maybe explain a little bit more?
About how i would put this into reality?

Thanks!

Jul 17 '05 #3
*Anyone* ? Please...

Jul 17 '05 #4
knoak wrote:
*Anyone* ? Please...


1. Try searching the Internet on things like database normalization
2. Go to the library and check out a book on database design
3. Buy a book on database design

No, I'm not being flippant. Database design is not something you can
learn in a few messages. There are a few ways to do it right - and a
million ways to do it wrong!
Jul 17 '05 #5
I noticed that Message-ID: <4q********************************@4ax.com>
from Michael Fesser contained the following:
Each product has a few other products with
which it can be combined. In the 'combination'-
field is an array of 3 other id's the product
can be combined with. (e.g. 78-34-94)


Broken design. Use another table for the combinations of products, don't
put multiple informations into a single field (keyword: normalization).


Correctly normalising the data would be best but actually it would be
possible to do what he wants to do, provided he was consistent in the
way he stored the data. You would just explode the field into an array
and then produce the links from the array values.
$comb_id = explode("-", $myrow['combination']);

for ($i=0;$i<count($comb_id);$i++){
echo"<a href=\"lookuppage.php?id=".$comb_id[$i]."\">Combination
$i</a><br>\n";
}
Then in lookuppage.php use $_GET[id] as the basis of a query.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #6
Thanks Geoff,

But wouldn't this mean i'd have to run a query for every result?

Trying to understand the solutions everyone's providing.

Knoak

Jul 17 '05 #7
I noticed that Message-ID:
<11*********************@z14g2000cwz.googlegroups. com> from knoak
contained the following:
Thanks Geoff,

But wouldn't this mean i'd have to run a query for every result?


Yep.

But databases are good at that.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #8

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

Similar topics

3
by: redneck_kiwi | last post by:
Hi all: I have a really weird problem. I am developing a customer catalog system for my company and as such have delved into sessions for authentication and access levels. So far, I have managed...
2
by: jwbeaty | last post by:
Here's a weird one. I'm running SQL Server 7 and when I run a backup something weird happens. When I perform the backup via Enterprise Manager by right clicking on the database I want to...
7
by: Jon Combe | last post by:
I have created the following test SQL code to illustrate a real problem I have with some SQL code. CREATE TABLE JCTable ( CustomerName varchar(50) ) ALTER TABLE JCTable ADD CustomerNo int...
13
by: Dmitry Tkach | last post by:
Hi, everybody! Here is a weird problem, I ran into... I have two huge (80 million rows each) tables (a and b), with id as a PK on both of them and also an FK from b referencing a. When I try to...
0
by: Jeremy | last post by:
I have written my own URL rewriter, and it was working fine until i moved the re-writing code from App_BeginRequest to App_AuthorizeRequest. Now I get a 404 (file not found) error whenever the...
0
by: soup_or_power | last post by:
I use the DES_ENCRYPT and DES_DECRYPT with the string 'sfG3853ncr1pt' I can't seem to encrypt the number 227968199 because I tried several times and also tried other numbers which work fine. ...
11
by: Petulant | last post by:
Hello~ Help Please~ I am new to Access, so am a little behind the learning curve. I have a query that I have been running for a while that has worked fine and now (with no changes) is throwing up...
0
by: Henrootje | last post by:
I have a problem which I do not understand........................ I have a split database. Tables in the backend on a networkdrive, all other in frontend placed in %temp% I have this form ...
2
by: Drupan c | last post by:
Hello everybody i have a weird question... if u guys have observed when we use ms sql .. on the query box when we take the mouse pointer to the corner of a single line...
1
antonopn
by: antonopn | last post by:
Hello there, I have just faced a really weird problem with a query in SQL SERVER 2000. I had a database with collation SQL_Latin1_General_CP1_CI_AS and converted it in a new database with...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...
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,...

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.