I have a table with date/time, temperature and humidity data stored on a mysql database.
I have a ugly looking but working HTML one so I made a new CSS table using templates and wanted to use the looping in PHP (as in the HTML) to fetch data to the table using the table designers format. (Some datas are manually in as in the sample table photo)
I want to automate that but my PHP script has a problem and does not load the page. shows error.
Im very new to LAMP environment actually and unsure if I can use class variables inside the PHP script without changing anything.
My table looks like this without the python script: https://imgur.com/a/WmpHzMZ
The code is here: https://codeshare.io/amvPYw
(I cannot add code here, it says bad formatting everytime)
Html element tags are close like </tr>. See your end line in while loop.
Related
I am making a database and a corresponding website for the same. The website offers taking (scientific) queries from the user and searching the information (protein/nucleotide sequences, name of organism, accession id, etc.) against my database as an output.
I am done with the database and the website, even the script (HTML->PHP->Perl) fetches information asked by the user.
My Problem
Let's take for example, a database with Employee info like ID, name, age, sex, etc.
I have all the output information in an array. The problem is when I have to post it into a html output. The thing is, I can print these values like printing the complete html file with the respective tags and then opening the html file, but my web page has some buttons/options which will do something (here, print any info, drawing charts using the values like age, salary,etc.). It will also have a scroll function for displaying the information and the buttons on the bottom of the page.
So I need some basic guidance,
Should I go with dynamic pages or static?
If dynamic, is there any way I can parse the arrays from Perl to PHP?
If it's in a database, I'd go dynamic. But I don't understand why you're jumping between perl and PHP, either can do the job on it's own.
If your data is being queried into arrays in perl, parse it out into JSON or XML. Both perl and PHP have awesome parsing modules available.
So first I want to say that I'm pretty new to php & javascript. But anyways, I want to make something like a User Interface (1) where you can write sth into certain fields which will create a string for every field and save it into a file on the server so you can get the values the fields should have from other devices.
This is a little graphic to show you what I want to make:
So I'm wondering if anybody knows if it's possible and how to create the file/load the values from it.
I think what you might want is a database, that way one php function can write those values to a db and then another can retrieve those values whenever.
If u r using mysql then ...
Create a php script that passes the parameter to database using mysqli_query function (that is saving data in database) and after that the website script can retrieve data from the database. .
I'm trying to realize a dynamic website for exercise. All contents are stored in the database:
I included html code(FORMS) as DB content with no ploblem, but when i try to insert php code as DB content nothing happens. The field type for Content is TEXT.
I tryed various ways :
INSERT INTO TableContent(Name_Content, Content, ID_Menu) values ("Amministration Area", "<?php include('LogIn.php')", 5);
INSERT INTO TableContent(Name_Content, Content, ID_Menu) values ("Amministration Area", "<?php include(\"LogIn.php\")", 5);
In the website page i see Amministrazion Area, but not what Login.php does.
I thought i made a mistake in Login.php page code so i changed it in a simply echo ("Hi"); but nothing appears anyway. I see only the text Amministration Area.
How can i solve it ?
It's just text! Text in a database. Nothing happens when you just insert text into a database and read from it. You have to actually get something to execute that text as PHP code. That doesn't happen automatically, thankfully! In PHP, the way to execute arbitrary strings as code is by using eval. But this is overall a very bad idea; storing all PHP code in a database is not making anything easier, on the contrary it makes everything more difficult to work with and more prone to exploits if you execute arbitrary code. I'd advice you to stop doing that and go back to PHP code in .php files, not databases.
PHP see <?php include("LogIn.php");? as a string, when you look in the source code of your file, you'll probably see it. It doesn't show up on screen because it starts with a <.
To execute the code instead of handling it as a string, you can use the eval() function.
You however don't want every row of your database be seen as PHP code, so you'll probably need to add a extra column that defines what the row is, i.e. a string, php code. Or you make an extra table where you store your includes.
i have a website with a Mysql database that has html in each row (yes, i know this is not ideal). The problem is that the programmer simply copied and pasted duplicated text in many rows. I therefore have to manually edit the html in many rows if i need to update the text. I wanted to includ a 'include' or 'require' function and store the generic html in an external file but it doesnt seem to parse in the mysql output (only shows the static html). Therefore, how can i include reference to an external file in the header html of the mysql rows that contains html? That is, i need to parse php included in a row of the mysql database and not from a php page calling to the database. I tried to the eval function but still it could not retrieve a external php file.
Another alternative is that the duplicated text is actually another row in the database. Therefore, i'm not sure how i can make a page dynamically pull multiple rows from the database in a specific order?
What a mess. Any ideas?
Cheers
You could parse each rows when getting them.
preg_match_all ("#include\((.+)\)#", $row, $result);
foreach ($result[1] as $value) {
include ($value);
}
Or something like that. :)
( http://php.net/manual/fr/function.preg-match-all.php )
I have an HTML table with contents, I would like to have an feature of Edit/Delete to that table. How do I do it with PHP?
I actually think that this sounds more like a job for JavaScript, which can edit/remove rows on-the-fly and with much less code. (Implement some AJAX too, and you can edit/remove rows in database too).
But if you insist on using PHP, you might just want to add some GET parameters to the Edit/Delete links that would delete or edit those rows.
Well, there is a pure PHP way to do it, and then there is a combination of Javascript and PHP. You must use PHP one way or another if you want your changes to the database to be permanent as that is your gateway to communicating with the database (as far as I know you cannot do that with Javascript as that is client-based and runs entirely in your web browser).
If using just PHP, you must generate HTML documents for each change. E.g., you click on one cell in the table and that gets you to a new HTML page where the field is editable through an input element; or you can list all fields at once for that row and edit them all at the same time. The fields are then posted in a form to a PHP page which will take the new values and update the database (or insert new values or however you wish it to behave). Here's a tutorial for how to do this:
http://www.freewebmasterhelp.com/tutorials/phpmysql/1
You can also mix in some Javascript which allows a more interactive interface to modifying the values in a cell. However, this obviously requires more code and may be overkill for what you're trying to do. Nonetheless, here is a link which demonstrates just that and also shows the code:
http://www.java2s.com/Code/JavaScript/GUI-Components/Editabletablecell.htm
Hope this is what you're looking for.
EDIT:
Forgot that you also wished to delete content in the table. That is also explained in the first link.
If you intend to work with databases, and it seems like you have little understanding of how they work, pick up a good book like: SQL - The Complete Reference. When you have enough knowledge of SQL, look at PHP's PDO extension: http://php.net/manual/en/book.pdo.php