Xtremer360 Posted December 19, 2009 Share Posted December 19, 2009 This code is apart of my edit form and for this select field I'm wanting to know how do I find out which is the right style that matches against the database put in the database. <select name="style" class="dropdown"> <option value="0">- Select -</option>'; <?php $query = 'SELECT name FROM efed_list_styles LIMIT 2'; $result = mysql_query ( $query ); while ( $row = mysql_fetch_assoc ( $result ) ) { print "<option value=\"".$row['name']."\">".$row['name']."</option>\r"; } ?> </select> Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted December 20, 2009 Author Share Posted December 20, 2009 *bump* Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted December 20, 2009 Author Share Posted December 20, 2009 Perhaps none of that made sense. Say I have a form that calls the data of a particular user and in that data is from a column called style and the value from that column is singles. Now with the select box I want it to scroll through the list of options it has with its little query and select the option called singles to match what's in the DB. Quote Link to comment Share on other sites More sharing options...
nafetski Posted December 20, 2009 Share Posted December 20, 2009 Heya I'm not 100% sure what you're asking unfortunately. What do you mean by style? Are we talking CSS, or are we talking about best practices for programming? Typically, you don't want to have your SQL/database code inline with your presentation code (your html). It still works, it's just not the best style. Once again - not 100% sure what the question is Is your code not working? Quote Link to comment Share on other sites More sharing options...
jeremywesselman Posted December 20, 2009 Share Posted December 20, 2009 So you have a select box in a form. The values from the select box are pulled from the 'efed_list_styles' table. You have a user table that has a column called style. You want to find out which of the styles from 'efed_list_styles' is in the user table column 'style'. Right so far? If so, all you have to do is add an if statement to check if the user column 'style' matches the 'efed_list_styles' column. I'm going to assume you have already pulled the information from the user's table and it is stored in $user. <select name="style" class="dropdown"> <option value="0">- Select -</option>'; <?php $query = 'SELECT name FROM efed_list_styles LIMIT 2'; $result = mysql_query ( $query ); while ( $row = mysql_fetch_assoc ( $result ) ) { print "<option value=\"".$row['name'] . "\"; if ($row['name'] == $user['style']) { print " SELECTED"; } print ">" . $row['name']."</option>\r"; } ?> </select> **Untested Should be something like that. Might need to tweak it a little bit. Jeremy Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted December 20, 2009 Author Share Posted December 20, 2009 That is exactly what i'm looking for however what does the user part stand for? This is where my code is from: case 2: echo $e; require_once('../backstagefunctions.php'); require_once('../backstageconfig.php'); $id = $_GET['id']; $query = mysql_query("SELECT * FROM `efed_list_titles` WHERE `id` = '" . $id . "'"); $row = mysql_fetch_array($query); ?> <h1 class="backstage">Title Management</h1><br /> <h2 class="backstage">Edit Title</h2><br /> <form name="edittitle" method="post"> <input type="hidden" name="action" value="title" /> <table width="100%" class="table2"> <tr> <td width="120" class="rowheading" valign="center">Short Name:</td><td class="row3"><input type="text" name="shortname" class="fieldtext140" value="<?=$row['shortname'];?>"></td> </tr> <tr> <td width="120" class="rowheading" valign="center">Name:</td><td class="row3"><input type="text" name="name" class="fieldtext490" value="<?=$row['name'];?>"></td> </tr> <tr> <td width="120" class="rowheading" valign="center">Style:</td><td class="row3"> <select name="style" class="dropdown"> <option value="0">- Select -</option>'; <?php $query = 'SELECT name,id FROM efed_list_styles LIMIT 2'; $result = mysql_query ( $query ); while ( $row = mysql_fetch_assoc ( $result ) ) { print "<option value=\"".$row['id']."\"; if ($row['name'] == $user['style']) { print " SELECTED"; } print ">" . $row['name']."</option>\r"; } ?> </select></td> </tr> <tr> <td width="120" class="rowheading">Status:</td><td class="row3"> <select name="status" class="dropdown"> <option value="0">- Select -</option> <?php $query = 'SELECT name FROM efed_list_status'; $result = mysql_query ( $query ); while ( $row = mysql_fetch_assoc ( $result ) ) { print "<option selected=\"selected\" value=\"".$row['id']."\">".$row['name']."</option>\r"; } ?> </select></td> </tr> </table><br /> <input type="checkbox" name="deletetitle"><span class="table1heading">Delete Title?</span><br /><br /> <input type="hidden" name="oldname" value="<?php echo $row['name']; ?>"> <input type="hidden" value="true" name="editted" /> <input type="submit" value="Edit Title" class="button"><br /><br /> <input type="button" value="Return to Title List" class="button200"><br /><br /> </form> <?php returnmain(); break; Quote Link to comment Share on other sites More sharing options...
jeremywesselman Posted December 20, 2009 Share Posted December 20, 2009 I thought you said you wanted to find which 'efed_list_style' that matched the 'style' column in the user table. That's what you're second description sounded like to me anyways. But it looks like in the code you've shown now that it is not in the user's table. Jeremy 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.