Jump to content

Help with a Select statement


Landslyde

Recommended Posts

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 :)

Link to comment
Share on other sites

<?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 by Barand
  • Like 1
Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.