I have three pages I want to split into 4 and I need to add some extra items and need some advice as maintaining these pages is a pain: Page 1
Currently the links at the top of the page are in an array to generate the links to the examples and the examples are in a table - all hard coded. But I am thinking there must be a better way to do this.
I still want the same basic layout but may move from a table to css althought this could be a problem with different browsers.
I need to generate the images to go with the examples so I have the php code on the page as well and after I run the page once I go and comment that out which is a pain as I have so many examples.
So would a database be the way to go or some otherway?
I want to be able to:
Add new examples within the current examples
Run the image generating code when required to generate the images - this is the same as the code displayed on the page using highlight_string()
Split the pages up when they get to long
On the page I have:
Operator name for a link
1 or 2 images per operator - sometimes there is no image but some text.
Operator title
Code - Highlighted using highlight_string()
Short description of the code
Default text if I do not have an example of the operator
How about you show us all you have got but just for 1 or 2 samples - what you have in your db …(or what you imagine you should have in your db)
If I understand you, you want to keep some PHP code in your db (along with other attributes), then run that code as PHP code and get the result, and then re-use that code as html displayed PHP snippet, is that it?
The other thing you are looking for is pagination of results – would it be better to think in “families” of image enhancement functions instead of pagination I wonder?
You probably need to activate some simple caching mechanism so that you run this code on demand and a html snapshot of each page is stored on the hdd till another run is made – looks an expensive page to make.
I have a link to the current page on the first post - this is all hard coded and I have removed all the actual php code to create the images etc. before uploading the page:
If I move to a database method I could have a normal display page showing the current information and an admin page that loops through all the examples just running the code and saving the output?
Database columns:
ID > 1
Title > Charcoal
Description > Simulate a charcoal drawing.
Code > $cmd = “<?php $input -charcoal 1”; exec(“convert $cmd charcoal.jpg”) ?>;
Image > charcoal.jpg ( could be a jpg, png or gif )
Operator > -charcoal ( can not use the Title and add a - as some operators have a + )
Text > if the output is texual rather than an image
Some Text or Images could be a null and some examples have two images. I could combine these two images into one image but again this means some different code between the admin page and the display page. There are not many examples with two images and I could write some code to allow for this in the admin page.
I also have some operators without an example as I can not think of a suitable one and some operators are depreciated.
It gets a bit confusing as I say because some code either outputs an image or text and I will need to save the text and not display it. This means the code in the display page will be different to the code on the admin page.
I have been thinking that the database method is the way to go but wondered if there was a better alternative.
If I understand you, you want to keep some PHP code in your db (along with other attributes), then run that code as PHP code and get the result, and then re-use that code as html displayed PHP snippet, is that it?
Yes that is correct.
would it be better to think in “families” of image
That makes sense but I am not sure how to break them down further as I also have a seperate page for compose and layers.
I had assumed you were actually evaluating the code sample using eval() or something and then really generating the image on the fly each time the page loaded.
No I had not even thought of eval()
When I started I only had two pages, now I have 3 and it is increasing.
I think I will try the database method as it makes sense the more I think about it although most operators will work OK there could be a couple of problem ones.
I do not think caching is a problem as the page only gets changed a couple of times a year mainly due to the painful process of updating it.
Thanks for the tips Cups and I now have an idea what to do - there is the harder part to come dealing with the oddball examples.
I am a bit busy with other things at the moment but have this test code:
// Image to use in the code
$input = "images/input.jpg";
// Loop through all the examples and create the image
// Also display the example details in a table
while ( $row = mysql_fetch_array( $result_name )) {
// Put the code into a variable
$code = $row['code'];
// Run the code to create the image
eval($code);
// Display the data
echo "<tr><td>";
echo "<img src=\\"".$row['image']."\\"></td><td><a name=\\"".$row['operator']."\\" class=\\"name\\">".$row['title']."</a><br>";
highlight_string("<?php
$code
?>");
}
I will have two pages:
1/ Will display the example data and image from the database like the current page - no eval().
2/ Will create the examples using eval() - this page will need to be in the same folder (unless there is some trick I can use to modify the image location from the database data) and so I will only upload it when I want to run it. I can not put it into a passworded folder as the image path is in the database $row[‘code’].
I am still working on this rewrite and I an now at the “pagination point”.
I have decided that I like the current design but I am going to have about 10 or so items per page. I like on this page Page 1 where it says “Page 1 covers -adaptive-blur to -floodfill” to cover each page and be created from the database and I would also like a next/back buttons on the pages so people can browse through if they are not sure what they are after.
I have one problem that all the items are not in order - as I add a new item to the end of my table it could belong to page 3 for example.
Thinking while writting this I could have a seperate table with the items to have on each page that I would rebuild if I add another item?
Any comments on the method or design would be useful.