Haroskyline Posted May 7, 2009 Share Posted May 7, 2009 I seem to be having a problem getting the contents of a selection box to show up. I'm working on an internship, and we're working on a site that works with a database to show records of students in a certain program. It has already been started, but there are quite a few bugs to yet be worked out. Basically 900+ lines of code have been handed over to me, and I'm now JUST learning PHP, very basic. So, I was wondering if someone could help me with a problem we've been having. <select name="sex" size="1" style="margin-left: 20px;"> <?PHP $result = $db->get_results("SELECT * FROM gender",OBJECT); foreach ($result as $key) { print "<option value=".$key->type.">".$key->desc."</option>"; } ?> <select name="schooldist" size="1" style="margin-left: 5px;"> <?PHP $query="SELECT * FROM schools"; $sresult = $db->get_results($query,OBJECT); foreach ($sresult as $key) { print "<option value=".$key['code'].">".$key['name']."</option>"; } ?> These two sections of code here, are supposed to access the database, and set variables to be selected in a selection box. But on the form, the selection box appears to be empty, and we can't figure out what is wrong with the code. There is this section, for determining the gender of the child, as well as a section for determining the school district they belong to. If more information is required, I will gladly answer any questions that could help you help me, and thank-you ahead of time. I'm just starting out with PHP, and hope to be on this site more often. Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/ Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 1. Why did you take the internship if you just started PHP? 2. echo > print 3. use var_dump($result) to know what is in $result. Though if you're working for a company, I doubt they would make their retrieval of DB columns that tacky. They probably have a way. I bet $result is an object instead of an array. Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828625 Share on other sites More sharing options...
Haroskyline Posted May 7, 2009 Author Share Posted May 7, 2009 1. Why did you take the internship if you just started PHP? 2. echo > print 3. use var_dump($result) to know what is in $result. Though if you're working for a company, I doubt they would make their retrieval of DB columns that tacky. They probably have a way. I bet $result is an object instead of an array. I had basic knowledge before hand, and isn't it supposed be a learning experience anyways? I can say I've learned exponential amounts already. In all cases is echo better? It's what I usually use, like I said I'm supposed to be improving on someone else's code. I'm looking at the code, where should I put var_dump($result)? I don't think it would be here, would it? $result = $db->get_results("SELECT * FROM gender",OBJECT); Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828643 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 1. It's supposed to be a learning experience, but it's a bit overwhelming if you just started. There are skill levels involved too. It's like telling a newbie to work on developing Expedia. It just won't happen and that person won't last. 2. echo sounds way cooler! I think it's faster than print too. Though some argue it's not. 3. After that line. Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828649 Share on other sites More sharing options...
Haroskyline Posted May 7, 2009 Author Share Posted May 7, 2009 1. It is very overwhelming indeed, but still a great opportunity. 2. I think one of them allows for variables to be placed inside while the other doesn't. 3. Alright, I put that in, but still nothing is showing up. For some reason it's not accessing the database. I'm going to double check the table names and such, you never know. If that doesn't work, I think I found a completely different code snippet that I can work with. Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828654 Share on other sites More sharing options...
Philip Posted May 7, 2009 Share Posted May 7, 2009 1. It is very overwhelming indeed, but still a great opportunity. 2. I think one of them allows for variables to be placed inside while the other doesn't. 3. Alright, I put that in, but still nothing is showing up. For some reason it's not accessing the database. I'm going to double check the table names and such, you never know. If that doesn't work, I think I found a completely different code snippet that I can work with. Yeah, I would have started smaller, but thats just me. Echo is a bit faster, but the difference is so small you won't notice a jump unless you're getting thousands of hits. The nice thing about echo is it takes in multiple parameters instead of having to concatenate everything. (e.g. echo $this, ' ', $that, (5*12), 'something' Do you know what class/methods they are using to connect to the DB? Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828664 Share on other sites More sharing options...
Haroskyline Posted May 7, 2009 Author Share Posted May 7, 2009 1. It is very overwhelming indeed, but still a great opportunity. 2. I think one of them allows for variables to be placed inside while the other doesn't. 3. Alright, I put that in, but still nothing is showing up. For some reason it's not accessing the database. I'm going to double check the table names and such, you never know. If that doesn't work, I think I found a completely different code snippet that I can work with. Yeah, I would have started smaller, but thats just me. Echo is a bit faster, but the difference is so small you won't notice a jump unless you're getting thousands of hits. The nice thing about echo is it takes in multiple parameters instead of having to concatenate everything. (e.g. echo $this, ' ', $that, (5*12), 'something' Do you know what class/methods they are using to connect to the DB? We're using mySQL. He just came in, and we got the idea that it might be a permissions error, and sure enough it was. The schools selection box populated, now to figure out the gender selection box. Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828676 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Echo is a bit faster, but the difference is so small you won't notice a jump unless you're getting thousands of hits. The nice thing about echo is it takes in multiple parameters instead of having to concatenate everything. (e.g. echo $this, ' ', $that, (5*12), 'something' And apparently using commas > using dots. I always forget that when I use echos because I tend to use dots. Bad habits die hard. *sighs* Haroskyline, KingPhilip asked you about the db class, not what database you're using. And what do you mean by "one of them allows for variables to be placed inside while the other doesn't"? Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828679 Share on other sites More sharing options...
Philip Posted May 7, 2009 Share Posted May 7, 2009 The reason I ask about the DB class, is because $db->get_results( ) is not a normal PHP method. I'm going to go out on a limb and say you're probably using wordpress, with their DB interaction? If so, Id recommend turning on errors (put this before your queries): $db->show_errors(); , or right after the query: $db->print_error(); Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828681 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Though, if you get Fatal errors on those, just take them out. KingPhilip is just guessing there. Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828684 Share on other sites More sharing options...
Haroskyline Posted May 7, 2009 Author Share Posted May 7, 2009 Google ended up working out for me, finally. I ended up using this code: <select name="schooldist" size="1" style="margin-left: 5px;"> <?php $sql = "SELECT * FROM schools"; "ORDER BY name"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { echo "<option value=\"".$row['code']."\">".$row['name']."\n "; } ?> </select> And it worked perfectly when the permissions were fixed. Thank-you for your help guys. Haha, now whenever you go to submit the information on the child, it skips right to error. Says the SSN is already taken. Oh, and for the class, he said it was EasySQL. Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828695 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 It worked, but if I were you, I would figure out that db class of yours because I doubt the company wants you to directly call mysql_query() when they have a class to handle these things. Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828704 Share on other sites More sharing options...
Haroskyline Posted May 7, 2009 Author Share Posted May 7, 2009 It worked, but if I were you, I would figure out that db class of yours because I doubt the company wants you to directly call mysql_query() when they have a class to handle these things. I'm sorry, I don't believe I fully understand what a class is, I suppose. :\ Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828717 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Wow, really!? You better start reading up on that. You're going to be doing most things in OOP. You should've started smaller. Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828721 Share on other sites More sharing options...
Haroskyline Posted May 7, 2009 Author Share Posted May 7, 2009 Google, Google, Google. :] I just took what was given to me. Sure, it would have been nice to start off smaller, but I don't think I had that option, honestly. Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828739 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Well, best of luck with your internship. You're going to need it, especially for at least the first month. Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828744 Share on other sites More sharing options...
Haroskyline Posted May 7, 2009 Author Share Posted May 7, 2009 Thanks, I'm not too worried though. This is a four week internship out of trade school in senior year. Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828748 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Thanks, I'm not too worried though. This is a four week internship out of trade school in senior year. And you just started PHP? Wow... Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828751 Share on other sites More sharing options...
Haroskyline Posted May 7, 2009 Author Share Posted May 7, 2009 Senior year in high school. Does that make a difference? Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828754 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 No, I know you're a senior in high school. I viewed your profile. Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828757 Share on other sites More sharing options...
Haroskyline Posted May 7, 2009 Author Share Posted May 7, 2009 No, I know you're a senior in high school. I viewed your profile. When did you start? Out of everyone I know locally, I know one person that knows PHP. [semi-Around my age] Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828758 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 It's not so much as when you start but how much experience you have in doing the job you have. I was referring to the fact that you're 4-weeks into the internship and you haven't learned what a class yet. I started around the age of 14, but I never really learned anything beyond the basics until 17. Of course at 14, I wasn't a hard core programmer. I was more into partying and playing sports and just having fun with friends. It's not so much of when you start but how much you know. For instance, if I were to tally up all the time I spent on PHP alone in my lifetime as of now, it wouldn't add up to more than a month total. Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828760 Share on other sites More sharing options...
Haroskyline Posted May 7, 2009 Author Share Posted May 7, 2009 No, it's not four weeks in, it's a four week internship. I'm going on two weeks. I'm not exactly being taught unless I run into a problem, I have to find things myself. For example: A Class is a blueprint for creating an Object. It tells you what variables (a.k.a. Properties) the Object can have, and what functions (a.k.a. Methods) can be used to manipulate the Object's Properties. Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828771 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 A Class is a blueprint for creating an Object. It tells you what variables (a.k.a. Properties) the Object can have, and what functions (a.k.a. Methods) can be used to manipulate the Object's Properties. Well, at least you know how to Google unlike some people here. Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828774 Share on other sites More sharing options...
Haroskyline Posted May 7, 2009 Author Share Posted May 7, 2009 I just lack direction in some aspects. :3 Quote Link to comment https://forums.phpfreaks.com/topic/157249-solved-selection-box-difficulties/#findComment-828779 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.