Jump to content

Recommended Posts

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!
Link to comment
https://forums.phpfreaks.com/topic/14411-recalling-data-from-sql/
Share on other sites

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.
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!
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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.