Hello,

I am very new to php/mysql, but I've learned a decent amount about it as of late
.
I'm trying to write a query for a dynamic list. The list is supposed show all user level 1's from a given state (i.e. CT, MA, ME).

The state it shows depends on a login_id session variable I've been using for every other page.

This is what I've come up with so far...am I on the right track? How can I build on this to get it to pull the information I want?

SELECT odb_members.id, odb_members.user_lvl, odb_members.name_first, odb_members.name_middle, odb_members.name_last, odb_members.addr_state
FROM odb_members
WHERE odb_members.user_lvl = 1
AND odb_members.addr_state=sessvar1

This query only pulls the correct information if I have addr_state equal to 'CT' or whatever other state you can think of.

The complexity of this kind of baffles me, because if the addr_state=sessvar1, then I have to put the same session variable somewhere else to tell it what the sessvar1 refers to.

On other pages, it goes: odb_members.id = sessvar1

I could really use some help on this.
I really do appreciate the time and effort, as I'm very, very interested in becoming proficient in this area.
Thanks so much.

Don't know if this helps but this would be the correct way to do it in php:

$query = "SELECT odb_members.id, odb_members.user_lvl, odb_members.name_first, odb_members.name_middle, odb_members.name_last, odb_members.addr_state
FROM odb_members
WHERE odb_members.user_lvl = 1
AND odb_members.addr_state='" . mysql_real_escape_string($_SESSION['sessvar1'], $dbconn) . "'";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.