Jump to content

Album code issues


Recommended Posts

So I am a beginner at coding so bear with me on the quality of my code.I am trying to code a photo gallery and having some difficulties.I have two pages with the in includes:Photo.php - this one seems to work but could have some errors that are causing the second page to not work.

$con = mysql_connect("....t","...","...");if (!$con)  {  die('Could not connect: ' . mysql_error());  }mysql_select_db("...", $con);$result = mysql_query("SELECT * FROM photo_albums ORDER BY uptime DESC");while($row = mysql_fetch_array($result))  {  echo '<div class="photoThumb">';  echo '<a href="viewAlbum.php?aid='.$row['aid'].'"><img src="' . $row['filepath'];  echo $row['filename'] . '"';  echo 'border="0" /></a>';  echo '<br/>';  echo '<span class="thumbText"><a href="viewAlbum.php?aid='.$row['aid'].'">' . $row['stitle'];  echo  '</a><br/>';  echo $row['photog'];  echo '</span>';  echo "</div>";  }mysql_close($con);

Next Page:viewAlbum.php - This on is the one that is not working properly. I cannot seem to get the page to call on the AID number from the thumbnail the user clicked on before. I can, although, manually type it in and make it display one album.

$con = mysql_connect("...","...","...");if (!$con)  {  die('Could not connect: ' . mysql_error());  }mysql_select_db("...", $con);$result = mysql_query("SELECT *FROM `pictures` WHERE `aid` = 1 ORDER BY `pid` ASC");while($row = mysql_fetch_array($result))  {  echo '<div class="photoThumb">';  echo '<a href="';  echo $row['filepath'];  echo $row['filename'];  echo '"><img src="';  echo $row['filepath'];  echo $row['filename'];  echo '" rel="lightbox[' .$row['aid'];  echo ']" border="0" width="100px" /></a><br/>';  echo "</div>";  }mysql_close($con);

Does anyone have any suggestions on how I fix this. My lightbox also does not seem to work if anyone also has any suggestions on that.Thanks for you time,Brian

Link to post
Share on other sites

The only problem I see is that you don't have single-quotes on your aid number.$result = mysql_query("SELECT * FROM `pictures` WHERE `aid` = '1' ORDER BY `pid` ASC");Also, it would help if you turned on error reporting to get a list of all the errors /warnings you get. It really does help a lot.

Edited by RahXephon
Link to post
Share on other sites
$result = mysql_query("SELECT * FROM `pictures` WHERE `aid` = '1' ORDER BY `pid` ASC");
Well that is the problem itself. I manually typed in that number 1. I dont want to manually type it in. I want to figure out how to get php to input the aid number in itself. As of right now I have three albums, aid: 1,2,3. No matter what I click on it shows the photos for album 1, aid:1.How would I fix that?
Link to post
Share on other sites

You can use get variables.You can put a link say: index.php?aid=1When clicked, the next page in the code would have:$aid = $_GET['aid'];This assigns whatever number to the $aid variable. In this case, 1.You can then assign it to the SQL statement. Like so:$result = mysql_query("SELECT * FROM `pictures` WHERE `aid` = '$aid' ORDER BY `pid` ASC");

Edited by RahXephon
Link to post
Share on other sites

That is pretty much how I have it set up but with different page names.I used the $aid = $_GET['aid']; but I cant tell you if it is doing its job because its giving me error messages in other parts of my code. Here is my new code

$aid = $_GET['aid'];$result = mysql_query("SELECT * FROM photo_albums ORDER BY uptime DESC");while($row = mysql_fetch_array($result))  {echo "<div class='photoThumb'>";echo "<a href='viewAlbum.php?aid='$row['aid']'>";echo "<img src='$row['filepath']$row['filename']' border='0' />";echo "</a><br/><span class='thumbText'>";echo "<a href='viewAlbum.php?aid='$row['aid']'>$row['stitle']</a><br/>";echo "$row['photog']</span></div>";}mysql_close($con); ?>

Still having issues..

Link to post
Share on other sites

"<a href='viewAlbum.php?aid='$row['aid']'>$row['stitle']</a>"When working with associative arrays, you will have to put them in { } or concatenate them with the string."<a href='viewAlbum.php?aid={$row['aid']}'>{$row['stitle']}</a>"OR"<a href='viewAlbum.php?aid=" .$row['aid']. "'>". $row['stitle'] ." </a>"Also, if you don't know what $aid is. Print it directly to the screen to see the value. var_dump() works great for that.

Edited by RahXephon
Link to post
Share on other sites

That means that your string length is equal to zero. The qoutation marks displaying will display any string the variable has. It should of displayed "1" or whatever number you put. In other words, it's saying there's nothing in the $aid variable. It's empty. Let's see the updated code on the page before this. Are you still getting errors there?

Edited by RahXephon
Link to post
Share on other sites

I ended up resorting back to my old code because it worked fine... Some other people changed it all around and it never worked so this is what I currently have.

$result = mysql_query("SELECT * FROM photo_albums ORDER BY uptime DESC");while($row = mysql_fetch_array($result))  {  echo '<div class="photoThumb">';  echo '<a href="viewAlbum.php?aid='.$row['aid'].'"><img src="' . $row['filepath'];  echo $row['filename'] . '"';  echo 'border="0" /></a>';  echo '<br/>';  echo '<span class="thumbText"><a href="viewAlbum.php?aid='.$row['aid'].'">' . $row['stitle'];  echo  '</a><br/>';  echo $row['photog'];  echo '</span>';  echo "</div>";  }mysql_close($con);

Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...