Alexhoward Posted April 6, 2008 Share Posted April 6, 2008 Hi guys, firstly thanks for all the help i've recieved through this site, it's been invaluable to creating my site. Now it's finished however, i'd like to redisign... my question is this: At the moment i've got lots of pages with slighlty different code to pull data out of a table differently. What i'd like to do, is change the variable dynamically, so i can achieve the same results with less pages. so, say the bones of the code to pull the data was something like... SELECT * FROM 'table' $cat $subcat $sort I'd like to be able to select a category from a DHTML tree, and it will set the variables for that category e.g. - Mens Clothing so it would make to select code: SELECT * FROM 'table' WHERE cat ='fashion' and subcat ='mens' then you could press the sort by name (for example) and it would make it: SELECT * FROM 'table' WHERE cat ='fashion' and subcat ='mens' sort by 'company_name' I imagine i'd have to make everything a form, and have a giant list of IF's to make this work, but i'm still a semi noob and don't really know how to start. Thanks for your time and help in advance Alex Howard Quote Link to comment Share on other sites More sharing options...
Alexhoward Posted April 6, 2008 Author Share Posted April 6, 2008 can anyone point me in the right direction...? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 6, 2008 Share Posted April 6, 2008 If you're every considering a huge number of if statements, then dont. There's almost certainly a better way. What i would suggest is that you set up a couple of database tables: categories: id, name sub_categories: id, cat_id(the id of the categories this is a sub-category of), name You'll then want to pass the category id and sub-category id around in the URL. When your page loads, you'll grab these pieces of information and work out what is being displayed. You'll also display the relevant items. You can then add searching and sorting from there. Quote Link to comment Share on other sites More sharing options...
Alexhoward Posted April 6, 2008 Author Share Posted April 6, 2008 Hi, thanks for your reply. I can't start making other tables now, it took long enough to input all the data in to the one i've got. this has the columns company_name | cat | subcat | link | keywords and is already a few hundred rows long. searching works fine through the keywords column i assumed it would work like a sort button? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 7, 2008 Share Posted April 7, 2008 So you have hundreds of rows that contain, say, fashion in the cat field and mens in the subcat field? If so, i recommend you read up on database normalization. It will be easier in the long run. See this topic here and the pages it links to: http://www.phpfreaks.com/forums/index.php/topic,126097.0.html Quote Link to comment Share on other sites More sharing options...
Alexhoward Posted April 7, 2008 Author Share Posted April 7, 2008 Ok, so it's better to have lots of little tables. and join them all together. Surley the only problem is that if you were editing them manually, you'd have no idea what you where looking at with just int primary keys...? bubt i understand. this would however need a full re-build :-\ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.