elmas156 Posted May 10, 2013 Share Posted May 10, 2013 OK, I know the topic title doesn't say much, but what I'm trying to do is fairly simple to explain. What I'm trying to do is to have real time inventory of specific items that are listed in my database. For simplicity, I'll just say that I have a two mysql query results that are identified in variables $total, and $used. By subtracting $used from $total, I get the number of items still available ($available). What I need to do is create a dropdown box that has numbers listed up to whatever amount is available. For example, if $available = 4, I need a dropdown box that has options 1,2,3, and 4. Any ideas on how to do this or what I should search for? I have found nothing so far. Thanks in advance for your help. Quote Link to comment Share on other sites More sharing options...
Solution Jessica Posted May 10, 2013 Solution Share Posted May 10, 2013 Really? $max = 4; echo '<select>'; for($i=1; $i<=$max; $i++){ echo '<option value="'.$i.'">'.$i.'</option>'; } echo '</select>'; Quote Link to comment Share on other sites More sharing options...
elmas156 Posted May 10, 2013 Author Share Posted May 10, 2013 Thank you for your help, I really appreciate the time that you and others take to help people who are learning the basics of php. I'm a little confused though, because you ask "Really?" as if this is a problem that one shouldn't have, or that even the newest of newbies should know. Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 10, 2013 Share Posted May 10, 2013 I'm a little confused though, because you ask "Really?" as if this is a problem that one shouldn't have, or that even the newest of newbies should know. I think she was referring to the latter. Not so much the "newest of newbies", but someone who knows at least the very basics of loop structures. I think you would have gotten a little more sympathy if you had shown at least an attempt. Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 10, 2013 Share Posted May 10, 2013 I also don't think someone with 250+ posts here can call themselves a newbie. Quote Link to comment Share on other sites More sharing options...
elmas156 Posted May 13, 2013 Author Share Posted May 13, 2013 I didn't say that I was a newbie, nor did I ask for anyone to do the work for me. If you look back to my original post, my question is this: "Any ideas on how to do this or what I should search for?" I have been dabling in php for a couple of years now, but I haven't been through any formal classes or anything of the sort. When I have a specific task that I would like to accomplish, I search google and online forums to figure out how to accomplish that task. Up until now, I haven't had the need to use a for loop to accomplish anything of this nature, and I don't have knowledge of "the very basics of loop structures," nor did I know exactly what to search for to find the answer that I needed. In this case, I searched for "php list numbers chronologicaly up to a specific value" and "php list numbers up to an assigned value." With these searches, I came up with no results that pointed me in the direction that I needed. However, had someone simply answered, "this can be accomplished using a for loop," I would have likely searched "php for loops," and found the result that leads to this page: http://www.w3schools.com/php/php_looping_for.asp, which is exactly what I was looking for. Jessica, I seriously do appreciate your help and your obvious extensive knowledge that you are willing to share with people who ask for help. I'm just saying that because someone posts a question that is trivial in your opinion, and they haven't shown any code that they've already tried, it doesn't mean that they haven't tried at all. In order to find something using a search engine or forums, you need to have some knowledge of what you're searching for. Sure, if you search "bag that a woman carries on her shoulder," you're going to get results for "shoulder bags" and "purses," but that's not always how it works for coding. Again, thank you for your help, but assuming that someone hasn't tried anything because the anwer is simple to you, only causes that person to be discouraged, and makes you look like a jerk, which, judging by your willingness to help others, I'm sure you are not. Thanks. Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 13, 2013 Share Posted May 13, 2013 If you don't know the basics of doing a loop in PHP, then yes you are a newbie. It's kind of one of the most basic things you can learn. Quote Link to comment Share on other sites More sharing options...
elmas156 Posted May 13, 2013 Author Share Posted May 13, 2013 Thank you for the advice, I will find a tutorial on loops and go through it for future reference. I have used while loops, but only in basic form, but that is the extent of my experience with any sort of loop. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 13, 2013 Share Posted May 13, 2013 a basic while(){} loop can be used to do this as well. 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.