Jump to content

A pretty basic php problem I think...


asmith6

Recommended Posts

http://i.imgur.com/6olCy.png

The picture (in the imgur link) pretty much describes what I'm trying to do. As it stands, it would take too long to simply do everything manually with html and css (both of which I'm pretty good at I think), moving all img src and dates from one div tag to another whenever I wanna add something. So yeah, what's the most efficient way to simply submit a picture, and all my other pictures will move?

 

I know some of you guys will say to just learn php, but quite frankly, I don't have the time... and all the php books are ~1000pgs long which seems really daunting. I know, my problem's pretty basic and it'll probably be covered in the first 100pages or so, but still, like I said I don't have that much time for the moment.

 

When I do, however, can you guys recommend me the quickest guide/video series/book to learn practical php? Not the most comprehensive, as the stuff I'm going to be doing's not that complex.

 

One last thing, I've been hearing about CakePHP; what is it? I read that it's an "open source web application framework", but I still have little clue. I'm currently using dreamweaver for all my web stuff (no I do not use the WYSIWYG feature, I just grown accustom to using it). Should I "learn cakephp"?

 

 

Please answer any one of those questions (particularly the first one). Many thanks and I'll be sure to reply!

Link to comment
Share on other sites

You want a pagination script. There are many tutorials on this, you don't need a book. I don't know where you are storing the image data at. Well, really I doubt if you are storing it since you say you are using HTML. To do this programatically you need to use somethign to determine the order of the images. Typically this is done in a database. But, again I will assume you are not using a database since you aren't using PHP. So, you probably just have the images stored in a folder and are deciding their order by the HTML pages you are manually editing. But, how are you determining the "date submitted"? Do youhave an upload script that is storing that information somewhere?

 

The "best" approach would be to use a PHP/MySQL approach. But, that would take a lot longer to learn. An easier, albeit, "hacK" approach would be to just use something like the file name or modification date to order the images. I'm really not going to go into muchmore detail at this time becuase I don't know what you need in your situation without more info.

Link to comment
Share on other sites

You want a pagination script. There are many tutorials on this, you don't need a book. I don't know where you are storing the image data at. Well, really I doubt if you are storing it since you say you are using HTML. To do this programatically you need to use somethign to determine the order of the images. Typically this is done in a database. But, again I will assume you are not using a database since you aren't using PHP. So, you probably just have the images stored in a folder and are deciding their order by the HTML pages you are manually editing. But, how are you determining the "date submitted"? Do youhave an upload script that is storing that information somewhere?

 

The "best" approach would be to use a PHP/MySQL approach. But, that would take a lot longer to learn. An easier, albeit, "hacK" approach would be to just use something like the file name or modification date to order the images. I'm really not going to go into muchmore detail at this time becuase I don't know what you need in your situation without more info.

Pagination script? I never heard of this. I thought I would just need to set some variables or something.

 

And no, I'm storing my image at amazon s3. I'm using nearlyfreespeech as my webhost, AND I'm actually using php include right now (but that's all the php in my coding).

 

What more info do you need?

Link to comment
Share on other sites

What more info do you need?

 

You state you want to display the images int he order that you submit them. How are you obtaining that information? If you can't programatically retrieve that information from Amazon then what is the script supposed to use to determine the order for display? You can create a hard coded array that would only require a single update whenever you add an image.

 

Pagination script? I never heard of this. I thought I would just need to set some variables or something.

Seriously? What good does a variable do without any logic to interpret the variable

$foo = 'bar';

There, I set a variable. Now I suppose everythign I want to happen will just magically occur.

Link to comment
Share on other sites

The database is the way to go if you want it truly dynamic.  The database table would contain the image url along with the date it was submitted, then you'd be able to query the database and order the results by the date descending and display using a gallery script that supports pagination.  The other way would be to rename the files on upload based on timestamp and read the directory of images.

 

It's easy if you know php, but I see from your post that you dont, so you could try googling for a gallery script that can do it, or maybe post in the PHP Freelance board

Link to comment
Share on other sites

What more info do you need?

 

You state you want to display the images int he order that you submit them. How are you obtaining that information? If you can't programatically retrieve that information from Amazon then what is the script supposed to use to determine the order for display? You can create a hard coded array that would only require a single update whenever you add an image.

 

