Does php has datagridview object or something? Or do I just make a table out of it? I need to do this format, http://replays.mineski.net/.. Do you think XML as a information storage is suitable for this?
well, html table is itself some kind of datagrid. So just use html table, tr, td to achieve what you want, additionally, use th for table headers. Good luck.
You could use something like PEAR datagrid http://pear.php.net/package/Structures_DataGrid, there are also some nice javascript based ones you can use eg: http://www.trirand.net/demophp.aspx
Related
I have a question, I want to have a dynamic table in php without database. The number of rows and columns in the table should be easy to adjust.
I want to make a variable of the rows and columns.
How can I make this? Is here a tutorial about?
thanks in advance.
You can use a number of ways to store your data. If you choose not to use a database then saving the data to file after encoding it would probably the next most common way.
Take a look at the XML example I've included here, let me know if you have any more questions. There is definitely more than one way you can do this.
PHP XML to dynamic table
I have a html table, generated by another website that I'm trying to convert to a php array.
I can not convert it using simplexml because the code of the generated table is not valid, and cause a lot of errors, also I need to keep some attributes of the table td elements, and remove the others.
What would be the most efficient way of doing this? Or do you know any php class that could help me achieve this?
BTW: What I'm trying to do is convert an school schedule to a php array, that I will be able to exploit after.
Here is an example of the data I retrieve: http://paste2.org/p/1869193
Btw, using php strip tags, I already remove the unnecessary tags such as spans and fonts.
You can also use PHP's Tidy if installed (it is by default on some installs) - it not only cleans up the HTML, but also lets you traverse the DOM:
http://www.php.net/manual/en/book.tidy.php
You can find a list of HTML parserd in the answers of the following question on SO:
Robust and Mature HTML Parser for PHP
I need to get the data out of all of the table cells in the 4th row of the 4th table on an HTML page. After researching for a while, it seems that using DOMXPath is the best way to parse the HTML file. However, no IDs or classes are used anywhere in the file. What would be the best way to get the data out of these cells?
Thanks in advance.
You can specify an index when fetching with XPath. In your case
/html/body/table[4]/tbody/tr[4]/td
Note that an XPath index is not zero-based, but one-based.
If you are familiar with jQuery syntax, have you looked into phpQuery?
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
I want to store the contents of an xml file in the database. Is there an easy way to do it?
Can i write some script that can do the task for me?
The schema of the XML file looks like this:
<schedule start="20100727120000 +0530" stop="20100727160000 +0530" ch_id="0210.CHNAME.in">
<title>Title_info</title>
<date>20100727</date>
<category>cat_02</category>
</schedule>
One thing to note is:
How do I read the start time? I need the time +0530 added to the time?
Thank you so much.
You'll probably want to create a table called schedules that matches your data, then read the contents of the XML file with an XML parser of your choice. SimpleXML might be the right tool for this job.
As for the dates, I recommend you try using the function date_parse_from_format().
look up simple_xml on the php page - off hand I'm not too hot on it, but basically you will end up with a loop which will add your data to an object eg:
$xml
and you will be able to call tags as such $xml->schedule->title $xml->schedule->date and $xml->schedule->category and you will be able to call attributes as such $xml->schedule[start] but you might wanna check that.
I had to do this recently for a client, and this was the best way I could find. The attributes may be tricky - I can't quite remember but you might have to look into namespaces and such... anyway, find simple_xml and you're on the right tracks.