Jump to content

[SOLVED] Need help with sorting function


Kevin Marks

Recommended Posts

My code is below...

 

<?php
include('../settings/settings.php'); ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="/www/css/thumbs.css" type="text/css">
<title> Title <? echo $sitetitle; ?></title>
<style type="text/css">
<!--
.style1 {
font-family: Arial;
color: #CCCCCC;
font-size: 14px;
}
.style2 {
font-family: Arial;
font-size: 12px;
}
-->
</style>
</head>

<body style="margin: 0px;">
<table width="100%" height="655" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="333" rowspan="2" align="left" valign="top"><img src="../layoutpictures/model.jpg" width="333" height="600"></td>
    <td height="82" align="center" valign="middle"><p><img src="../layoutpictures/info.jpg" width="500" height="50"><br>
      <span class="style1"><a href="../../../../index.html">Back to Homepage</a>  | <a href="../../index.php">Back to Girl's Page<br>
      </a><a href="../photos/medium/Set1.zip">Download .Zip file of images</a></span>
    </p>
    </td>
  </tr>
  <tr>
    <td height="525" align="center" valign="middle">


<?php


    // create an array to hold directory list
    $results = array();

    // create a handler for the directory
    $handler = opendir($directory);

    // keep going until all files in directory have been read
    while ($file = readdir($handler)) {

        // if $file isn't this directory or its parent, 
        // add it to the results array
        if ($file != '.' && $file != '..') {
            $results[] = $file;
    }

}

    // tidy up: close the handler
    closedir($handler);

?>

<table width="100%"><tr align='center' valign='middle'>

<?php
foreach ($results as $thumb) {
$index = $index + 1;
$col= $col +1;
if ($col<"6") {
	echo "<td>";
} else {
	echo "</tr><tr align='center' valign='middle'><td width='20%'>";
	$col = 1;
}
echo "<a href=\"../galleries/gallery.php?size=medium&index=$index\"><img border='0' src='$urltothumb$thumb'></a>";
echo "</td>\n";
}
?>
</table></td>
  </tr>
  <tr>
    <td align="left" valign="top"> </td>
    <td height="18" align="center" valign="middle"><span class="style2">information </span></td>
  </tr>
<tr>
  <td colspan="2" align="CENTER" valign="MIDDLE" height="30"> </td>
</tr>
</table>
</body>
</html>

The images that are being read in the array are in need of being sorted.  the readdir() function returns the files as they have been stored on the Linux server (which is not alpha numerically).  I have tried using variations of sort() and natsort() with no success... there is always a parsing error either on the line or after the line where I insert it.

 

Suggestions????

 

Mod edit:

...

add around your code. Also use <?php so code is color coded inside the code tags

 

 

Link to comment
Share on other sites

Post the error.

 

 

I have tried using variations of sort() and natsort() with no success... there is always a parsing error either on the line or after the line where I insert it.

 

Suggestions????

 

Mod edit:

...

add around your code. Also use <?php so code is color coded inside the code tags

 

 

Link to comment
Share on other sites

<?php


    // create an array to hold directory list
    $results = array();

    // create a handler for the directory
    $handler = opendir($directory);

    // keep going until all files in directory have been read
    while ($file = readdir($handler)) {

        // if $file isn't this directory or its parent, 
        // add it to the results array
        if ($file != '.' && $file != '..') {
            $results[] = $file;
    }

}

//to fix sorting issue due to readdir() function
natsort($results)

    // tidy up: close the handler
    closedir($handler);

?>

 

and the error is is producing.

 

Parse error: syntax error, unexpected T_STRING  on line 61

 

Line 61 is the closedir($handler) line

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.