Jump to content

neomicron

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

neomicron's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have been boggling my mind with this, and I have found a couple of solutions, but they seem a bit overkill and slow - so I am hoping someone here could help out. I am trying to build a MySQL database to coincide with PHP class structures (and don't suggest I just not do this - because I am... too bad :-P ) Take, for instance, a situation where I have three tables... I'll call them table_a, table_b, and table_c. I want it to be set up that table_c inherits (like a child object) information from table_b, which does the same from table_a. Theoretically this is how it would work. Here is the table structure. Table A has 2 fields. "id" and "name" Table B has 4 fields "id" "name" "parent" and "comment" Table C has 4 fields "id" "name" "parent" and "value" Now, if I set it this way: A.id = 1; A.name = "A"; B.id = 1; B.name = "B"; B.parent = "A"; B.comment = "Our comment"; C.id = 1; C.name = "C"; C.parent = "B"; C.value = "Data stuff"; Now, when I instantiate C (ie I pull data from C) I want to have it first pull data from A, then from B, then from C. When it pulls the information from B, and there is overlap (B.name and A.name for instance) B should win out and I would get a response back with B.name. Next it would pull C and do that same. If there is not overlap, or there is a blank/non-existent field, it would not overwrite. So, if I made C, I SHOULD have the following: id = 1 name = "C" parent = "B" comment = "Our comment" value = "Data stuff" Now, I have done this a few ways. For instance I could do a join twice, and have PHP dig through a mysql_fetch_array result and find the last instance of each variable. The other option I had was to use SELECT CASE repeatedly for each field of the table, and have it do the logic.. but if I say made children of children of children (multiple inheritance) those case statements would get to be pages long. There HAS to be a better way that I am just not thinking of... any help?
  2. [!--quoteo(post=327816:date=Dec 15 2005, 08:27 PM:name=uswebproFreak)--][div class=\'quotetop\']QUOTE(uswebproFreak @ Dec 15 2005, 08:27 PM) 327816[/snapback][/div][div class=\'quotemain\'][!--quotec--] Hey I found out how to hash text when inserting: INSERT INTO tablename (fieldname, other_fieldname) VALUES (password('secret_stuff'), 'other_data') 'secret_stuff' is changed to: 2d7510136b7a8a7e how do I un-hash it, so I can use the info? Often times a hash is stored for passwords and other information to be verified againt the user input. In your case, rather than un-hasing the password field, try something like this: $pw = $_POST['password']; //get the password the user entered into our site $user = $_POST['username']; $sql = "SELECT * FROM `accounts` WHERE `username` = '".$user."' AND `password` = password(".$pw.");"; Execute this query and it will return information if the usernames match. Now, this is a pretty bad example (sql injection among other things) but it is just to show a point. Rather than trying to un-hash your database values to compare to user input, just hash the user input and see if they match. i.e. $userinput = "test"; md5("test") = md5($userinput); will return as true
×
×
  • 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.