Jump to content

My image gallery code isn't working...


asmith6

Recommended Posts

I'm tired and just about given up. Can anybody help me?

 

 

<?php
	$objConnect = mysql_connect("localhost","","root") or die(mysql_error());
	$objDB = mysql_select_db("sdf");
	$pic2 = "SELECT * FROM images";
	if (!isset($_GET['Page']))	$_GET['Page']='0';
	$pic1 = mysql_query($pic2);
	$Num_Rows = mysql_num_rows($pic1);
	$Per_Page = 16;   // Per Page
	$Page = $_GET["Page"];
	if(!$_GET["Page"])
	{$Page=1;}
	$Prev_Page = $Page-1;
	$Next_Page = $Page+1;
	$Page_Start = (($Per_Page*$Page)-$Per_Page);
	if($Num_Rows<=$Per_Page)
	{$Num_Pages =1;}
	else if(($Num_Rows % $Per_Page)==0)
	{$Num_Pages =($Num_Rows/$Per_Page) ;}
	else
	{$Num_Pages =($Num_Rows/$Per_Page)+1;
		$Num_Pages = (int)$Num_Pages;}
	$pic2 .=" order  by thumbnailID ASC LIMIT $Page_Start , $Per_Page";
	$pic1  = mysql_query($pic2);
$cell = 0;
$link1 = "SELECT * FROM images";
$result_link1 = mysql_query($link1);
$link = mysql_fetch_array($result_link1);
$alt1 = "SELECT * FROM images";
$alt = mysql_fetch_array(mysql_query($alt1));
echo '
    <div id="tablediv">
      <table border="0" cellpadding="17" cellspacing="0" class="table">
        <tr>';

  while($pic = mysql_fetch_array($pic1)) {

    if($cell % 4 == 0) {
      echo '</tr><tr>';
    }

    if($cell == 2) {
      echo '
        <td>
          fillerspace
        </td>';
    } elseif ($cell == 3) {
      echo '
        <td>
Fillerspace2
        </td>';
    } else {
      echo '
        <td>
          <a href="/' . $link["link"] . '.php">
            <div class="image">
              <img src="https://s3.amazonaws.com/image/' . $pic["pic"] . '.png" 
                   alt="' . $alt["alt"] . '" 
                   height="200" 
                   width="200" 
              />
            </div>
          </a>
        </td>'; 
    }
    $cell++;
  }
  echo '</tr></table></div>';
?>

 

Basically, there are a couple of faults with this code. I didn't include the pagination part, but there is, for simplicity. But right now, when I insert a new record such as this:

INSERT INTO `images` VALUES (' ', 'blog', 'yo', '6', 'hello', '2011-02-15T07:24:17Z')

The columns go in order  of thumbnailID, folder, link, pic, alt, and time.^^^^^^^^

 

several problem arises. One, the new record is not displayed as the newest entry on my site. So the record is actually placed in one of the paginated pages. How can I reverse the order? The other thing is, it seems like my pic column is the only thing being understood. You see, when I inserted the above record, I checked my site and saw the pic 6, but the link wasn't 'yo', and the alt wasn't 'hello'. Why is that?

 

By the way, my host is awfully terrible. Maybe it's just having a major delay in reading the link and alt? I don't know. That would be the only reasonable answer, unless my code is off.

 

Thank you, and I'll check 10hours from now.

 

Link to comment
Share on other sites

the first thing i spotted is you are listed by ASC, so you want to change it to DESC, this will put the new image at the top.

 

there seems to be an awful lot of extra code that you dont really need.

 

why is $pic2 and $link1 and $alt1 all the same SQL command? (well you add ordering and paging to $pic2 but this is the only recordset you need)

 

give me a moment and Ill post a stripped out version for you

 

Link to comment
Share on other sites

<?php
	$objConnect = mysql_connect("localhost","","root") or die(mysql_error());
	$objDB = mysql_select_db("sdf");
	$pic2 = "SELECT * FROM images";
	if (!isset($_GET['Page']))	$_GET['Page']='0';
	$pic1 = mysql_query($pic2);
	$Num_Rows = mysql_num_rows($pic1);
	$Per_Page = 16;   // Per Page
	$Page = $_GET["Page"];
	if(!$_GET["Page"])
	{$Page=1;}
	$Prev_Page = $Page-1;
	$Next_Page = $Page+1;
	$Page_Start = (($Per_Page*$Page)-$Per_Page);
	if($Num_Rows<=$Per_Page)
	{$Num_Pages =1;}
	else if(($Num_Rows % $Per_Page)==0)
	{$Num_Pages =($Num_Rows/$Per_Page) ;}
	else
	{$Num_Pages =($Num_Rows/$Per_Page)+1;
		$Num_Pages = (int)$Num_Pages;}
	$pic2 .=" order  by thumbnailID ASC LIMIT $Page_Start , $Per_Page";
	$pic1  = mysql_query($pic2);
$cell = 0;

echo '
    <div id="tablediv">
      <table border="0" cellpadding="17" cellspacing="0" class="table">
        <tr>';

  while($pic = mysql_fetch_array($pic1)) {

    if($cell % 4 == 0) {
      echo '</tr><tr>';
    }

    if($cell == 2) {
      echo '
        <td>
          fillerspace
        </td>';
    } elseif ($cell == 3) {
      echo '
        <td>
Fillerspace2
        </td>';
    } else {
      echo '
        <td>
          <a href="/' . $pic["link"] . '.php">
            <div class="image">
              <img src="https://s3.amazonaws.com/image/' . $pic["pic"] . '.png" 
                   alt="' . $pic["alt"] . '" 
                   height="200" 
                   width="200" 
              />
            </div>
          </a>
        </td>'; 
    }
    $cell++;
  }
  echo '</tr></table></div>';
?>

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.