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... Link to comment https://forums.phpfreaks.com/topic/193372-php-and-mysql-query-question/ 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 Link to comment https://forums.phpfreaks.com/topic/193372-php-and-mysql-query-question/#findComment-1018127 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? Link to comment https://forums.phpfreaks.com/topic/193372-php-and-mysql-query-question/#findComment-1018275 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.