Jump to content

Matt Ridge

Members
  • Posts

    196
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Matt Ridge's Achievements

Member

Member (2/5)

0

Reputation

  1. Aside from the DB connection lines, I provided just 4 lines of code that performs any actions. Did you even look at those lines and try to analyze what they are doing? This is not difficult stuff and we are trying to be patient. But, rather than try the code provided or even ask a question about the code provided you just restate what you are trying to achieve. So basically, I took time out of my day to help you and you completely ignored it. The code I provided will create a select list and auto-select the value that matches the value of $name. That is what you just said you wanted. If you don't want "--None--" in the select list then simple change $fabOptions = "<option value='--None--'>--None--</option>\n"; To this $fabOptions = ''; Here is the same logic with some comments added. <?php //For this to work properly, the variable $name //will contain the previously selected 'user' value //Connect to DB and run query to get list of 'user' values $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $mysqli->select_db('user'); $result = $mysqli->query("SELECT user FROM user"); //Create variable to hold the options HTML code //Set this to empty string if you don't want "--None--" $fabOptions = "<option value='--None--'>--None--</option>\n"; //Iterate through DB results of 'user' values while($row = $result->fetch_assoc()) { //Set the variable $selected to the HTML code to select the option //if the current DB value matches $name, else set to an empty string $selected = ($name && $name == $row['user']) ? " selected='selected'" : ''; //Create the HTML code for the option using the current 'user' value from the //DB results as the value and label for the option. Use the $selected variable //to set the selected status of this option $fabOptions .= "<option value='{$row['user']}'{$selected}>{$row['user']}</option>\n"; } //The lines below will output the select list and all the options generated above ?> <div id="fab1"> <select name='fab1'> <?php echo $fabOptions; ?> </select> </div> I should not have to provide that level of detail for every code snippet I provide. I only did it so I would not feel that I wasted my time in my first response today. This will be my last post to provide any assistance to you as I only volunteer my time here for the enjoyment of helping others who appreciate my help. Maybe you do appreciate the help, but I'm just not feeling it. Good luck to you. Actually I do appreciate the help, the fact you don't feel so is something you need to work on your own about. The reason I said you ran circles around me is because I read what you posted and didn't understand how it worked. I am learning as I go, I normally write my code myself, but when it comes to pull down menus I got code from other people's help, and have adapted it to what you have seen in front of you prior to your posts. You wrote the code in such a way that it didn't make any sense to me, because you went from what I had to a very small code... you may of described it in terms you understood, but obviously I didn't. I'm sorry you feel that I am wasting your time, but sometimes people have questions that you may find foolish, but to them is not. I believe that there is no such thing as a stupid question, perhaps you may not, so I am sorry, but next time you see one of my posts please ignore it then, because obviously you feel your help can be utilized better than responding to me when I thought I actually had a valid issue. This was one of the reasons I decided to go and learn programming people... because the people here that are gurus and other types think that people like me, people who actually are here to learn that may have a stupid question or two in other people's eye actually give attitude and look down upon people like me. I only came back here because of my employer requested something beyond my knowledge. At this point in time I expect to either be banned, or censured... honestly I'm not worried, because right now I don't think I'll be asking anything here any more, the attitude of people here have turned me off. I'll use stackechange instead, it may be not as fast in response time, but honestly I don't care any more. I don't need the attitude. Yes you people don't get paid, well guess what I don't get paid to post either. I only get a paycheck when I have a finished product. So, thank you for teaching me that people here that are admins, gurus, or others don't like what they perceive as stupid questions. Because honestly, there is no such thing as a stupid question. Just harmful answers.
  2. Ok, you just ran circles around me... What needs to be done, and what I've decided to do is instead of seeing if --None-- is required, just to view what is inside the table's field via the drop down menu. This means if my name "Matt Ridge" is selected and in the field in the database table that is the name that will show up in the drop down menu when this form is run: http://kaboomlabs.com/testbed/edit.php?id=1 The reason is so that when the person edits decides that my name doesn't belong there, they can choose the correct name, press submit and the correct name will be put in it's place. Then when they run the script again, said name will be in the place where mine once was. Does this make any sense?
  3. Ok, I've finality gotten time to sit down and take a look at this deeply, and I just about figured out till I realized you utilized PHP inside HTML, which throws my entire script for a loop... I'll work on making it so that it's XHTML and PHP separate later, for now I got to deal with the monster I was given now... <?php if ($row['fab1']=="--None--") { echo'<div id="fab1">'; $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $mysqli->select_db('user'); $result = $mysqli->query("SELECT * FROM user"); echo "<SELECT name='fab1'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['user']}'>{$row['user']}</option>\n"; } echo "</select>\n"; echo '</div>'; } else { echo'<div id="fab1">'; $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $mysqli->select_db('user'); $result = $mysqli->query("SELECT * FROM user"); echo "<SELECT name='fab1'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['user']}'>{$row['user']}</option>\n"; } echo "</select>\n"; echo '</div>'; } ?> The way I have it now, is well complex, I like your way of doing it, if I can get the code above down to half the size, I'd like it even more so. Basically I was thinking of this: <?php if ($row['fab1']=='$fab1') { echo'<div id="fab1">'; $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $mysqli->select_db('user'); $result = $mysqli->query("SELECT * FROM user"); echo "<SELECT name='fab1'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['user']}'></option>\n"; if ($name && $name == $value) { echo '$fab1'; } } echo "</select>\n"; echo '</div>'; ?> The problem is I know this won't work... can you help?
  4. And then from there instead of using the script I have, use yours, it looks a little more elegant anyway.
  5. $fab1 for now, the rest I'll be able to figure out on my own.
  6. $query = "UPDATE testbed SET ab = '$ab', date = '$date', part = '$part', rev = '$rev' , partdesc = '$partdesc' , ncmrqty = '$ncmrqty' , comp = '$comp' , ncmrid = '$ncmrid' , rma = '$rma' , jno = '$jno' , fdt = '$fdt' , cof = '$cof' , fab1 = '$fab1' , fab2 = '$fab2' , fab3 = '$fab3' , non = '$non' , dis = '$dis' , comm = '$comm' , caad = '$caad' , po = '$po' , pod = '$pod' , dri = '$dri' WHERE id = '$id'";
  7. I guess I was getting confused on the code that was escaping inside the query. So in this case it would be: $query = "UPDATE testbed SET fab1 = '" . mysqli_real_escape_string($dbc, $name) . "'$fab1"; Or do I have this wrong?
  8. I wish I could say yes, in understanding... but not really. Between what you have posted above and the section of what I ma suppose to do, how am I to incorporate that into the script I am using. That is the problem I am seeing. Also escaping after the query... I've never seen that before as far as I can tell. So sorry if I sound dense but what you are attempting to explain is a little over my head right now.
  9. This code is exactly what I am attempting to do: <?php if ($row['fab1']=="--None--") { echo'<div id="fab1">'; $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $mysqli->select_db('user'); $result = $mysqli->query("SELECT * FROM user"); echo "<SELECT name='fab1'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['user']}'>{$row['user']}</option>\n"; } echo "</select>\n"; echo '</div>'; } else { echo'<div id="fab1">'; $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $mysqli->select_db('user'); $result = $mysqli->query("SELECT * FROM user"); echo "<SELECT name='fab1'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['user']}'>{$row['user']}</option>\n"; } ?> Basically the second part is where you code you are talking about is going... if I am reading what you posted. Although I do have a question, why don't you want to escape string it? Won't that allow for injection?
  10. Basically 1 and 2 are correct. What I want for the last part is that I want is when a name has been entered into the database from the original document being posted is to see in the edit field, to see said name selected in the pull-down menu already as it's default choice. So when the form is submitted again, the same name will be entered into the field, instead of --None-- since that is the first choice in said pull-down menu.
  11. Here is where it gets interesting. There are two tables being used in this code, ncmr and user. User is what holds the user names in field $user for the pull-down field. Ncmr holds the $fab1 filed where the data is being stored. What I want to do is that if the $fab1 in the ncmr database has a name in it, the pull down menu will show the name unless --None-- was selected, and allow it to be changed if need be via a pull down menu which pulls names from the user table, then have the change if any be inserted into the ncmr database. Does this make any sense to anyone? I hope so because I really don't know how to say it any other way. Somehow I have a feeling if I have to we are going to be doing a "Who's on First" scenario.
  12. What I mean by separating PHP and XHTML in separate sections I mean one page two distinct areas. I use to do that, and then was told to not because it is better to wrap PHP around everything than to go in and out of PHP and XHTML... Ah. That's an odd suggestion, especially considering how larger PHP apps do things. Mostly HTML templates/views are the way to go. Like I said before, they should have just have the bare minimum amount of PHP to display the results of some other process. ~99% of them should be pure markup. Now you see why I probably get confused about how to do things a lot, being told and taught to do it one way, instead of another sort of bites one in the ass quite a bit.
  13. What I mean by separating PHP and XHTML in separate sections I mean one page two distinct areas. I use to do that, and then was told to not because it is better to wrap PHP around everything than to go in and out of PHP and XHTML...
  14. I'm more asking where to put this code... prior the submit button or during the post? It should be somewhere in your post handling code. It's probably too late to change now, but if you want to save some headaches in the future, you should separate as much PHP from your HTML as possible. Putting the vast majority of your PHP first will let you separate logic from presentation, and make everything a lot easier. Well-formed PHP scripts tend to look like: <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { // check to see if we're accessing the page via POST // all form handling code // this allows you to store results in variables and redirect the user (if necessary) without getting those // pesky 'Headers already sent' errors // this is also where error handling code goes } ?> <!-- HTML goes here. If written correctly, the only PHP you need here are statements echoing results, conditionals, and/or loops. Simple code with minimal logic to display errors or results. If you find yourself doing any processing, accessing the db, etc., you're doing it wrong. --> You should always strive to separate your concerns as much as possible. HTML has a different 'job' than PHP. HTML is only concerned with presentation. PHP is concerned with back end logic. The only PHP that should be in HTML is what is necessary to complete the presentation. Similarly, HTML and CSS should be separated, as HTML deals with layout and CSS with formatting. And JavaScript should be written unobtrusively (meaning no inline JS in your HTML) as JavaScript manipulates the document, but is not part of it. If you can think of code in terms of layered components, you'll have a much easier time. HTML is really just a skin on top of your app. You know this pisses me off to some extent, there seems to be a fight all the time about PHP vs XHTML & PHP split pages... Some people say that put the entire page in PHP, the other camp says as you do. You know I can do it both ways, but I don't know which one is right any more. I prefer to do XHTML and PHP separately but I've forced myself to do PHP only because "it is what people say to do" This is one of the reasons I wish there was a standard.
  15. I'm more asking where to put this code... prior the submit button or during the post?
×
×
  • 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.