I'm new to programming and trying to make my first web app. I'm building a site where users can login, see a list of links, and save/bookmark links from this list to their account. Eventually, I'd also like to be able to add functionality where users can create their own links.
So far, I'm planning on storing the information in 3 tables like these:
Users table user_id | username | password
Links table link_id | link_name | link_URL
Bookmarks table bookmark_id | user_id | link_id
I figured I would run a query to get a list of all the link_ids from the bookmarks table that belong to a certain user_id, like so:
$connection = mysql_connect('localhost', 'root', 'password') or die(mysql_error());
mysql_select_db("array-test",$connection) or die(mysql_error());
$query_link_id = "
SELECT link_id FROM bookmarks WHERE user_id =2
";
$query_result = mysql_query($query_link_id,$connection);
$link_id_array = mysql_fetch_array($query_result, MYSQL_BOTH);
If I echo out the array, it only has 1 value, the first row from the column. If I run the same query directly in phpadmin, I see the column with multiple values. I'm not sure what I'm doing wrong here.
Is storing the values in an array the correct way to do this? I have to somehow get the link_ids into an array, turn them each into variables, then run another query to get the rest of the link information - which I really have no idea how to do. I'm feeling pretty stuck on this and I've been searching for a solution for a few days. I appreciate any help and insight. Thanks!