spencer9772 Posted December 22, 2014 Share Posted December 22, 2014 Hey guys so I am making an online App website. So I need to it to be so some apps will be added by default. Then users can search for apps and "install" apps but really just have them show up on the homepage. So how would the database design work like have a field that is updated to 1 if the user has it installed and 0 if its not. And then do like an if statement to pull all the fields with 1 where username='$username'. And when it pulls it should I add like a URL field to it to so when it pulls the app information there will be a link to the app url. Could somebody please help me with what I should do because I am really confused on what design and if statements I should use Quote Link to comment https://forums.phpfreaks.com/topic/293256-php-apps/ Share on other sites More sharing options...
Solution Frank_b Posted December 22, 2014 Solution Share Posted December 22, 2014 (edited) That sounds as a many-to-many relationship with three tables: table 1 : users table 2 : apps table 3: users_apps Table 3 is what we call a jointable which makes relations between records out of the users and the apps table. a little example would help i guess: users table : - user_id (primary key, autoincrement) - username - password - email - .... apps table: - app_id (primary key, autoincrement) - name - description - download_url - .... users_apps table: - user_id (foreign key, in phpMyAdmin als index called) - app_id (foreign key, in phpMyAdmin als index called) some example rows in users_apps: user_id app_id 1 1 1 2 3 1 this let us know that user with id 1 have downloaded two apps: 1 and 2 Also we see that user 3 have downloaded only one app: app nr 1. With a little query we can also count how much times every app is downloaded: app 1 has been downloaded twice and app two has been downloaded once. Edited December 22, 2014 by Frank_b Quote Link to comment https://forums.phpfreaks.com/topic/293256-php-apps/#findComment-1500412 Share on other sites More sharing options...
spencer9772 Posted December 22, 2014 Author Share Posted December 22, 2014 So hey how would I do it so like some apps are added by default? Quote Link to comment https://forums.phpfreaks.com/topic/293256-php-apps/#findComment-1500423 Share on other sites More sharing options...
Frank_b Posted December 22, 2014 Share Posted December 22, 2014 That is not be too dificult either. First of all your application needs to know what are standard apps and which one not. To do that you could simply add a column to the apps table with a name like for example 'default' or 'standard'. Give apps a 1 if they are standard and otherwise a zero. After that, when a user signed up and you store the user details into the database you can also immediately add records to the users_apps table. (that would be a while loop with INSERT queries) Quote Link to comment https://forums.phpfreaks.com/topic/293256-php-apps/#findComment-1500428 Share on other sites More sharing options...
Frank_b Posted December 22, 2014 Share Posted December 22, 2014 A lot of beginners will think something like 'wow that will be a long list in the join table'. Yes but computers are fast these days and its exactly where databases are made for. It is not a problem at all and besides of that it is the only way to keep track on which user has which apps! Quote Link to comment https://forums.phpfreaks.com/topic/293256-php-apps/#findComment-1500429 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.