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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
.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 |