I have an array made up of dated events that I list on a webpage using PHP to generate the page that shows a date sorted table. I am trying to insert the PHP time() function, in a specific format that works for me, into one specific record of the text (CSV) array so that every time someone opens this page, this one specific record always reads with the current date in the format that I need. I have tried many variations of
<?php print ((time() + '39681000000')/1000000); ?>
Both with and without the PHP open and close tags, and many other variations, but with no success. The record just shows a blank field with this function in it with the tags and just shows the code without the tags. The PHP function works fine stand alone, but will not work when inserted in the record field. It does not seem that I can insert any PHP function, let alone this one, into the record field and have it work, so it does not seem to be a problem with how this function is written.
I have also tried to declare this as a Global variable at the top of the page and then call it in this field, but that does not work. I have tried the now() function with no joy either.
Thanks,
Stan...
In that case a string replace might be the best option (like mentioned above by drew). Try to remove the PHP code from the CSV file and replace it with something like ${DATE}, then put something like this in your while loop that imports the CSV file right after you set $line:
$line = str_replace('${DATE}', (time() + 39681000000/1000000), $line);
Related
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.
I have a question on how to achieve something from a development standpoint in Laravel. I am looking for ways to use autoload to return data from a database by just supplying a few character entry. For example, if I need to search for the word 'Johnson' which is already stored in a table in the database, supplying the word: 'Joh' in the search bar should bring up Johnson and other names like Johnson. I am very new to PHP and laravel, does anyone have any suggestions?
You are going to have to use Ajax and php to do this.
Basically the logistics will be as such:
a key is typed into an input which will load a javascript function that does a post to a php file. That php file will do a query for "Joh%". All records will come back matching Joh%. Print them out with php and it will be delivered back to the javascript function which called the php file in the first place. Now that javascript function will have to manage adding and subtracting entries from the dropdown on the input box you are typing in.
The question your asking is basically a lot of code and you should take it step by step. First start by getting a php query to work where you get records matching "Jon%", then continue on to another step.
I have a page that is full of tables (generated by a foreach loop) and every row displays, among other things, a month.
Now I want to give the user the ability to choose a month and have only the table rows for that current month displayed (or no table at all if that month is missing from the table). A bit like the filtering function in Angular JS.
I'm still a bit new to php and the only solution I can up with is to handle the whole thing somewhat clumsily with modifying CSS classes and having the superfluous rows hidden by CSS.
What would be a more efficient way to do this?
Your problem is related with the filter alternate of angular into php.
As you know php is server side. So, if you want to get the filter after a reload or by ajax method, you need a $_GET variable.
Use a different query string in your url for each click of each button. Then retrieve the GET variable and use it to get data from database for relevant category.
before anyone asks; I've googled my 'question', I've also looks at the 'Questions that may already have your answer' and none of them work.
What I'm wanting to do is 'Pagination'. However, I don't want to use Databases as I've never had to and I'd rather not give up and go to them now as XML does everything I want it for.
The code I have is the following:
$files = glob('include/articles/*.xml');
foreach($files as $file){
$xml = new SimpleXMLElement($file, 0, true);
}
I've tried these ones already: XML pagination with PHP, PHP XML pagination and Pagination Filtered XML file and have achieved nothing. I have also tried a lot of Javascript 'pagination' scripts and still nothing.
So to sum it up: I have four articles (More to be added) and I want to show 2articles per a page. The following information will be 'pulled' from the xml file: ID, TITLE, CONTENT, PICTURE, AUTHOR, DATE by doing $xml->id and so on for the rest of them. Does anyone know of any way of doing this? as I've spent the past four hours (Its 4:04AM GMT) and have found nothing that works yet. (If I find anything that does work I'll make sure to update the question with the working code encase there is anyone else out there that needs help with this too.)
For a start define the order in which you want your articles to appear. I.e. which article goes on page 1, which one on page 2, etc. This is important, because that order will be the base for your pagination algorithm. Please note that glob() is not guaranteed to return results in any specific order, which means the order can change from one invocation of your script to another (notably when you add new articles) -- almost certainly not what you want.
Then the second step is to introduce another variable which is part of your URL that denotes the actual page (number) you're on. The URL query string would be a natural choice for putting this information, so your URL's look like: article.php?page=1. On the PHP side you can use the $_GET superglobal to retrieve the query string parameters.
Thirdly, use the new style URL's whenever you link to your article.php script. Additionally, validate the input --especially when you also want to display the current page based on this parameter (or you will end up with an injection vulnerability). This also means you want to have a default value (in case the value is invalid/wrong/ or not supplied at all for some reason).
Finally, filter your articles based on the two key pieces of information: the order of the articles w.r.t. the page number and the page number: i.e compute the actual articles that should appear on the current page.
I'm trying to fill a page with content from a database. My thinking is, to use some kind of while loop in php and go through each row in the database and use jQuery's .prepend command to add it below the other content.
The problem I'm seeing in this, is that every time the page is loaded it would be pretty resource intensive to have to load through every row in a table and display it.
I was thinking that when I display the item I should then change a value in the table that indicates that it is already displayed and therefore keep the current content. My problem with this is, how exactly would I keep this content there if it's dynamically added like this?
Or is there just a better way in general to do this?
Keep track of which entry #s you've already stored and deal with the new stuff using sql's limit function.
Add a timestamp to each row in db
whenever you read in jquery the rows keep the last timestamp in a variable
when you send request in jquery add the last timestamp and then filter using query WHERE update_time > $jquery_timestamp
using this way, only new info will be sent