Jump to content

webdeveloper123

Members
  • Posts

    437
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by webdeveloper123

  1. Would it be fine to just remove product_type?
  2. actually that's a good point. If I have a new product, I can just add it to the product table. Now that I am populating the db, I have realised that product_type.type_descrip serves the same purpose as product.name and I don't think I need product.p_description because it's not like a e-shop where you read the product description and decide on a purchase, it's just an internal system to generate an invoice.
  3. Hey @gizmola, thanks for the input. I took on board most of your advice and implemented it. Now I have decided not to have a member registration system, thus changing the data model. Instead I have a login form (user,pass is hard coded) & that will act as a fictional member of staff logging into the fictional company system and generating invoices for the clients. I have an updated version of the data model and was seeking advice if it is good to go. Thanks
  4. ahh ok. I think decimal is fine, but thanks for your advice.
  5. Thanks Barand. @maxxd Do you mean like this? Shall I go for this model?
  6. Ah ok. So like this? Could this be the final model?
  7. Hey Barand, thanks. Do you think I could use the following as a final data model?
  8. Thanks for the tips Barand. I had an inkling about the member table needing a memberID but I wasn't sure. No. Again when I was creating the model I had a suspicion that is what I inadvertently did. @maxxd Yes on the contact email and being shipped to separate locations that is out of scope for this mini project. But thanks for your input. Would order details be a new entity or replace order?
  9. Hi, I've created a database design and I would like some input from other members on it. I don't think I've done it correctly as pType is stored twice, once in Products & again in productType. I'm also not sure if I have the multiplicity correct. This ERD is intentionally simple. I did not want to have different model numbers, colours etc. Having said that, any feedback is welcome. I just wanted to keep it simple as the ultimate goal was to generate an invoice , within a function , in PHP. The invoice is similar to the invoices generated by ebay. Any feedback is welcome. Thanks
  10. So your $new array is pretty nifty, you can re-use that, adjust it, for many different array function on 2d arrays
  11. ahhh that's how you do it. I was using array_replace_recursive for a few hours yesterday but did not get my expected output. So you created a new array with the data you want to change then pass that to the function. I was trying this: $array2 = array( 4 => ["fname"] => "Steve"); $array3 = array( 7 => ["age"] => "72"); But it had errors. Thanks for the help Barand!
  12. Hey thanks Barand, I know how to do it that way and have done it that way but was wondering if it can be done using array_replace? @ginerjmYes I was going to move onto mysqli_multi_query and parameterized queries after doing this array stuff
  13. Oh yeah. Basically I want to edit values in the array. So for example If I have the array in my first post I would like to Edit index 1 =>age to 33 5 => fname = Sandra 3 => lname = Cunningham @ginerjm No I don't have any of this data in a db. I wanted to brush up on my array skills. It's just that if they basic 1 dimensional arrays then I'd be fine but 2d arrays are a bit trickier.
  14. Hi, I have these 2 arrays which are merged: $table = array ( 0 => array ( 'fname' => 'Peter', 'lname' => 'Smith', 'age' => '37' ), 1 => array ( 'fname' => 'Paul', 'lname' => 'Hartley', 'age' => '48' ), 2 => array ( 'fname' => 'Mary', 'lname' => 'Baker', 'age' => '42' ), 3 => array ( 'fname' => 'Jane', 'lname' => 'Doe', 'age' => '51' ) ); $newdata = array ( 4 => array ( 'fname' => 'Jon', 'lname' => 'Atkins', 'age' => '27' ), 5 => array ( 'fname' => 'Phil', 'lname' => 'Jones', 'age' => '14' ), 6 => array ( 'fname' => 'Frank', 'lname' => 'Lampard', 'age' => '48' ), 7 => array ( 'fname' => 'Toney', 'lname' => 'Brentford', 'age' => '25' ) ); $table = array_merge($table, $newdata); I am trying to use array_replace to edit values in the array. I know I can do it like this: $table[2]['age'] = 67; But I wanted to use array_replace. So I did this: $replacements = array(3 => "Steve", 7 => "Adam"); $newArray = array_replace($table, $replacements); print_r($newArray); But all I did was enter Steve at position 3 and Adam at position 7. Here is the output from print_r: Array ( [0] => Array ( [fname] => Chris [lname] => Smith [age] => 37 ) [1] => Array ( [fname] => Paul [lname] => Hartley [age] => 48 ) [2] => Array ( [fname] => Mary [lname] => Baker [age] => 67 ) [3] => Steve [4] => Array ( [fname] => Jon [lname] => Atkins [age] => 27 ) [5] => Array ( [fname] => Phil [lname] => Jones [age] => 14 ) [6] => Array ( [fname] => Tank [lname] => Lampard [age] => 48 ) [7] => Adam ) I also tried: $array2 = array("fname" => "Steve"); $array3 = array("age" => "72"); $replacedArray = array_replace($table, $array2,$array3); print_r($replacedArray); But all that did was add [fname] Steve and [age] 72 at the end of the array. Here is the print_r output Array ( [0] => Array ( [fname] => Chris [lname] => Smith [age] => 37 ) [1] => Array ( [fname] => Paul [lname] => Hartley [age] => 48 ) [2] => Array ( [fname] => Mary [lname] => Baker [age] => 67 ) [3] => Array ( [fname] => Jane [lname] => Doe [age] => 51 ) [4] => Array ( [fname] => Jon [lname] => Atkins [age] => 27 ) [5] => Array ( [fname] => Phil [lname] => Jones [age] => 14 ) [6] => Array ( [fname] => Tank [lname] => Lampard [age] => 48 ) [7] => Array ( [fname] => Toney [lname] => Parker [age] => 25 ) [fname] => Steve [age] => 72 ) I even wrote a little foreach loop which wasn't very good ( I know it's not very logical) but I thought I'd give it a try as I'd been trying all day: $table[0]['fname'] = "Chris"; $table[2]['age'] = 67; foreach ($table as $key => $value){ $age[] = $table[2]['age']; $fname[] = $table[0]['fname']; $age[] = 58; $fname[] = "Brandon"; } $replacedArray = array_replace($table, $age,$fname); print_r($replacedArray); This is the output from print_r($replacedArray); Array ( [0] => Chris [1] => Brandon [2] => Chris [3] => Brandon [4] => Chris [5] => Brandon [6] => Chris [7] => Brandon ) Can anyone help please?
  15. sorry I didn't understand your code...is it missing function before fn? I tried it and then I tried: print_r(fn($table, $newdata)); But I get error: Parse error: syntax error, unexpected ')', expecting => (T_DOUBLE_ARROW) in
  16. Hi, I have the following arrays: $table = array ( 0 => array ( 'fname' => 'Peter', 'lname' => 'Smith', 'age' => '37' ), 1 => array ( 'fname' => 'Paul', 'lname' => 'Hartley', 'age' => '48' ), 2 => array ( 'fname' => 'Mary', 'lname' => 'Baker', 'age' => '42' ), 3 => array ( 'fname' => 'Jane', 'lname' => 'Doe', 'age' => '51' ) ); $newdata = array ( 4 => array ( 'fname' => 'Paul', 'lname' => 'Hartley', 'age' => '48' ), 5 => array ( 'fname' => 'Mary', 'lname' => 'Baker', 'age' => '42' ), 6 => array ( 'fname' => 'Jane', 'lname' => 'Doe', 'age' => '51' ), 7 => array ( 'fname' => 'Toney', 'lname' => 'Brentford', 'age' => '25' ) ); I am trying to use array_diff on the 2 arrays and based on my understanding only Peter Smith 37 should be returned. I am using this code: $result = array_diff($table, $newdata); print_r($result); But I am getting same errors: (8 times) Array to string conversion in Array ( ) Note the Array ( ) only shows once in the error. On php.net it says array_diff is used in 1 dimensional arrays but you can: Of course you can check deeper dimensions by using: array_diff($array1[0], $array2[0]); So I did: $result = array_diff($table[0], $newdata[0]); From my understanding the number in the square bracket refers to the key in the array but I get this error: Notice: Undefined offset: 0 in Warning: array_diff(): Expected parameter 2 to be an array, null given I also used: $result = array_diff($table[fname], $newdata[fname]); But I get a whole host of errors So I noticed that the examples in array_diff were all using the same key for multiple values, So Instead I tried array_diff_key: $result = array_diff_key($table, $newdata); print_r($result); And I do get output, but not the expected output. This is the print_r($result) output Array ( [0] => Array ( [fname] => Peter [lname] => Smith [age] => 37 ) [1] => Array ( [fname] => Paul [lname] => Hartley [age] => 48 ) [2] => Array ( [fname] => Mary [lname] => Baker [age] => 42 ) [3] => Array ( [fname] => Jane [lname] => Doe [age] => 51 ) ) but surely only Peter Smith 37 Should be the only output. Can anyone see where I'm going wrong? Many thanks
  17. thanks Barand and andrejuniordesouza!
  18. btw, I just used array_merge on the for loop script and it works!
  19. So it must have done it first time when I inserted one new element into the array, but because I Had more than one element I had to use array_merge?
  20. oh no!! I was thinking maybe it should be array_merge a few hours ago but thought Nah it can't be! anyway, thanks for the code barand!
×
×
  • 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.