Calling all PHP People!

I revamped the personal section of my site. I’m trying to keep it small and compact, and there is as always stuff to be added. If anyone has a browser other than Internet Explorer 6 or Mozilla Firefox 0.9, could you take a look and make sure the layout isn’t totally whacked out? Thanks! There are new photos on there too, of seahorses!

Also, I need all you people who are good with PHP! My next assignment I’ve given myself on my art archive is to do two doable but probably very tedious things.

One is, to have my search results display on multiple pages, so 10 results would display on one page and so on.

The other is, when you click on an image and go to the display page, to have Back and Forward buttons that will go through the images in the search results.

Both of these seem like they need to involve some magical global list to store search results in (it would actually only need to store 1 attribute of the results, because I can get all the info I need from the id number), but I do not know enough PHP to figure out a good way to do this.

Any advice?

9 thoughts on “Calling all PHP People!”

  1. They’re both doable-but-tedious. You don’t need a magical global list, though, because you have a database that you can requery every time you render a page.

    What you probably want to do is pass an argument through the URL (like gallery.php?start=20 would set the $start variable to 20). You’d then requery the database based on that argument, something like this:

    $gallery_query = "SELECT * FROM gallery WHERE gallery_id>=" . $start . " ORDER BY gallery_id ASC LIMIT 10";
    $gallery_result = @mysql_query($gallery_query);
    while ($gallery_row = mysql_fetch_array($gallery_result)) {
        // Print out data for each result, like thumbnail image, link, etc:
        echo '<img src="' . $gallery_row["thumbnail_filename"] . '" alt="' . $gallery_row["title"] . '" />';

    mysql_fetch_array puts the results of the next row in a query into an array, with items in that array indexed by database column names. Each time you call mysql_fetch_array, it automatically gets the next row from the result set, until there aren’t any more–then it returns FALSE, so the loop would stop automatically at the last (probably 10th) result from the query. You could then add 10 to the $start variable, call that $next, and generate a url like “gallery.php?start=30” for the “Next” button like this:

    $next = $start + 10;
    $boundary_query = "SELECT * FROM gallery WHERE gallery_id=" . $next;
    $boundary_result = @mysql_query($boundary_query);
    if $boundary_result {
        echo '<a href="gallery.php?start=' . $next . '">Next Page</a>';

    And something similar for a “Previous” button.

    The engine would be basically the same for individual images, except you’d only be getting one result at a time, and you’d want an “up” button for going to the gallery page on which the image was located (round down to nearest ten and use that as the $start argument).

    Am I making sense?

    1. Oh, and I should mention that there is software out there that does this. Google for “php image gallery software” or something similar. Obviously, you might have less control over your images’ presentation that way, and it would probably read directly from a directory instead of a database, but it could save you some work.

      1. Nah, I’m hard core, I want to do it myself.

        One thing, is the start variable just a separate variable that is like a counter? Or is it to be what the id number of the image is? Because the results of a search will return a bunch of id numbers that are probably out of order, so adding 10 to the id number would not work to get the next set.

        1. Hmm… you could make it a separate variable if you wanted, although that would be harder. Why don’t you have an ordered index column?

          1. I do, i mean, the id_number is an index. However, if you were to search for say, all Digitally Colored images from 2001, the id_numbers you get will not be in sequential order, there will be a bunch of skips. Unless there is a way to assign an index number as you make the query.

          2. Oh, I see. Well, okay, if you select all digitally colored images from 2001, then sort by ascending id_number, you will get them in order (but still with gaps).

            What you can do is instead of selecting LIMIT 10 results (which will give you a result set of 10 or fewer rows), you can select LIMIT (10 + $start), then set up a for loop to go through the first $start rows without displaying anything. Then the mysql_fetch_array cursor will be in the right place when you actually start displaying them. You see what I’m saying?

            Like this:

            $gallery_query = "SELECT * FROM gallery WHERE gallery_id>=" . $start . " ORDER BY gallery_id ASC LIMIT " . ($start + 10);
            $gallery_result = @mysql_query($gallery_query);
            // Skip cursor ahead
            for ($i = 0; $i < $start; $i++) {
            // Then start printing
            while ($gallery_row = mysql_fetch_array($gallery_result)) {
                // Print out data for each result, like thumbnail image, link, etc:
                echo '' . $gallery_row[';

            Although you could just as easily make that 10 a variable too, if you wanted to be able to adjust it; you could have it default to 10, or be set differently if you passed it through the url (gallery.php?start=20&size=10).

            Anyway, there might be a better way to do it, but that’s the first thing that comes to mind.

  2. Can’t help you PHPwise yet, my semester break starts in one week, then the learning begins. 😉

    But Designwise i can help, using Opera 7.50 i have no problems navigating through your interesting design. But that also brings up a point of critique: That black frame you’re using should be attached completely to the upper left corner of the site. Furthermore a “antialiased” border would look better – But i assume that you had this thing rather for study purposes…. 😉

    1. Yeah I was just kind of messing around and trying to keep the filesize decently small. I generally usually just make my site space 800 x 600 for the small-resolutioned viewers. Do you think it would be better if I just made a black outline go all the way around, like enclosing it in a box?

Comments are closed.