Jump to content

CyberShot

Members
  • Content Count

    322
  • Joined

  • Last visited

Everything posted by CyberShot

  1. I want to create a database for my person use. I am the treasurer for an HOA. I collect money for 14 units monthly. I currently use a spreadsheet but I figured it would be a great learning experience to try creating a database. ( very little skill ). I want to be able to select a unit and see how much is owed, when the last payment was made and any other notes needed. I can't decide how I should make it. Should I just make a plain database with simple records like a spreadsheet or make it more complicated? by simple, I was thinking one table. ID, name, address ( a four digit number ) , paid ( bool ), amount_paid, date, notes I have toyed with the idea of making it more tables but I don't know if it is needed. The idea is that I want the ability to select a unit number ( address ) and see what is owed up to the current date. If I have a unit that hasn't paid in a year, I want to be able to see that and the months owed. if they pay half of the amount, I want to be able to do the math on that and see that. I am trying to figure out if a one table database will work just fine.
  2. is there a general rule as to when to set a variable? I was watching a tutorial today and the author made a small function that would accept a string. Why would you set the string in the function like that? Would it work if it was just $string? function e($string=""){ do something return $string; }
  3. Ok, I have remade my table to match what you have posted.I had to alter the tables in order to set up the foreign keys. Was that necessary? ALTER TABLE unit ENGINE=InnoDB; ALTER TABLE payment ENGINE=InnoDB; I was then able to set up the relationships. I set the payment_id a the primary_key and the unit_id as the foreign key in the payment table. The unit_id is the unit table should be the primary key set to auto_increment. Is this good?
  4. for the unit table. I set the unit_id as the primary key and auto increment and for the payment set the unit_id as primary key auto increment?
  5. I agree with you 100%. I have managed to create an html select that does display each unit from the database where the value of the select is the address table primary key. This is a home owners association and what I am trying to keep tack of is the HOA dues. Those dues pay the water, sewer, garbage, landscaping and electrical for the complex. There are 14 units. Each unit pays monthly. There is no good cheap software out there that does what I want so I was trying to make something myself but as you can tell, I don't know what I am doing. I made the database, inserted some records and have managed to display them in a table. The html form was at this point was just to get a working query that I could work off of and then make more correct with prepared statements at a later time. Once the basic structure was up and running. The update queries are not working. I can get it to tell me that the database has been updated but the new record doesn't actually show up. Maybe I should just scrap the project and go back to watching TV and playing games.
  6. I only need one record per month per unit. each unit could actually make multiple payments per month though. My plan is to output each month into a table and each month the data in that table would reset to zero to show the new payments for each unit for the current month. Then the database would hold all payments made over time. I would like to query the database to show units that have not paid, how much they owe and when the last payment was made and what months are missing. You said it's unusual to join the primary key of one table to another. I guess I don't understand because that is how I thought it was done. What is the right way to do it as that is the way I would like it to be.
  7. here are my two tables. you will see in the below in the amount table, there is one record that has a duesID of 5 which does correspond to the address table unitID of 5. This is the correct record to show for unit 4109. I am trying to get a query that will choose the unitID and put the proper record down below so that when I query the database, the correct record will show for the correct unit. Right now, I have a form with unit #, date, amount paid and notes. My thought was that I could put in the unit number and then have the query select the matching number from the unitID in the address table and then insert the record into the amount table with the matching duesID number so that when I want to select a single record, I could just choose the unit number which will match the unitID and that record will populate. mysql> select * from address; +--------+----------------+ | unitID | unit | +--------+----------------+ | 1 | 4101 | | 2 | 4103 | | 3 | 4105 | | 4 | 4107 | | 5 | 4109 | | 6 | 4111 | | 7 | 4113 | | 8 | 4115 | | 10 | 4119 | | 11 | 4121 | | 12 | 4123 | | 13 | 4125 | | 14 | 4127 | | 9 | 4117 | +--------+----------------+ mysql> select * from amount; +--------+------+------+------+---------------------+------------+---------------------+ | duesID | dues | late | paid | notes | date | autodate | +--------+------+------+------+---------------------+------------+---------------------+ | 5 | 210 | 0 | 1 | paid through paypal | 2018-12-04 | 2018-12-10 20:54:07 | +--------+------+------+------+---------------------+------------+---------------------+
  8. Barand. I am trying to get your query working but I am having trouble. It is close though but I am getting an error at the last line. Here is what my database looks like table address unit ( varchar(20) ) unitID ( int, primary key, auto increment ) table amount autodate (timestamp) dues (int(6) ) late (varchar(1) ) paid (varchar(1) ) notes ( varchar(500) ) duesID ( int, primary key, auto increment ) Right now, I am just trying to get a test query in so that I can get a "scaffold" to work off of. so I thought the way this would work is that the query would check the unitID in the address table to see if it matches the "unit" number passed through the post variable from the html form. Benanamen said not to create useless variables, so I took them out and just used the post variables as suggested. So my html form has a text box for unit #, date, amount paid and notes Right now, I am just trying to get the unit # to match the primary key in the address table and then put the amount, and notes into the amount table. After I get that working, I will work off of that to get the rest of the fields to populate. I have 14 entries in the address table and 1 in the amount table. As the query is now, it's says I have an error in my sql syntax "WHERE ad.unitID = '10' The ten should match the primary key in the address table and put the record into the amount table to match. Here is what I have been trying with my query $sql = "UPDATE amount am INNER JOIN address ad ON ad.unitID = '{$unit}' SET dues = {$amount}, notes = '{$notes}', WHERE ad.unitID = {$unit}";
  9. all of this is done on localhost. I would assume it's not as dangerous? I have updated the code to use the if($_SERVER['REQUEST_METHOD'] == 'POST') How do you perform an update that doesn't have variables? are you saying that they are ok to pass if I use prepared statements but not just in an mysqli->query? I do remember reading that PHP_SELF was vulnerable attacks. What should I put there then? I don't want to separate my update function out of the db class. What is the best method for this? why can't you output internal system errors? how do I get my errors if I don't output them?
  10. I created an htlm form using $_SERVER['PHP_SELF'] to update my database and I am calling the form like so <?php if( $_POST['update']){ $unit = $_POST['unit']; $date = $_POST['date']; $amount = $_POST['amount']; $notes = $_POST['notes']; $york->update($unit, $date, $amount, $notes); } ?> in my database class, I have created an update function public function update($unit, $date, $amount, $notes){ $conn = $this->link; $sql = "UPDATE amount SET dues = ' . $amount . ', notes = '. $notes .' WHERE duesID = '. $unit .'"; if (mysqli_query($conn, $sql)) { echo "Record updated successfully"; } else { echo "Error updating record: " . mysqli_error($conn); } } $this->link connects to the database in my __construct and there are no errors as far as that goes. When I hit the update button in the html form, the page reloads and there is a message saying "Record updated successfully" but when I check the database, there isn't any new record. Looking at it again, I have realized that the query is looking for duesID to match the $unit number which in this case should be 10 but the amount table doesn't have a record for that. so what I need is a query that will select the address table and amount table then update the amount table where the address table unitID = $unit which is passed through my html form. How do I do that? The Address table does have a 14 entries in it with just to columns. Unit and unitID. Is this where a join comes into play?
  11. this is true that the error does give you the line number but it isn't true that the line it points out is always the problem. It could be 2 or 3 lines above the actual line pointed out. I have seen this before. That said, I do not have any formal programming schooling. I am trying to teach myself which is not as easy as it sounds. There are lots of tutorials out there but they are notorious for leaving out information. They do things but do not tell you why they did them. I just finally came to understand the use of "$this->" as of yesterday.
  12. I see in my post that the braces are messed up. I just didn't copy the code correctly. They are not messed up in the class
  13. I am trying to create a class and I ran into a problem. The connect function is returning a fatal error on the line below and I can't figure out the issue. $result = $this->conn->query("SELECT unit FROM address"); class database { private $server = "localhost"; private $db_user = "my user"; private $db_pass = "my pass"; private $db_name = "my database"; private $conn; private $result = array(); function connect(){ // Create connection $this->conn = new mysqli($this->server, $this->db_user, $this->db_pass, $this->db_name); if ($this->conn->connect_error) { echo "Not connected, error: " . $mysqli_connection->connect_error; } else { //echo "Connected."; return $this->conn; } public function displayHeader(){ $result = $this->conn->query("SELECT unit FROM address"); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo '<li>' . $row["unit"] . '</li>'; } } else { echo "0 results"; } $conn->close(); } } }
  14. when I first get the information out of WordPress, it looks like this ( this is just a short bit of it ) $theID = get_post_meta(get_the_ID()); $string = $theID['panels_data']; var_dump($string); //gives me the below line string(748) "a:3:{s:7:"widgets";a:1:{i:0;a:3:{s:5:"title";s:4:"home"; When I pass the string to unserialize function, I get an error $string = unserialize($string); echo $string; "warning" unserialize() expects parameter 1 to be string, array given in
  15. That helps a little but my main problem still exists. I get my data and when I dump the variable, it says it's a string that looks like this a:3:{i:1;s:6:"elem 1";i:2;s:6:"elem 2";i:3;s:7:" elem 3" yet when I pass that variable into the unserialize function, I get an error. I thought this is what unserialize was for. it says unserialize() expects parameter 1 to be string, array given in This is why I am confused.
  16. I have what I think is a serialized information in my WordPress site.. Here is a partial chunk a:3:{s:7:"widgets";a:1:{i:0;a:3:{s:5:"title";s:4 I thought that if I use unserialize, it would put it into an array or something. I thought unserialize takes a string which according to the data type looks like what I would be passing after going through my foreach loop but when I try to unserialize it, it tells me i am trying to convert an array to a string. Not sure what I am doing wrong here. foreach ( $string as $option) { echo unserialize($option) ; }
  17. I have this array and I am trying to get the image value print_r($image); Array ( [0] => Array ( [image] => 32 [image_fallback] => ) [1] => Array ( [image] => 31 [image_fallback] => ) ) The only way I have been able to get it to work is by doing this foreach($image as $key){ foreach($key as $value){ $imageID = wp_get_attachment_image($value,'full'); // gets the attachment image from the image ID.. 31, 32 from the above array echo $imageID; // prints out the image tag with the url to the image } } The above code does give me the desired result. What I want to know is if there is a sexier way to getting it done? Is this considered propper?
  18. should this line $result1 = mysql_query($query1); be this $result1 = mysqli_query($query1); ?
  19. Looks like the problem was that I missed adding the class index to one of the options. The error is gone
  20. I am working in WordPress building a widget for siteorigin page builder. The widget is working just fine but I am getting an undefined index error and I don' t know why. I have a file that returns and array. That is all that it does. It looks like this but has a lot more indexes. 'facebook' => array( 'label' => __( 'Facebook', 'mosty' ), 'base_url' => 'https://www.facebook.com/', 'class' => 'fa fa-facebook', ), 'twitter' => array( 'label' => __( 'Twitter', 'mosty' ), 'base_url' => 'https://twitter.com/', 'class' => '', ), I have added the class index to the array and I am using the facebook one as my test. I need to get the result of the "class" index and send it to the front end of the site. I have that working. It does display on the front end. In the front end file, I have a bit of code to error check to see if I can get the value I brought the array file into the back end like this if( empty( $this->networks ) ) { $this->networks = include plugin_dir_path( __FILE__ ) . 'data/networks.php'; } ?php foreach ($network_names as $key => $value){ echo '<ul><li>The key is '. $key . ' The value is ' . $value . '</li></ul>'; } ?> Here is the output of my test loop and at this point, this is all I would expect and the first entry is correct The key is facebook The value is fa fa-facebook The key is twitter The value is The key is google-plus The value is The key is linkedin The value is The key is tumblr The value is The key is vk The value is The key is flickr The value is The key is delicious The value is The key is dribbble The value is The key is skype The value is The key is youtube The value is The key is github The value is The key is forrst The value is The key is digg The value is The key is soundcloud The value is On the front end of the site, I am getting this error Notice: Undefined index: class in /path to widget/team/team.php on line 111 Here is my line 111 109 $network_names = array(); 110 foreach ( $this->networks as $key => $value ) { 111 $network_names[ $key ] = $value['class']; 112 } I am sending the array to the front end of the site on line 121 of team.php I have attached my team.php class to the post for you to view. Again, the widget does work and does display the data but gives me that undefined index for "class" index of my array. How can I solve this problem? team.php
  21. I re-wrote it with the implode, explode. It's shorter and cleaner. It also makes the address at least look like something WordPress would do. I had hoped to find a way to hide the variable all together but I can accept this method.
  22. My only thing with this is that I don't see this kind of thing often. I would think there would be a better way. I think your idea has promise and I might actually look into that. I did try the http_build_query but I don't think it ended up working. This is the first time I have tried passing variables through a link
  23. I am passing an array of wordpress page IDs through an anchor link but it looks rather ugly. I am serializing my array like this $var = htmlspecialchars(serialize($pages), ENT_QUOTES); which gives me this string(45) "a:4:{i:0;i:944;i:1;i:17;i:2;i:19;i:3;i:1310;}" passing it through an anchor tag like so $link = tbpb_get_archives_link(); // returns the permalink of a WordPress page <a href="<?php echo $link . '?var='. $var ?>" class="work-all"><span><i class="fa fa-times"></i> All works</span></a> now my anchor tag looks like this in the navigation bar http://mysite.com/all-projects/?var=a:4:{i:0;i:944;i:1;i:17;i:2;i:19;i:3;i:1310;} is there a way to clean that up and make it look prettier? or another method of passing the variables from one page to another?
  24. That is interesting. Thank you. I will have to study this
×
×
  • 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.