Darkmatter5 Posted April 25, 2008 Share Posted April 25, 2008 Using the following code examples, how do I get the "Surveyor" selected from the list to be populated to the $q variable in the first PHP tag? I don't know how to use the $_GET obviously so what I have in the code is an experiment from code from a tutorial site. <?php $q=$_GET["q"]; if(isset($_POST['submit'])) { include 'library/dbconfig.php'; include 'library/opendb.php'; $query="SELECT * FROM byrnjobdb.surveyors WHERE SurveyorID=$q"; $result="mysql_query($query)"; echo "$result"; include 'library/closedb.php'; } ?> <?php include 'library/dbconfig.php'; include 'library/opendb.php'; $query="SELECT SurveyorID, Surveyor FROM byrnjobdb.surveyors WHERE Active='1' ORDER BY Surveyor ASC"; $result=mysql_query($query); echo "<select name='Surveyor'>"; echo "<option>---Select---</option>"; while ($row=mysql_fetch_array($result)) { $r1=$row['surveyorID']; $r2=$row['Surveyor']; echo "<option value='$r1'>$r2</option>"; } echo "</select>"; include 'library/closedb.php'; ?> <input type="Submit" name="submit" id="submit" value="Load Record" /> Thanks! Link to comment https://forums.phpfreaks.com/topic/102924-help-putting-a-list-selection-into-a-variable/ Share on other sites More sharing options...
MadTechie Posted April 25, 2008 Share Posted April 25, 2008 could be a post or get so onr of these. <?php echo $_POST['Surveyor']; //OR echo $_GET['Surveyor']; ?> you can tell from this line echo "<select name='Surveyor'>"; Link to comment https://forums.phpfreaks.com/topic/102924-help-putting-a-list-selection-into-a-variable/#findComment-527221 Share on other sites More sharing options...
moselkady Posted April 25, 2008 Share Posted April 25, 2008 Add if statement inside the loop to check if the current surveyorID is the requested $q and in that case you would put "selected" in <option> tag while ($row=mysql_fetch_array($result)) { $r1=$row['surveyorID']; $r2=$row['Surveyor']; if ($r1 == $q) echo "<option value='$r1' selected>$r2</option>"; else echo "<option value='$r1'>$r2</option>"; } Link to comment https://forums.phpfreaks.com/topic/102924-help-putting-a-list-selection-into-a-variable/#findComment-527226 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.