• 0

How would I store this information?


Question

Hey all,

I recently started learning some PHP and MySQL and I need a guide for good database setups, I suppose.

What I want to do is add the ability to have users register on my site, and have them save links on my website. They could save thousands of links.

I could make a database with their usernames, passwords and salts, then I was thinking I could have another database with their usernames and possibly another area in the database that could save the links, but how would they be saved?

Link to comment
https://www.neowin.net/forum/topic/1139258-how-would-i-store-this-information/
Share on other sites

10 answers to this question

Recommended Posts

  • 0
  • 0

So each link is in the table. So it could be like (User1 - Link1) -> (User2 - Link 1) -> (User1 - Link 2) -> (User1 - Link 3) -> (UserX - Link Y)?

Then when a user loaded their link page, it would go through the table and list all the links have match with the user?

Thanks for the database tip! :D

  • 0

Yeah, so example data:

Login

--

1,articuno1au,password,[email protected]

2,thatguyandrew,lolcats,[email protected]

Links

--

1,1,http://www.hotmail.com

2,1,http://www.wocserver.org

3,2,http://www.shayconcepts.com

4,1,http://www.forums.wocserver.org

5,2,http://www.facebook.com

Then:


SELECT Link
FROM Links
WHERE UserID in (SELECT UserID
FROM Login
WHERE Username = "articuno1au")
[/CODE]

Would return:

Hotmail, wocserver, forums.wocserver

Putting your username in would return:

shayconcepts, facebook

In the links table, the information is collected by UserID not GUID (Which is there just to serve as a Primary Key :))

Sound good?

Just as a side note, for performance reasons, you are better off using JOIN to link the tables when querying. MySQL doesn't like embedded/subquery queries >.<

  • Like 1
  • 0

FYI stackoverflow is a good resource :)

When you start getting more comfortable you will start finding ways to make the tables optimal for each application use

Practice always helps!

actually looking at others applications/programs/scripts or however you wish to pass it on as helps tons!

http://en.tekstenuitleg.net/articles/software/database-design-tutorial/intro.html

http://www.deeptraining.com/litwin/dbdesign/FundamentalsOfRelationalDatabaseDesign.aspx

Those seem like decent articles

Good luck!

  • 0

FYI stackoverflow is a good resource :)

When you start getting more comfortable you will start finding ways to make the tables optimal for each application use

Practice always helps!

actually looking at others applications/programs/scripts or however you wish to pass it on as helps tons!

http://en.tekstenuit...rial/intro.html

http://www.deeptrain...baseDesign.aspx

Those seem like decent articles

Good luck!

Thanks!

  • 0

The bit that requires special attention is securing the scripts that are running.

Having logins and submitting new links equals web forms and the use of GET and POST so you'll be wanting to do a bit of work to make sure your DB queries and inserts are secured from iffy SQL injection or other dodgy user inputs. Don't just think mysqli_real_escape_string will do the job...it'll likely not even work unless you've covered the configuration of the host in advance.

Working for a web design/development company I've seen a few rather farcical examples of "content management systems" that so called developers (created by others outside our company) have written in PHP that miss or just ignore these risks.

I'm in the middle of writing my own (super simple) blog and even though it's literally bare-bones (has no comments system yet and probably wont) and a few pages to list the articles/archive it's something I have to pay attention to as well.

  • Like 2
  • 0

The bit that requires special attention is securing the scripts that are running.

Having logins and submitting new links equals web forms and the use of GET and POST so you'll be wanting to do a bit of work to make sure your DB queries and inserts are secured from iffy SQL injection or other dodgy user inputs. Don't just think mysqli_real_escape_string will do the job...it'll likely not even work unless you've covered the configuration of the host in advance.

Working for a web design/development company I've seen a few rather farcical examples of "content management systems" that so called developers (created by others outside our company) have written in PHP that miss or just ignore these risks.

I'm in the middle of writing my own (super simple) blog and even though it's literally bare-bones (has no comments system yet and probably wont) and a few pages to list the articles/archive it's something I have to pay attention to as well.

That's great advice, thanks!

  • 0

Teknikal you plan on open sourcing it?

