How to create a page for database entries in a html page - html

At the moment I have this database:
|---------------------|------------------|
| Project | Task |
|---------------------|------------------|
| id | id |
|---------------------|------------------|
| project_name | task_name |
|---------------------|------------------|
| project_id(FK) |
|------------------|
The supplies table, has a list for (name of the item or task) (id) and the project it is assigned to via a foreign key.
I have a simple post HTML form that lets users fill it out, and that in turn updates the database
Now I'm looking to add a sort of "output" that lets me create hyperlinks (or small pages) to each project, so that users can have the option to delete the project/add new tasks into it and so on
The only part I'm struggling on is figuring out how to create a seperate type page, I have tried using this
while($row = mysqli_fetch_assos($result)) {
echo "<li>" . "<a href=clientportal.php?project_id={$row['id']}'>
{$row['name']}</a>" . "</li>";
}
But this creates a HTTP 500 error, which I assume is because I used post and not get in my form.
Is there another way to do what I am looking for? or should I go back to my form and change it to a get method
Ideally I'm looking for a simple list of current projects, with hyperlinks, that take me to a page where I can add some php/sql code to output a few simple SQL query options as mentioned, such as deleting the project, adding a new task etc.
Thank you!

Related

Complex Mail Merge (CSV to Word, CSV to PDF, or Other)

QUESTION:
How do you write an ifStatement for Word or for PDF to calculate multiple rows per matching result?
USEAGE:
What I am trying to do seems fairly straight forward and was very easy when I was able to use MS Access 15 years ago, but with Access being not a possibility anymore, I am hoping somebody has a reasonable solution.
The WHAT:
I am trying to generate Statements/Invoices from a CSV (or spreadsheet of any format) into a nice report layout. Let's say the columns look like this:
First Name | Last Name | Account | Address | Item | Description | Item Total
Jane | Smith | 123 | 111 Main St | Ice Cream | it's really cold | $100.00
This is super easy and I can do in Word within 10 minutes and make it "pretty".
BUT what if there are multiple Items per invoice?
So maybe the CSV looks like:
First Name | Last Name | Account | Address | Item | Description | Item Total
Jane | Smith | 123 | 111 Main St | Ice Cream | it's really cold | $100.00
Jane | Smith | 123 | 111 Main St | Hot Dogs | all beef, all the time | $200.00
I still want there to only be 1 invoice per person but not sure how to do an if statement in Word that would say "If there are multiple items per person, put them on a new row, then total them all together"
I would be glad to have the CSV go into a PDF fillable form if I could get the multiple rows to work - I just cannot figure that portion out.
Other options: I looked at OpenOffice "Base" but couldn't get a nice form for a very custom Report. I researched briefly on how to do something like this on AWS, but without any luck. I don't think Microsoft has anything like Access anymore
You can use Word's Catalogue/Directory Mailmerge facility for this (the terminology depends on the Word version). To see how to do so with any mailmerge data source supported by Word, check out my Microsoft Word Catalogue/Directory Mailmerge Tutorial at:
http://www.msofficeforums.com/mail-merge/38721-microsoft-word-catalogue-directory-mailmerge-tutorial.html
or:
http://www.gmayor.com/Zips/Catalogue%20Mailmerge.zip
The tutorial covers everything from list creation to the insertion & calculation of values in multi-record tables in letters. Do read the tutorial before trying to use the mailmerge document included with it.
Depending on what you're trying to achieve, the field coding for this can be complex. However, since the tutorial document includes working field codes for all of its examples, most of the hard work has already been done for you - you should be able to do little more than copy/paste the relevant field codes into your own mailmerge main document, substitute/insert your own field names and adjust the formatting to get the results you desire. For some worked examples, see the attachments to the posts at:
http://www.msofficeforums.com/mail-merge/9180-mail-merge-duplicate-names-but-different-dollar.html#post23345
http://www.msofficeforums.com/mail-merge/11436-access-word-creating-list-multiple-records.html#post30327
Another option would be to use a DATABASE field in a normal ‘letter’ mailmerge main document and a macro to drive the process. An outline of this approach can be found at: http://answers.microsoft.com/en-us/office/forum/office_2010-word/many-to-one-email-merge-using-tables/8bce1798-fbe8-41f9-a121-1996c14dca5d
Conversely, if you're using a relational database or, Excel workbook with a separate table with just a single instance of each of the grouping criteria, a DATABASE field in a normal ‘letter’ mailmerge main document could be used without the need for a macro. An outline of this approach can be found at:
https://answers.microsoft.com/en-us/msoffice/forum/msoffice_word-mso_winother-mso_2010/mail-merge-to-a-word-table-on-a-single-page/4edb4654-27e0-47d2-bd5f-8642e46fa103
For a working example, see:
http://www.msofficeforums.com/mail-merge/37844-mail-merge-using-one-excel-file-multiple.html
The problem with the DATABASE field, though, is that it won't provide the totals you're after. Nevertheless, if you're going down the macro route, it wouldn't take too much more code to append a totals row to the resulting table.
Alternatively, you may want to try one of the Many-to-One Mail Merge add-ins, from:
Graham Mayor at http://www.gmayor.com/ManyToOne.htm; or
Doug Robbins at https://onedrive.live.com/?cid=5AEDCB43615E886B&id=5AEDCB43615E886B!566
PS: While I'm cognisant of StackOverflow's preference for the substance of answers to be posted here rather than linked to, the complexity in this case is far too great to deal with that way, besides which, one can't post the actual field codes or a document containing them here.