Pagination script? I never heard of this. I thought I would just need to set some variables or something.

Seriously? What good does a variable do without any logic to interpret the variable

$foo = 'bar';

There, I set a variable. Now I suppose everythign I want to happen will just magically occur.

 

I really wish I knew what you were talking about hah (not familiar wth the whole lingo). Well, would I be able to acheive what I want by simply going over the w3schools/tizag tutorial?

 

The database is the way to go if you want it truly dynamic.  The database table would contain the image url along with the date it was submitted, then you'd be able to query the database and order the results by the date descending and display using a gallery script that supports pagination.  The other way would be to rename the files on upload based on timestamp and read the directory of images.

 

It's easy if you know php, but I see from your post that you dont, so you could try googling for a gallery script that can do it, or maybe post in the PHP Freelance board

 

How long would it take to learn basic php up to database table? I thought web coding is mostly div tags and li id tags >.<

 

And no, I intend on doing the actually coding myself. I just need some guidance :/

 

Thanks!

Link to comment
Share on other sites

Here is a "rough" script that may help you. All you need to do is edit four different variables.

 

$image_url: this will be the base URL/path to access the images - I assume it is the same for all the images

 

$rows_per_page: maximim number of rows to be displayed on a page

$cols_per_page: maximim number of columns to be displayed on a page

 

$images: this is an array of all the images to be displayed - in the order that they are to be displyed.

 

<?php
//Base URL to access the images (set this to your Amazon space)
//I have set to a folder on my server for testing purposes
$image_url = 'images/';

//User defined variables for page settings
$rows_per_page = 2;
$cols_per_page = 4;

//Master array of ALL the images in the order to be displayed
$images = array(
        'image1.jpg', 'image2.jpg', 'image3.jpg', 'image4.jpg',
        'image5.jpg', 'image6.jpg', 'image7.jpg', 'image8.jpg',
        'image9.jpg', 'image10.jpg', 'image11.jpg', 'image12.jpg',
        'image13.jpg', 'image14.jpg', 'image15.jpg', 'image16.jpg',
        'image17.jpg', 'image18.jpg', 'image19.jpg'
    );

//END USER DEFINED VARIABLES

//System defined variable
$records_per_page = $rows_per_page * $cols_per_page;
$total_records = count($images);
$total_pages = ceil($total_records / $records_per_page);

//Get/define current page
$current_page = (int) $_GET['page'];
if($current_page<1 || $current_page>$total_pages)
{
    $current_page = 1;
}

//Get records for the current page
$page_images = array_splice($images, ($current_page-1)*$records_per_page, $records_per_page);

//Create ouput for the records of the current page
$ouput = "<table border=\"1\">\n";
for($row=0; $row<$rows_per_page; $row++)
{
    $ouput .= "<tr>\n";
    for($col=0; $col<$cols_per_page; $col++)
    {
        $imgIdx = ($row * $rows_per_page) + $col;
        $img = (isset($page_images[$imgIdx])) ? "<img src=\"{$image_url}{$page_images[$imgIdx]}\" />" : ' ';
        $ouput .= "<td>$img</td>\n";
    }
    $ouput .= "</tr>\n";
}
$ouput .= "</table>";

//Create pagination links
$first = "First";
$prev  = "Prev";
$next  = "Next";
$last  = "Last";
if($current_page>1)
{
    $prevPage = $current_page - 1;
    $first = "<a href=\"test.php?page=1\">First</a>";
    $prev  = "<a href=\"test.php?page={$prevPage}\">Prev</a>";
}
if($current_page<$total_pages)
{
    $nextPage = $current_page + 1;
    $next = "<a href=\"test.php?page={$nextPage}\">Next</a>";
    $last = "<a href=\"test.php?page={$total_pages}\">Last</a>";
}

?>
<html>
<body>
<h2>Here are the records for page <?php echo $current_page; ?></h2>
  <ul>
    <?php echo $ouput; ?>
  </ul>
Page <?php echo $current_page; ?> of <?php echo $total_pages; ?>
<br />
<?php echo "{$first} | {$prev} | {$next} | {$last}"; ?>
<img src="/images/button11.jpg" />
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.