Jump to content

gleamthecube

Members
  • Posts

    16
  • Joined

  • Last visited

    Never

Everything posted by gleamthecube

  1. One more question. What condition would I use to determine if the query brings up nothing. Say there are 100 pictures in a gallery, and I'm at page 10, what condition would my if statement have to test to know that there isn't any images on page 11?
  2. The thing is, is that there are multiple galleries with different number of pictures. Also, pictures can be added or deleted from each gallery, so they're always going to change in size. Is there some sort of way to know the number of items you query so that I could use that as some kind of condition for how many times you should do that?
  3. This isn't completely a php question but here it is: So I can load images onto a page with no problem, but I'm dealing with a lot of images. Right now my php code loads certain images into an unordered list on a page. function getPhotos($select_album) { $q = 'SELECT id, src, tn_src FROM photo WHERE album_id="' . $select_album . '/" ORDER BY id desc'; $result = mysql_query($q) or die("Error with query"); if($result) { while($row = mysql_fetch_object($result)) { $tn_src = $row->tn_src; $src = $row->src; $id = $row->id; print '<li> <a href="backend/' . $src . '"> <img src="backend/' . $tn_src . '" /> </a> </li>'; print "\n"; } } } That works fine. My question is, is if there is a way with php to only view, say, 10 items at a time and be able to navigate through pages of them? I've thought about doing something with jquery, but all the premade gallery programs I find won't work. I'm working with a limited amount of space. (900px X 1200px) So what I would need is just thumbnails of 10 or 20 pictures and then when clicked they launch a lightbox. Is there anything out there that can do that? Or how would I write the code to organize a lot of thumbnails into a multiple page gallery?
  4. I changed it to: $q = 'SELECT id, tn_src, src, sc_src FROM photo WHERE album_id="' . $arr["galleries"][$count] . '/" ORDER BY id desc'; and it worked, but how the hell do you line break when writing to a file?!? ???
  5. The database only has one object in it right now under album_id="birthday/", so all the XML files contain only: <gallery></gallery> Seeing that birthday has something in it, it's XML file contains: <gallery><image title=\"\" main=\"\" thumb=\"\"/> \n</gallery>
  6. Ok, building on to this problem, I tried to write up a little script to update each of my XML files that my SWF's read. I get the errors: PHP Notice: Undefined property: stdClass::$tn_src in D:\inetpub\wwwroot\membershipsite\updatexml.php on line 16 PHP Notice: Undefined property: stdClass::$src in D:\inetpub\wwwroot\membershipsite\updatexml.php on line 17 PHP Notice: Undefined property: stdClass::$sc_src in D:\inetpub\wwwroot\membershipsite\updatexml.php on line 18 From this code: <?php require 'database.php'; $arr = array("galleries" => array(0 => 'baby', 1 => 'birthday', 2 => 'bridal', 3 => 'childrens', 4 => 'cookies' , 5 => 'cupcakes', 6 => 'sculpted', 7 => 'wedding')); $count = 0; while($count < //There's probably an easier way to do this... { $q = 'SELECT id FROM photo WHERE album_id="' . $arr["galleries"][$count] . '/" ORDER BY id desc'; $result = $mysqli->query($q) or die($mysqli_error($mysqli)); $myFile = 'xml/' . $arr["galleries"][$count] . '.xml'; $fh = fopen($myFile, 'w') or die("can't open file"); if($result) { fwrite($fh, "<gallery>\n"); while($row = $result->fetch_object()) { $tn_src = $row->tn_src; $src = $row->src; $sc_src = $row->sc_src; fwrite($fh, '<image title=\"'. $src . '\" main=\"' . $sc_src . '\" thumb=\"' . $tn_src . '\"/> \n'); } fwrite($fh, "</gallery>"); } $count++; } fclose($fh); header("location: index.php"); ?> This is a page I will call to update all XML files once a user is done editing each gallery. Any idea of what's going on, anyone?
  7. And how would I go about getting the next 30 after that?
  8. Now all I have to do is be able to list only, say, the current 30 images in a directory and be able to cycle through them 30 at a time. I'll get back to you in this thread if that gives me any trouble. Thank you! p.s. You wouldn't know an easy way to do that?
  9. No matter what way I do it, it won't work. :-\ I tried it the way you explain and it wouldn't work, and now I'm trying: <ul><?php getPhotos($_REQUEST['album']); ?></ul> and... function getPhotos($select_album) { $q = 'SELECT id, tn_src FROM photo WHERE album_id="' . $select_album . '/" ORDER BY id desc'; No matter what I write into the url $q is equal to: SELECT id, tn_src FROM photo WHERE album_id="/" ORDER BY id desc Now I'm really confused!
  10. This ( $album_id = addslashes('D1'); ) is supposed to be ( $album_id = addslashes($_POST['D1']); ). I changed that after I posted the first post in this thread. So I believe a post? Is there a different way to do this? And I can't get any albums to display no matter what is after ?album_id= Oh, I saw that Addslashes('D1') and I was wondering.. It seems like your problem is that you're using (or trying) to use the same variable to get the album_id to place in the database, and to select from the database. Rather than that you should try something like this: $select_album = $_REQUEST['album']; $_REQUEST means that it's coming directly from the URL, now you'll pass $select_Album to the getPhotos() function. You'll keep the $album_id = addslashes($_POST['D1']) because that's the variable that will be used to upload images. That makes a lot of sense. I'm still kinda foggy on where to declare that variable, or how I would construct that string. Should I include the '/' in the url? Or just drop it and use: $q = 'SELECT id, tn_src FROM photo WHERE album_id="' . $select_album .'/" ORDER BY id desc'; Is that even correct? I still can't get it to work. >
  11. This ( $album_id = addslashes('D1'); ) is supposed to be ( $album_id = addslashes($_POST['D1']); ). I changed that after I posted the first post in this thread. So I believe a post? Is there a different way to do this? And I can't get any albums to display no matter what is after ?album_id=
  12. Nope, that's exactly correct. Php and C++ have many differences, but many similarities as well. $album_id would most likely be a request variable, depending on how you're doing it. (eg. gallery.php?album=something) Thanks so far, it's working a little better now, but this just got a little more confusing. I kinda see what's happening, I think. Say I upload a picture into the album "birthday/", upon upload everything works fine, it gets resized, but it doesn't show up. Am I right when I say that the variable was empty when the page first loaded, so nothing was loaded from the database, then when I uploaded the image the variable was only sent to the upload function, and when the page was refreshed it was empty again? That's what seems to be happening, because I can select one of the galleries from the drop down menu and press upload and it will bring up the corresponding images. I see what you mean by calling, in my case, index.php?album_id=something, but say when I upload to "birthday/" do I write index.php?album_id=birthday/ , because that doesn't work. Still a little confused on what you're saying isn't working :s When uploading album_id is set correctly in the database, correct? It should differ depending on what they selected from the drop down. Then you'd goto index.php?album_id=whatever, so that it would select the images from the DB, again, I'm a bit confused in what you're asking. Files get uploaded and the database gets updated, but upon returning the index.php there is nothing in the section where thumbnails are supposed to be. I see that you have to add ?album_id=something to the end of index.php to get the correct gallery to appear upon reload, but I don't know what to put after it. I tried ?album_id=birthday/ but that doesn't work. The '/' is part of the string for album_id. I can get an album to display if I just select something from the drop down menu, but not choose a file, and click upload. It doesn't upload anything, it just refreshes the page, but with the album I choose being viewed. That's what's confusing me.
  13. Nope, that's exactly correct. Php and C++ have many differences, but many similarities as well. $album_id would most likely be a request variable, depending on how you're doing it. (eg. gallery.php?album=something) Thanks so far, it's working a little better now, but this just got a little more confusing. I kinda see what's happening, I think. Say I upload a picture into the album "birthday/", upon upload everything works fine, it gets resized, but it doesn't show up. Am I right when I say that the variable was empty when the page first loaded, so nothing was loaded from the database, then when I uploaded the image the variable was only sent to the upload function, and when the page was refreshed it was empty again? That's what seems to be happening, because I can select one of the galleries from the drop down menu and press upload and it will bring up the corresponding images. I see what you mean by calling, in my case, index.php?album_id=something, but say when I upload to "birthday/" do I write index.php?album_id=birthday/ , because that doesn't work.
  14. Exactly, I did that earlier, but I still couldn't figure out a way to have a certain gallery load. Is there a way to call the page to refresh but with that value to be sent to that function? Should I pass it like: <ul><?php getPhotos($album_id); ?></ul> Or am I stuck in c++ world? Forgive me, this is like my third day with php.
  15. Hello new forum I joined out of despair! Ok, so I'm not a web developer by any means, I'm in school for information systems and have a decent background in c++ and a few other languages, so while waiting on a client I freelanced through a friend, to make a site for, I'm trying to learn a little PHP. In the actual site, I use ActionScript to load information on images from an XML document into individual galleries. I noticed that this forum has a website critique part so I might put it in there when I'm done, but I think that's more for PHP, which the portion I've made doesn't include. You can see it where I've temporarily put it, if you want to, here: http://cupcakes.50webs.com That all works fine, but out of boredom I wanted to see if I could create some sort of backend administrative portion to the site, so my client could log in and update which photos are in which galleries. I found a couple good tutorials on the majority of what I'm trying to learn and went with those. And that's when I encountered the dead end I'm at right now. Here's my paradigm: I've got the login part working fine, I can load the images from my database, and also save them to their corresponding locations with a drop down menu, but what I want to be able to do is display which images are in which gallery set. Here is the index page: <?php require_once 'classes/Membership.php'; $membership = New Membership(); $membership->confirm_Member(); require 'config.php'; require 'functions.php'; require 'database.php'; if(isset($_FILES['fupload'])) { $filename = addslashes($_FILES['fupload']['name']); $source = $_FILES['fupload']['tmp_name']; $album_id = addslashes('D1'); $target = $path_to_image_directory . $album_id . $filename; $src = $path_to_image_directory . $album_id . $filename; $tn_src = $path_to_thumbs_directory . $album_id . $filename; if($filename == '' || !preg_match('/[.](jpg)|(gif)|(png)|(jpeg)|(JPG)|(GIF)|(PNG)|(JPEG)$/', $filename)) $error['no_file'] = '<p class="alert">Invalid file type, or no file to upload. </p>'; if(!$error) { move_uploaded_file($source, $target); $q = "INSERT into photo(src, tn_src, album_id) VALUES('$src', '$tn_src', '$album_id')"; $result = $mysqli->query($q) or die(mysqli_error($mysqli)); //This part resizes the initial image so it will fit on a window in LightBox (550px) if(preg_match('/[.]jpg$/', $filename)) { $imf = imagecreatefromjpeg($target); } else if (preg_match('/[.]JPG$/', $filename)){ $imf = imagecreatefromJPEG($target); } else if (preg_match('/[.]gif$/', $filename)) { $imf = imagecreatefromgif($target); } else if (preg_match('/[.]png$/', $filename)) { $imf = imagecreatefrompng($target); } $oxf = imagesx($imf); $oyf = imagesy($imf); $nyf = 550; $nxf = floor($oxf * (550 / $oyf)); $nmf = imagecreatetruecolor($nxf, $nyf); imagecopyresized($nmf, $imf, 0,0,0,0,$nxf,$nyf,$oxf,$oyf); if(!file_exists($path_to_image_directory . $album_id)) { if(!mkdir($path_to_image_directory . $album_id)) { die("There was a problem."); } } imagejpeg($nmf, $path_to_image_directory . $album_id . $filename); //This creates two more images for a thumbnail and a smaller image to be used in the swf. //Go look at the website above to see what I'm talking about. createThumbnail($filename, $album_id); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" href="css/default.css" /> <title>My Photos</title> </head> <body> <h1>My Photos</h1> <ul><?php getPhotos(); ?></ul> <h1>Upload a Photo</h1> <form enctype="multipart/form-data" method="post" action="index.php"> <p><input type="file" name="fupload" /></p> <select size="1" id="D1" name="D1"> <option selected>Select album type</option> <option value="birthday/" href="index.php">Birthday</option> <option value="childrens/">Childrens Cakes</option> <option value="cookies/">Custom Cookies</option> <option value="cupcakes/">Custom Cupcakes</option> <option value="baby/">For Baby</option> <option value="bridal/">For Bridal</option> <option value="sculpted/">Sculpted and Shaped</option> <option value="wedding/">Wedding Cakes</option> </select> </p> <p><input type="submit" value="Upload Photo" name="submit" /></p> </form> <p><strong>Files must be under 1mb</p> <br /> <a href="login.php?status=loggedout">Log Out</a> </body> </html> The upload option works fine, everything gets resized and sent to its right place. Here is the functions page, where I believe my problem is: <?php // This is what I want to change, I think, so that mysql will only load images from a selected gallery type. // How I would go about doing that, I have no idea! Help! function getPhotos() { require 'database.php'; $q = "SELECT id, tn_src FROM photo ORDER BY id desc"; $result = $mysqli->query($q) or die($mysqli_error($mysqli)); if($result) { while($row = $result->fetch_object()) { $tn_src = $row->tn_src; $src = $row->src; $id = $row->id; print '<li> <a href="review_image.php?id=' . $id . '"> <img src="' . $tn_src . '" alt="images" id="' . $id . '" /> </a> </li>'; print "\n"; } } } function getDeletePhotos() { require 'database.php'; $q = "SELECT id, tn_src FROM photo ORDER BY id desc"; $result = $mysqli->query($q) or die($mysqli_error($mysqli)); if($result) { while($row = $result->fetch_object()) { $tn_src = $row->tn_src; $src = $row->src; $id = $row->id; print '<li><img src="' . $tn_src . '" alt="images" id="' . $id . '" /></li>'; print "\n"; } } } function getChosenPhoto($the_selected_id) { require 'database.php'; $id = $the_selected_id; $q = "SELECT src FROM photo Where id = $id LIMIT 1"; $result = $mysqli->query($q) or die("there was a problem"); if($result) { while ($row = $result->fetch_object()) { echo '<img src="' . $row->src . '" alt="image" /><br />'; echo '<p id="src">' . $row->src . '</p>'; } } else die("There was some problem"); } // This function resizes two images described earlier. function createThumbnail($filename, $album_id) { require 'config.php'; if(preg_match('/[.]jpg$/', $filename)) { $ims = imagecreatefromjpeg($path_to_image_directory . $album_id . $filename); $imt = imagecreatefromjpeg($path_to_image_directory . $album_id . $filename); } else if (preg_match('/[.]JPG$/', $filename)){ $ims = imagecreatefromJPEG($path_to_image_directory . $album_id . $filename); $imt = imagecreatefromJPEG($path_to_image_directory . $album_id . $filename); } else if (preg_match('/[.]gif$/', $filename)) { $ims = imagecreatefromgif($path_to_image_directory . $album_id . $filename); $imt = imagecreatefromgif($path_to_image_directory . $album_id . $filename); } else if (preg_match('/[.]png$/', $filename)) { $ims = imagecreatefrompng($path_to_image_directory . $album_id . $filename); $imt = imagecreatefrompng($path_to_image_directory . $album_id . $filename); } $oxs = imagesx($ims); $oys = imagesy($ims); $oxt = imagesx($imt); $oyt = imagesy($imt); $nys = 300; $nxs = floor($oxs * (300 / $oys)); $nxt = 50; $nyt = floor($oyt * (50 / $oxt)); $nms = imagecreatetruecolor($nxs, $nys); $nmt = imagecreatetruecolor($nxt, $nyt); imagecopyresized($nms, $ims, 0,0,0,0,$nxs,$nys,$oxs,$oys); imagecopyresized($nmt, $imt, 0,0,0,0,$nxt,$nyt,$oxt,$oyt); if(!file_exists($path_to_scaled_directory . $album_id)) { if(!mkdir($path_to_scaled_directory . $album_id)) { die("There was a problem."); } } if(!file_exists($path_to_thumbs_directory . $album_id)) { if(!mkdir($path_to_thumbs_directory . $album_id)) { die("There was a problem."); } } imagejpeg($nms, $path_to_scaled_directory . $album_id . $filename); imagejpeg($nmt, $path_to_thumbs_directory . $album_id . $filename); header("location: index.php"); } ?> Config.php has this in it: <?php $path_to_image_directory = 'images/'; $path_to_thumbs_directory = 'images/tn/'; $path_to_scaled_directory = 'images/scaled/'; ?> And database.php has this: <?php $db_name = "myPhotos"; $db_server = "localhost"; $db_user = "root"; $db_pass = ""; $mysqli = new MySQLi($db_server, $db_user, $db_pass, $db_name) or die(mysqli_error()); ?> I really hope someone can help me with this, not because I need to have it done, I just want to know what I'm doing wrong. ??? ??? ??? ??? Edit: I attached a zip of the whole thing. [attachment deleted by admin]
×
×
  • 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.