Jump to content

Buchead

Members
  • Posts

    59
  • Joined

  • Last visited

Everything posted by Buchead

  1. Thanks for all the help but I'm still experiencing problems extracting the correct information. It clearly down to being new to mysql and attempting something other than the basics! Using 'SELECT * FROM products_tree WHERE sectionID IN (1,4)' pulls out all the records which have those sectionIDs and not just productIDs that match both the sections. If I put that query as a subselection it pulls out no records. How can I set it so that it only pulls the productIDs that match both the sectionIDs? Sorry if this is obvious but it's not to me!
  2. Thanks for that. By using: SELECT productID, sectionID, count(productID) FROM products_tree GROUP BY productID HAVING count(productID) = 2 it displays the product IDs that have multiple enteries. However, I can't seem to get it pulling off only those records where one of the section IDs matches a specific criteria. By viewing the sectionID pulled from the query it's showing the same for all the records (which is only one section ID I want to search for). products_tree looks like: productID    sectionID     1                 1     2                 1     3                 1     1                 2     4                 1     5                 1     4                 3 It's pulling off productIDs 1 and 4, but showing sectionID '1' for both of them. I'd want to search for productIDs with sectionID's of 1 and 3, thus pulling off 1 record, but can't seem to add in any other search parameters. Any ideas? Thanks.
  3. Hello, Please can someone point me in the right direction. I have 2 tables called products and products_tree. products contains 5 fields (productID, name, height,  length, weight) and products_tree contains 2 fields (productID and sectionID). It's possible for products to be in more than 1 section, so there would be mulitple enteries in products_tree. What I'd like to do it select the items from products where they're in multiple sections. For example: In products, an item has productID of 10. It's listed in sections 4 and 5, so there are 2 enteries in products_tree, so productID  sectionID     10              4     10              5 I've been unable to find the command that checks products_tree for any productID that match the 2 sectionIDs, and then retrieve this productID data from products. Is it actually possible to perform in one command, or am I heading in an impossible direction? Thanks, Clive.
  4. Thanks. Realised what I was doing wrong. Had 2 sql queries and I'd filled in the wrong one. Completely down to user error!
  5. Hello, Wondering if anyone can point me in the right direction. I have the following command: "SELECT * FROM products_tree, products WHERE products_tree.sectionID = '$section' AND products.productID = products_tree.productID AND products.keywords LIKE '%$search%'" It works ok. Checks the products_tree table for the given section number, and then retrieves the relevant data from products for the given productID and the keywords match the criteria. However I'd like to order the output by products.code as it's simply outputting in the order retrieve from the database. I've added in an ORDER BY clause but that had no effect. What am I doing wrong? Thanks, Clive.
  6. Hello..... I've just installed apache/mysql/php/phpmyadmin on an XP machine, and whilst it all works fine, when I write a page to retrieve any data from the database I get a completely blank page. No errors about not connecting to the database (tried using wrong password); just get nothing at all. If I have a standard php page that doesn't involve a database it works fine! phpmyadmin allows me to update the databases, so that side of it appears to be ok. It's running: Apache/1.3.34 (win32) PHP 5.1.1 Mysql 5.0 phpmyadmin 2.7.0 I've installed it on another PC (albeit slightly different versions) and it works fine, so I know my coding is ok! Is anyone able to suggest what I've done wrong? Thanks.
  7. Thanks for that - gives me somewhere to start. Unfortunately I didn't create the database. It's been long-existant in work and they won't let me change it. And my manager, like all managers, thinks it's easy to get the desired results! Though I guess it is if you've used php before. Thanks again.........
  8. The tables (5 of them) all have the same structure: Name - varchar(35) Address - varchar(200) Service - tinyint Dept - char(10) I use the following to obtain a list of all the tables: $tbls = @mysql_query("SHOW TABLES"); A loop then goes through retrieving the data and populating the array:- $result=@mysql_query("SELECT * FROM `$tbl` WHERE (`Name` LIKE '%$search%' OR `Dept` LIKE '%$search%') ORDER BY `Name`,`Service`",$link); I'm unsure how to get this command to put the output into the correct order as it's simply looping through the tables, rather than having the ability to jump between tables. Where about should I put the var_export as it throws up an error wherever I seem to put it. Thanks.
  9. Hello.... I have an array that consists of multiple class items. The number of items depends upon what's read in from the database. I'm having trouble sorting the array based on one particular class item. The class item consists of personal information (name, address, time of service, dept) and the array is populated depending upon which dept is required. I'd like to have the output then sorted by time of service. I can get it displaying fine as in the order it's read from the database and stored in the array. Due to the information being in different tables I can't find a way to simple sort it using a mySql command. I've tried creating a new array and populating it each of the original array using the time of service as a key. But that doesn't work, and I'd think it's a very bad route to take. I "think" I know how to solve it but just know the commands! Thanks for any help, Clive.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.