newrehmi Posted February 25, 2010 Share Posted February 25, 2010 let say I have 2 table, which is user and photo table user may have many photo, while a photo only have 1 user. so I made user_id (foreign key)column in my photo table.. lemme give an example about my photo table.. id | name | url | user_id | 1 | bus | bus.jpg | 1 | 2 | car | car.jpg | 1 | 3 | plane | plane.jpg | 1 | 4 | train | train.jpg | 2 | 5 | bicycle | bcycle.jpg | 2 | so, I now abit confusing about what query to run. My question is, how to echo 'all' the value on name and url, based only on user_id=1. May someone tell me, what query to run, and what function do I need to use? If using 'while' how? btw, I am making an image gallery... Quote Link to comment Share on other sites More sharing options...
Rocu Posted February 25, 2010 Share Posted February 25, 2010 Perhaps something like this? $query = mysql_query("SELECT * FROM photos WHERE user_id = '1'"); while($row = mysql_fetch_array($query)) { echo $row["id"] . ' - ' . $row["name"] . ' - ' . $row["url"] . '<br />'; } This should output: 1 - bus - bus.jpg 2 - car - car.jpg 3 - plane - plane.jpg Quote Link to comment Share on other sites More sharing options...
newrehmi Posted February 25, 2010 Author Share Posted February 25, 2010 wow, that helps!... btw, what do it mean, by putting a dot between the $row? 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.