php - Child not displaying data from correct parent -
i'm relatively new php, , stuck on 1 issue. index.php file displays list of states, , displays states correctly. each of states has p_id field correspond alphabetized listing of states.
the database i'm using has table contains following fields in cat table: p_id (parent id), state (name of state), city, , id (child's id, resets every new state). query use populating states:
select distinct state, p_id cat order state asc list_cities.php next page displays after clicking on state. alabama first state alphabetically, parent (p_id)=1. when click on alabama (or other state), no cities displayed. listed in cat table.
this query use display cities:
select p_id, id, city, state cat p_id="'.$p_id.'" order p_id, id any appreciated! thanks!
imagine have state table this:
------------- id | state ------------- 1 | california 2 | new york 3 | arizona and city table like:
------------------------------ id | state_id | name ------------------------------ 1 | 1 | los angeles 2 | 1 | san diego 3 | 1 | san jose the correct query retrieve states is:
select id, state states order state asc; and correct query retrieve cities, based on state is:
select id, name, state_id cities state_id = ?; then obviously, use pdo class connect database since more secure whatever can write. check pdo manual more info. '?' parameter bind pdo don't let confuse you.
from i've understood have created 1 table specify both city , state name. seperate them, , create 2 tables did above.
Comments
Post a Comment