lil_bugga Posted May 15, 2009 Share Posted May 15, 2009 Hi guys, I posted a topic a few days ago having problems with my navigation system, I've still had no replies on that to help so I'm trying a new way. I'm thinking of: [*]1st creating $num to store highest id no. from store_category [*]then creating $i = 0 [*]then starting loop whilst $i <= $num, start building display block[] [*]then make a query to get store_category title that is the equivilant of $i [*]then make a query to get any sub links [*]incriment $I =$i +1 [*]end loop each new iteration should now get the main link and any 2nd level links then i should be able to display the blocks The problem i'm having at the moment is retrieving the highest value, this is what I have so far <?php //connect to server and select database; you may need it $mysqli = mysqli_connect("localhost", "xxx", "xxxxx", "test"); //show categories first echo "php start<br /><br />"; $num = "SELECT MAX(id) FROM store_categories"; $res = mysqli_query($mysqli, $num); if (res) { echo $res; } echo "<br /><br />php end"; //close connection to MySQL mysqli_close($mysqli); ?> What i'm trying to achieve overall is a block like this, then where i have the options of beginners, kids and adults I could have many more options all taken from my database <a href="javascript:display('$id')" class="Group">~" $cat_title "~</a> <div class="hide" id="$id"> <a href="#" class="Option">Beginners</a> <a href="#" class="Option">Kids</a> <a href="#" class="Option">Adult</a> </div> Thanks in advanced for any help Quote Link to comment https://forums.phpfreaks.com/topic/158268-retrieve-highest-value/ Share on other sites More sharing options...
Zhadus Posted May 15, 2009 Share Posted May 15, 2009 I guess I'm not the only one that doesn't have a clue for what you're trying to do. How is your database setup and what exactly are you trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/158268-retrieve-highest-value/#findComment-834798 Share on other sites More sharing options...
lil_bugga Posted May 15, 2009 Author Share Posted May 15, 2009 Basically I have two tables for items in a mock shop store_categories id cat_title cat_desc 1 Hats Funky hats in all shapes and sizes! 2 Shirts From t-shirts to sweatshirts to polo shirts and be... 3 Books Paperback, hardback, books for school or play and store_subcategories subcat_id cat_id subcat_title 1 3 Adult Books 2 3 Childrens Books 3 3 Educational Books 4 3 Reference Books 5 2 Mens Tops 6 2 Boys T-ops 7 2 Ladies Tops 8 2 Grils Tops 9 1 Causal Hats 10 1 Party Hats 11 1 Fishing Hats 12 1 Sports Hats I'm attempting to load these so that I can have my navigation update just from the database so I can add and remove lines without all the effort. When I was mocking up my site I was using javascript to manage my navigation and its different levels. This is the javascript navigation I had in place before hand, basically when i clicked the main link the div changes from hidden to visible. <a href="javascript:display('Books')" class="Group">~ Books ~</a> <div class="hide" id="Books"> <a href="#" class="Option">Beginners</a> <a href="#" class="Option">Kids</a> <a href="#" class="Option">Adult</a> </div> I'm trying to get my SQL code to produce this block of code from me substituting the hard coded values like books from the example above with the categories from store categories table. hope this helps make it clearer Quote Link to comment https://forums.phpfreaks.com/topic/158268-retrieve-highest-value/#findComment-834918 Share on other sites More sharing options...
lil_bugga Posted May 15, 2009 Author Share Posted May 15, 2009 any one any ideas or am I still loosing you all? Quote Link to comment https://forums.phpfreaks.com/topic/158268-retrieve-highest-value/#findComment-834997 Share on other sites More sharing options...
.josh Posted May 15, 2009 Share Posted May 15, 2009 Umm...why not just ORDER BY id DESC in your query to begin with...example: SELECT * FROM table ORDER BY id DESC will return all your rows, ordered by id, in descending order. Quote Link to comment https://forums.phpfreaks.com/topic/158268-retrieve-highest-value/#findComment-835018 Share on other sites More sharing options...
.josh Posted May 15, 2009 Share Posted May 15, 2009 wait wait, didn't read your next post. Okay what you want to actually do is a join. SELECT store_categories.cat_id, store_categories.cat_title, store_subcategories.subcat_title FROM store_categories, store_subcategories, WHERE store_categories.cat_id = store_subcategories.cat_id ORDER BY store_categories.cat_id DESC and then you should get returned cat_id cat_title subcat_title 3 Books Adult Books 3 Books Childrens Books 3 Books Educational Books 3 Books Reference Books 2 Shirts Mens Tops 2 Shirts Boys T-ops 2 Shirts Ladies Tops 2 Shirts Grils Tops 1 Hats Causal Hats 1 Hats Party Hats 1 Hats Fishing Hats 1 Hats Sports Hats Quote Link to comment https://forums.phpfreaks.com/topic/158268-retrieve-highest-value/#findComment-835025 Share on other sites More sharing options...
lil_bugga Posted May 16, 2009 Author Share Posted May 16, 2009 thats not what i was looking to get results wise but thanks anyway. I'm trying a different method now so I'll see how that goes Quote Link to comment https://forums.phpfreaks.com/topic/158268-retrieve-highest-value/#findComment-835064 Share on other sites More sharing options...
.josh Posted May 16, 2009 Share Posted May 16, 2009 ...and what is wrong with that result? a loop, couple of conditions to display certain things at certain times, and you've got exactly what you're asking for. Quote Link to comment https://forums.phpfreaks.com/topic/158268-retrieve-highest-value/#findComment-835075 Share on other sites More sharing options...
Ken2k7 Posted May 16, 2009 Share Posted May 16, 2009 I'm guessing you don't have the subcat_id column that lil_bugga wanted. Quote Link to comment https://forums.phpfreaks.com/topic/158268-retrieve-highest-value/#findComment-835078 Share on other sites More sharing options...
lil_bugga Posted May 16, 2009 Author Share Posted May 16, 2009 ...and what is wrong with that result? a loop, couple of conditions to display certain things at certain times, and you've got exactly what you're asking for. Please see my new topic, i think that demonstrates and explains what I want a lil more clearly, it just be me getting it wrong as im new to php. http://www.phpfreaks.com/forums/index.php/topic,252495.msg1185812.html#msg1185812 Quote Link to comment https://forums.phpfreaks.com/topic/158268-retrieve-highest-value/#findComment-835081 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.