Solved

How would I do this?

Posted on 2013-02-01
2
230 Views
Last Modified: 2013-02-02
I have a pull down menu that features the full name of a student. The list is based off of a query where I'm just listing all the students and coupling their first and last name as a string (<?php echo stripslashes($first_name).' '.stripslashes($last_name); ?> I need to process that name by breaking it apart and grabbing the id attached to that row that contains both the first name and the last name.

So, I'm thinking that there's some php magic that allows me to break apart the name and then do a select query where it's "select id from students where first_name='$something' and last_name='$something_else'";

What?
0
Comment
Question by:brucegust
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 38845685
For starters, stripslashes() is not the right function to use before echo sends the browser output.  You want htmlentities() to avoid sending evil JavaScript commands to the client browser.

Probably your query is looking for the student names in a table that also contains an AUTO_INCREMENT PRIMARY KEY column, right?  Why not SELECT all three columns in the query?

If you want to post the CREATE TABLE statement we can probably give you a query that will get all the fields you need in a single trip to the data base engine.
0
 

Author Comment

by:brucegust
ID: 38846652
Thanks, Ray. I was able to get it done using explode, but I'll take your advice on the htmlentities too.
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question