Jump to content

Need help with sorting images from a DB by order of upload. THANKS


Recommended Posts

I have http://FLcarsForYou.com almost working... except I cant get the images to sort correctly.

 

On the admin upload area, ive asked the customer to add the "main listing" picture first, so it does not come up with a picture of the interior on the multi-listing pages. I must have screwed something up, because now it lists the last picture as the main image...

 

So.. if you are the know-all of sorting... please give me guidance. Thanks!

 

 

The table has id_files which is an incremental rising number per upload... and it looks like the uploaded files keep the its filename used by his digital camera "DSCF9816.JPG" which makes me think they are being listed by alphabetical right now, because some will work for him and others wont.

 

Feel like im getting closer, but no, there is no timestamp column

//select images connected to a given listing

$query = "SELECT * FROM tbl_Files WHERE prop_num = $a_row[id] LIMIT 1";

$output = mysql_query("$query",$link);

 

 

 

$count = 0;

while ($image_row =mysql_fetch_array ($output) )

{

 

 

print "<td valign=top align=center width=115><a href=\"./carview.php?view=$a_row[id]\"><img src='image.php?Id=$image_row[id_files]' border=1 width=175 alt=\"Photo\"></a><br></td>";

$count++;

}

 

 

if ($count == 0)

{

print "<td valign=top align=center width=115><a href=\"./carview.php?view=$a_row[id]\"><img src=\"./images/nophoto.gif\" border=1 width=175 alt=\"View Listing\"></a><br></td>";

}

 

That should be the multi-listing portion... and the individual listing page

 

//select images connected to a given listing

$count = 0;

$query = "SELECT * FROM tbl_Files WHERE prop_num =  $a_row[id]";

$result = mysql_query("$query",$link);

while ($image_row =mysql_fetch_array ($result) )

{

print "<font face=\"arial\" size=1><b>Click photos to enlarge</b></font><br><br><p>";

echo "<B>";

echo stripslashes($image_row[description]) . "<BR>\n";

echo "</b><table border=1 cellspacing=0 cellpadding=0 width=100><tr><td align=center><a href=\"http://flcarsforyou.com/image.php?Id=$image_row[id_files]\" target=\"_new\"><img src='image.php?Id=$image_row[id_files]' border=0 width=175 alt='Click to Enlarge'></a></td></tr></table>";

echo "<P> \n";

$count++;

 

 

}

print "</font>";

 

if ($count == 0)

    {

    print "<table border=1 cellspacing=0 cellpadding=0 width=100><tr><td align=center><img src=\"./images/nophoto.gif\" border=0 width=175></a></td></tr></table>";

    } 

 

elseif ($count == 1)

{

print "<font face=\"arial\" size=1><b>Click photo to enlarge</b></font><br><br><p>";

}

else

 

{

print "<font face=\"arial\" size=1><b>Click photos to enlarge</b></font><br><br><p>";

}

 

And here is the upload  part, incase i can update it to add timestamp..

 

Now that i think about it... Timestamp might be an issue if the customer wants to delete a picture and update it... it would then be the latest added..

 

 

if ($action == "upload")

{

if (isset($binFile) && $binFile != "none")

  {

  $data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));

    $strDescription = addslashes(nl2br($txtDescription));

    $sql = "INSERT INTO tbl_Files ";

    $sql .= "(description, bin_data, filename, filesize, filetype, owner, prop_num) ";

    $sql .= "VALUES ('$strDescription', '$data', ";

    $sql .= "'$binFile_name', '$binFile_size', '$binFile_type', '$current_user', '$propnum')";

   

    if (!mysql_query ($sql, $link) )

{

die (mysql_error());

}

   

    echo "Your image has been added ($binFile_name).";

   

  }

}

Maybe adding a checkbox next to the images in the admin section, allowing the customer to upload all images, and then select the main image...

 

Im guessing that would need a checkbox with a value of 1 or 0 and then make the images list with "is_main_image=1" coming up first. Does that make much sence? I havent had much php experience.. especiall with mysql

Getting the user to specify the main image seems the best idea, rather than relying on the order. I'd use radio buttons rather that checkboxes to make sure only one can be specified,

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.