SephirGaine Posted July 12, 2006 Share Posted July 12, 2006 Hey. Kind of feel lost since I've got two topics on the first page, however this question is quite a bit more complicated. I'll also see if I can't throw both my questions on here rather than creating two seperate topics.Right now, I have a login system working on my website. I also have a generator that creates a work order request depending on what the user entered. I have a database set up with the current employees' login, password, email, phone, and their full name. I need to use a script that recognizes which username is currently logged in for that session, then display the according name, email, and phone number onto the page. Basically, I just need to know where to start for this.My second question is similar as well. I need to create a drop-down list on the form that the user entered in order to create the work request. That drop-down list would list the current techs and contracters that we use. Then, depending on which tech the user selects, it will display that tech's information onto the work order. However, since that will be pretty much the same as my first question, just using one more variable, my main question is about how to display database entries within a dropdown menu, within a form.I know the basic logistics about how to get this working, however I really don't know where to start. So, any/all help will be much appreciated. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/14411-recalling-data-from-sql/ Share on other sites More sharing options...
brown2005 Posted July 12, 2006 Share Posted July 12, 2006 well i use $_SESSION['MemberID'] = $login_array['members_id']; in the login script and then use this to select the member from the database Quote Link to comment https://forums.phpfreaks.com/topic/14411-recalling-data-from-sql/#findComment-56953 Share on other sites More sharing options...
akitchin Posted July 12, 2006 Share Posted July 12, 2006 i don't know how your login system works specifically, but once a user has logged in successfully you should be able to assign their unique identifier (be it an actual ID, or their username, or whatever will identify them) to a $_SESSION variable which will propagate with them as they browse the site. you can then use this $_SESSION value in your work order builder (simply use the user's value in the query as you would any other piece of info).as to the second question, this is merely a matter of some looping with a query:[code]<?php$query = "SELECT id, name FROM techies ORDER BY name ASC";$resource = mysql_query($query);if ($resource !== FALSE){ while ($tech_info = mysql_fetch_assoc($resource)) { echo '<option value="'.$tech_info['id'].'">'.$tech_info['name'].'</option>'; }}?>[/code]that's a simple bit of code that you can pluck in between a <select></select> form element to echo one option in the dropdown box for each tech. if you just want to use their name, then there's no need to employ the "value" attribute in each <option> tag. don't forget to change the query, and feel free to fiddle with the code itself.hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/14411-recalling-data-from-sql/#findComment-56955 Share on other sites More sharing options...
SephirGaine Posted July 12, 2006 Author Share Posted July 12, 2006 I'll give it a shot. Thanks for the help!Also, a quick side question. Someone from another forum mentioned using a cookie when the user logs in, that would store all the information that I have in my database table from that user. Would I then be able to recall the information within the cookie onto a webpage? If so, it sounds like that might be the easiest solution for future expansion on the website, so I might want to take a look into that as well. For now, I'd like to get this request form working properly before revamping anything, but I'd like to get some second-hand input on the cookies idea as well.Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/14411-recalling-data-from-sql/#findComment-56977 Share on other sites More sharing options...
SephirGaine Posted July 13, 2006 Author Share Posted July 13, 2006 Quick follow-up question. I used that code ya gave me, modified it a bit with my own options, however I'm getting two listings where the techs' names should be. They are both called 'Array.'I'm not sure if I'm recalling the incorrect data or perhaps the page is not properly connected to the database. So any help would be appreciated.[code]<?php$query = "SELECT Name FROM Techs ORDER BY name ASC";$resource = mysql_query($query);if ($resource !== FALSE){ while ($tech_info = mysql_fetch_assoc($resource)) { echo '<option>'.$tech_info.'</option>'; }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14411-recalling-data-from-sql/#findComment-57647 Share on other sites More sharing options...
kenrbnsn Posted July 14, 2006 Share Posted July 14, 2006 The output of the mysql_fetch_assoc() function is an array, you need to reference an entry in the array. Since you asked for the field "Name", you would use:[code]<?php echo '<option>'.$tech_info['Name'].'</option>'; ?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/14411-recalling-data-from-sql/#findComment-57665 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.