Landslyde Posted March 1, 2015 Share Posted March 1, 2015 I have a db with this therapist's client info. I fixed him a page to view that. I fill a select box's options with the client fname and lname from the MySQL db for him to chose whose details he wants to view. Seemed like a great idea. But now that I have the Select value as a combination of $row[1] and $row[2], I'm at a complete loss as to how to select from the db. I tie the two together like so: <select name="view" style="margin-left: 15px; margin-top: 15px; font-size: 1em;"> <option>All</option> <?php require_once 'login.php'; $stmt = $db->prepare('SELECT * FROM attendees ORDER BY lname'); $stmt->execute(); $result = $stmt->fetchAll(); foreach($result as $row){ ?> <option><?php echo $row[1],' ',$row[2]; ?></option> <?php } ?> </select> Fact is, I'm dead in the water with this. I like the idea of making it convenient for the therapist by giving him this dropdown box, but I have absolutely no idea how to form the Select statement with an option value like John Doe. If I had to I cld remove one of the name fields and simply have him enter first and last names at the same time in one field. But that looks sort of cheesy, you know. Does anyone have any ideas on how to better do this? Ideas are cool...I'll take it from there. I'm not here to get you guys to code for me, just help me with a little thinking, something that's not my best friend right now Quote Link to comment Share on other sites More sharing options...
tryingtolearn Posted March 1, 2015 Share Posted March 1, 2015 Assuming attendees has an id field that is unique pass that as the option value to get the details to view <option value="<?php echo $row[WHATEVER THE ID ROW IS HERE]; ?>"><?php echo $row[1],' ',$row[2]; ?></option> 1 Quote Link to comment Share on other sites More sharing options...
Barand Posted March 1, 2015 Share Posted March 1, 2015 (edited) <?php require_once 'login.php'; $stmt = $db->prepare('SELECT * FROM attendees ORDER BY lname'); $stmt->execute(); $result = $stmt->fetchAll(); foreach($result as $row){ ?> <option><?php echo $row[1],' ',$row[2]; ?></option> <?php } ?> You are already inside a PHP block (shown in blue) so the red elements should not be there. You need to echo the <option> line echo "<option value='$row[0]'>$row[1] $row[2]</option>"; // assuming $row[0] is the attendee id Don't use "select * ", specify just the three columns you need Edited March 1, 2015 by Barand 1 Quote Link to comment Share on other sites More sharing options...
Landslyde Posted March 1, 2015 Author Share Posted March 1, 2015 Barand: tryingtolearn: You guys are the best! Before I fell asleep at abt 6am, I was wondering if I cld set the value of the option to the ID, to $row[0]. Jumped out of bed just now and see that you guys confirmed that. And also provided examples. Really good forum with class acts here! Thank you both. Much appreciated 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.