简体   繁体   English

PHP SQL查询生成器

[英]Php sql query builder

For a client i am working on a mysql php database with a web interface, and i need to have a section where they can build reports and save them. 对于一个客户端,我正在使用带有Web界面的mysql php数据库,并且我需要有一个区域,他们可以在其中构建报告并保存。 Does anyone have any suggestions as to how i got about doing this with a table that has 3 or 4 joins on it? 有没有人对我如何对具有3个或4个联接的表执行此操作有任何建议? And what is the best way to build pdfs with php? 以及用php构建pdf的最佳方法是什么?

I mean about in terms of displaying to the user and what questions to ask - I was thinking about the office access query wizard and maybe doing something like that. 我的意思是向用户显示内容以及要问什么问题-我正在考虑Office访问查询向导,并且可能正在执行类似的操作。 Asking what fields they want to display, what order etc. I was just looking for decent ways to do that and how. 问他们要显示哪些字段,顺序如何等。我只是在寻找一种体面的方式以及操作方式。

Thank you for the two suggestions for PDF writing, I will look into them. 感谢您提供有关PDF编写的两个建议,我将对其进行研究。

To generate pdf's in php I use fpdf . 要在php中生成pdf,请使用fpdf It's easy, free, and more functional than some of the alternatives. 它比某些替代方案更简单,免费,功能更强大。 For more help with the rest of your question I'd really need more information. 要获得有关其余问题的更多帮助,我真的需要更多信息。

There are some pretty decent PDF Libraries available in PHP...TCPDF is pretty easy to use to take HTML and render/output as a PDF. PHP中提供了一些相当不错的PDF库... TCPDF非常易于使用,可以将HTML以及呈现/输出为PDF。

As far as your question about the database, if the tables are always going to have the same 3 or 4 tables joined, I typically put the table name or alias in front of the field name. 至于您对数据库的问题,如果这些表总是要连接相同的3或4个表,则通常将表名或别名放在字段名的前面。 If I'm using a multi-select to allow users to select the field, I'd do: 如果我使用多重选择来允许用户选择字段,则可以执行以下操作:

    <option value="mytable.first_name">First Name</option>

I'm obviously making a lot of assumptions here, it'll be harder if there's a variable number of joins because you'll have to manage the tables and the join conditions and apply them when appropriate. 我显然在这里做了很多假设,如果连接数可变,将变得更加困难,因为您必须管理表和连接条件,并在适当时应用它们。 If I had to handle a variable number of joins, I'd probably create an array with join conditions; 如果必须处理可变数量的联接,则可能会创建一个具有联接条件的数组。 loop through all the fields I have selected above and pull the tables out. 循环浏览我在上面选择的所有字段,然后将表拉出。 Then use the tables in my join array to fetch out the join on directives. 然后,使用我的join数组中的表来提取join on指令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM