Jump to content

[php and mysql] query question.


newrehmi

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.