Leech (?) content of mySQL tables

This is a discussion on Leech (?) content of mySQL tables within the PHP Language forums, part of the PHP Programming Forums category; Well, thank you both for your reaction. I looked at Pedro's option, but i do not wish to work ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-20-2004
knoak
 
Posts: n/a
Default Leech (?) content of mySQL tables

Well, thank you both for your reaction. I looked at Pedro's option,
but i do not wish to work with UPDATE, because that would only slow
down queries. (thanks for the effort anyway..)

So i looked at badr's option, and i'm really interested, but i found
out that somehow my host doesn't support INNODB types.

What my main goal is to be able to sort the animals by name of the
species.
Of course the species is referred to as an ID number. If species are
birds (id 1), fishes (id 2), and ants (id 3),

The ouput has to be: Instead of:
Forest ant (ants) Eagle
Red ant (ants) Forest Ant
Hawk (birds) Hawk
Eagle (birds) Red Ant
Shark (fishes) Shark
Whale (fishes) Whale

So the animals have to be ordered by something that's not in their
own table, and ordering by species id also is impossible because they
are
not entered in alphabeticaly order...

Later on, the website's admin has to be able to turn species AND
animals on and off, so the query should be this in theory:
SELECT species_names, animal_names FROM animals WHERE
species_status=on AND animal_status=on ORDER BY species_name

Where the species_names and species_status are only defined in the
'species'-table.

I hope it's clear, and that i'm not asking to much... (and that it's
not impossible...)

Greetings knoak
Reply With Quote
  #2 (permalink)  
Old 12-20-2004
Michael Fesser
 
Posts: n/a
Default Re: Leech (?) content of mySQL tables

.oO(knoak)

>Well, thank you both for your reaction. I looked at Pedro's option,
>but i do not wish to work with UPDATE, because that would only slow
>down queries. (thanks for the effort anyway..)


Eh? Of course you only have to use UPDATE when you actually want to
update something, like changing the species name from 'birds' to 'flying
animals'.

>What my main goal is to be able to sort the animals by name of the
>species.
>Of course the species is referred to as an ID number. If species are
>birds (id 1), fishes (id 2), and ants (id 3),
>
>The ouput has to be: Instead of:
>Forest ant (ants) Eagle
>Red ant (ants) Forest Ant
>Hawk (birds) Hawk
>Eagle (birds) Red Ant
>Shark (fishes) Shark
>Whale (fishes) Whale
>
>So the animals have to be ordered by something that's not in their
>own table,


Easy. After joining the species and animals tables together you can sort
on whatever column(s) you like. From Pedro's example:

SELECT s.description, a.name
FROM species s, animals a
WHERE a.species=s.id
ORDER BY s.description, a.name

or something like

SELECT description, name
FROM animals LEFT JOIN species s ON (species = s.id)
ORDER BY description, name

>Later on, the website's admin has to be able to turn species AND
>animals on and off


Will this be used just for a query to restrict the search result or is
it going to be stored in the database permanently?

>, so the query should be this in theory:
>SELECT species_names, animal_names FROM animals WHERE
>species_status=on AND animal_status=on ORDER BY species_name
>
>Where the species_names and species_status are only defined in the
>'species'-table.


Should be no problem.

Micha
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:53 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0