MySQL table structure suggestions?

Hey i'm currently working on a database project and simply can't think of a good way to save my data. The data being saved changes depending on what is being saved.
My current not-so-good table is:
User-ID | XLoc | YLoc | ZLoc | Data-ID | Data (String)
The data column is currently being saved as a string (serialized depending on object being saved) then unserialized. I understand serialization is a dumb idea when it comes to a proper database, but i haven't a clue on how else i could've done this.
I was thinking about assigning "sub" tables depending on the Data-ID then joining all the tables together on a search but i feel that wont be very efficient.
So my idea would play out like:
User-ID | XLoc | YLoc | ZLoc | Data-ID | Data-Index
Data-Index | SomeObjectRelatingData | SomeObjectRelatingData
Once again i just don't know how i'd put this all together so any help at all would be EXTREMELY helpful and i'm sorry if i was vague.
Example Data:
Particle-Name(string) | Material (int)
Time(long) | MeshType (int)
This data is currently serialized like so: Time:MeshType in string format. Once the data is retrieved from the database it's deserialized then changed back into it's formal type;
All the data needs to be accessed easily and they all share the User-ID, XLoc, YLoc, ZLoc.

rails 4 should i use call back filter or concerns for this

I want to store url's but extract the base url and store it in different table of its own.
url: example.com/this-is-worth-saving
base url: example.com
URL table:
+----+-----+-------------+
| id | url | base_url_id |
+----+-----+-------------+
Base_url table:
+----+----------+
| id | base_url |
+----+----------+
Should I use the before_create callback in rails to check to see if the base_url already exist in the base_url table and
if it does then grab the id and place it in the url's tables base_url_id
else create the new record the grab the id.
OR
Is there a better solution or schema design perhaps.
I've heard many arguments against the use of callback filters in rails ( 4 ).
Basically I want the base_url_id.
Callbacks are a giant debate in the Rails world. I like them, but I also use them only when absolutely necessary. In this case, I don't think you need callbacks.
I'd recommend using find_or_create_by! on your "base_url" table... Assuming your table is called BaseUrl, you could do:
#base_url = BaseUrl.find_or_create_by!(:base_url => params[:base_url])
Again, this assumes the name of your table is BaseUrl and you're using incoming params which contain a key of base_url. You'd want to modify the above code to fit your needs, but I think find_or_create_by! is what you want, as this will either:
a. Return an existing record with that base_url, or
b. Create a new record with that base_url.