well it's nothing fancy. literally 1 db table. just suits my own needs. i don't like using things like wordpress as they are too bloated with all sorts of features i don't need. with my own approach I can keep it minimal, fast and I can focus on the content and SEO for titles, descriptions etc. more of a learning exercise really. i find when you use other tools people tend to neglect the important stuff.

all i need is a list of recent articles on the index, a full archive of all my articles and a page that displays each individual article when you click on it and not much else.

i might get round to doing a basic commenting system but it might be easier just to paste in something like "disqus" and let it do it. still have to do a web form to allow me to make posts but I might not even bother with that as it's just me...I can just do it directly in phpmyadmin and achieve the same result. i don't imagine a very basic search function will be difficult but I'm not really sure how best to do that yet.

also have to figure out some URL rewriting as entry.php?id=1 isn't much use. i decided to include a "slug" column in my database so I might use "my-super-cool-blog-post-title" or something to that effect and use it in the URL rather than the ID.

when it's done I can explain how i made it and what it does I guess.

This topic is now closed to further replies.
  • Posts

    • Apple reportedly looks to blacklisted Chinese memory chips as RAM prices climb by Karthik Mudaliar Image via Apple Apple is reportedly trying to get a clearance from the Trump administration to buy memory from ChangXin Memory Technologies (CXMT) to get some relief from soaring DRAM prices. As per a report by the Financial Times, Apple approached the Commerce Department more than a month ago and also spoke to other officials and allies in Washington. For starters, CXMT is a company that's already been placed on the Pentagon's list of Chinese military companies. The Chinese company is the country's top DRAM maker. For Apple, the timing is certainly awkward but not surprising. Tim Cook had recently warned that Apple would have to raise prices because AI companies are buying up large amounts of memory for data centers, and just like that, Apple raised MacBook and iPad prices. Micron also recently revealed that customers have committed billions of dollars to secure memory supply years in advance, which shows us how aggressive securing infrastructure has become. This gives suppliers such as Samsung, SK Hynix, and Micron more leverage, while pushing hardware makers to look for alternatives. CXMT is one of those alternatives, but not the simplest one. Apple has spent many years trying to diversify parts of its supply chain away from China, especially for final assembly, while still depending heavily on Chinese manufacturing and suppliers. Even domestic brands from China are moving towards CXMT and YMTC instead of relying on Samsung, Micron, and SK Hynix. For Apple, though, it would invite more scrutiny than local Chinese companies. For now, this is more like a lobbying effort rather than a confirmed supply deal. There's no official statement from either of the parties. What is clearer, though, is the pressure behind such a request. AI demand has certainly made hardware a bottleneck, and companies are trying everything they can to bring things back to normal, even if that means making politically sensitive choices. Source: Financial Times
    • I did test it a month or so back, but ... the results I expect to be on the first page are not there.
    • Neowin is saying these are good prices? Thats crazy. As others have said they are just ######. Time for big tech to bring down the prices for real not this fake crap.
    • The iFlyTek AINote 2 is among the thinnest E-Ink tablets. It has an EMR stylus, a built-in fingerprint reader, and plenty of built-in AI features. You had me until "and plenty of built-in AI features." That and any company that still does the iProduct naming trope is an immediate pass. It suggests the company isn't very imaginative or creative and is trying to piggyback off another company's success. Extremely lame. Also kind of expensive. Better choices at lower prices out there.
    • These are not "great" prices... just "less awful". Apparently "Those who forget the past are doomed to pay higher prices and think they've won."
  • Recent Achievements

    • Week One Done
      flexorcist earned a badge
      Week One Done
    • One Month Later
      Woland13 earned a badge
      One Month Later
    • Week One Done
      Woland13 earned a badge
      Week One Done
    • One Year In
      bernmeister earned a badge
      One Year In
    • Week One Done
      Scoobystu earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      486
    2. 2
      +Edouard
      220
    3. 3
      PsYcHoKiLLa
      147
    4. 4
      Steven P.
      74
    5. 5
      FloatingFatMan
      70
  • Tell a friend

    Love Neowin? Tell a friend!