Hard-coding URLs vs Nested Set vs Combo in Content System

I've been putting together a database to handle content produced for a site, however, thinking about the long-term, I'm unsure if I have the best system.
At present I'm using the routing method of passing everything via index.php which .htaccess routes as follows index.php?route=example/url (user sees http://www.domain.com/example/url)
At present the database is setup like below:
uid | title | content | category
--------------------------------------------------
/ | Home | aaa | 1
/example | Example | bbb | 2
/example/url | Example: URL | ccc | 2
Though I am not sure if this is the best approach, especially if I wanted to rename example to something - I'd have to rename each URL...
So I've also thought about the Nested Set method (such as http://www.phpclasses.org/package/2547-PHP-Manipulate-database-records-in-hierarchical-trees.html) though this would just show lots of different numbers in the database where I could access everything by it's node. Example below;
node | left | right | name
--------------------------
1 | 1 | 6 | Home
2 | 2 | 5 | Example
3 | 3 | 4 | URL
Then I could use the node as the uid? But I'm unsure how I could translate http://www.domain.com/example/url to the uid equalling 3...
I already do have a category column in my database at the moment, to categorise the content, though I could potentially alter this.
I'm basically looking for suggestions about how to proceed, because as the site gets more content it will be harder to change the setup - so I want to ideally get this right from day one.
Which of the two is better for scalability?
If the second, how to translate the URL to the node?
Could I somehow combine both so that the original database stores the uid as the node number, then do a join of some sort to make the uid be a url (as in 1) - then ]
^ I think I'd prefer this (the third), but unsure how to do in MySQL exactly, with some other benefits:
I could replace my category system with the parent node - which may be better
I could also then in theory store the node ID within a stats system, rather than a URL
If anyone can give some help/suggestions - I'd be grateful!
Well, if you use index.php?route=example/url, you could always do something like this:
$args = explode( '/', $_GET['route'] );
$args = filter_var_array( $_GET['route'], FILTER_SANITIZE_STRING );
Then your values of $args would be:
0 -> example
1 -> url
etc. You could then use these values to determine what template to load, and what content to grab from the database, or whatever else you're doing already.
HTH.
The nested set model probably is a good choice here. That'd result in a table layout like (id,left,right are the fields required by the nested set model, the others contain the respective content):
| id | left | right | uid | title | content | category |
More details on how to perform a particular query can be found here.
However I would not perform the look up on the database but a simple array cache:
new array('/' => array('content' => 'aaa', 'category' => 'bbbb'),
'/example/' => array(),
.....
);
This cache can be build up very easy (though expensive) and queried very easy.
On a side note: i suspect you're trying to model page content here. Maybe you should refactor you database structure then as this table would have two responsibilities (url->content mapping and content).

CakePHP Form Helper Database Interaction

Currently I am developing a CakePHP that will list various businesses.
In the database, there is a table for businesses that lists them like so:
id | name | address | city | state | state_id | zip | url
The state column are abbreviations of states (for listing purposes) CA, AK, FL, etc and the state_id matches up with the ids in the states table:
id | name | state_abbr
I have an admin_add.ctp template with form helpers for inserting new businesses.
For entering a state for a business I am going to have a pull down that lists all the states. However, how do I make the database insert so it will know how to add the state abbreviation and state id when I submit the form to add the business?
Save only state_id in your businesses table, you can always recover the state_abbr whenever you need it from the states table. (So delete the state field from businesses).
Evenctually, to avoid join each time, you can always read the states table once and have a mapping state_id=>array("name"=>something,"state_abbr"=>xy) to retrieve that information faster if you need it a lot of times in the same session
I figured it out.
In my Business controller I have var $uses = array('business', 'state') and then in the add function I can pass all the states data to the view of the Add Business page.
Then in the view of the Add Business I set an associative array linking the state_id to the state name. Then I can pass that through $form->input('state_id', array('options' => $stateArray)).