Jump to content

oha055

Members
  • Posts

    23
  • Joined

  • Last visited

    Never

Everything posted by oha055

  1. Nevermind! got it working! if(count($array) > 0)
  2. Hi! I have got an array which contains messages for different types of errors on my website (for login errors and such). My problem is however, that when the array is empty it still shows the message box (the CSS). here is the code I am using: public function showMessages() { if (count($this->_messages > 0)) { echo '<div id="messages">'; foreach ($this->_messages as $msg) { echo $msg . '<br />'; } echo '</div>'; } } I am starting to think that I need to be doing this in JavaScript. I would prefer to do it using PHP only, if it is possible though. Thanks for the help!
  3. Got it working! This is the code. I am new to PHP so feel free to comment if there are other, better ways of doing this private function showBlog() { $imageId = count($this->_filenames) - 1; if (isset($_GET['id'])) { $imageId = $_GET['id']; } ?> <center><img src="images/gallery/<?php echo $this->_filenames[$imageId]; ?>" /></center> <div id="navigation"> <div id="prev"> <a href="?id=<?php echo $imageId - 1; ?>">prev</a> </div> <div id="next"> <a href="?id=<?php echo $imageId + 1; ?>">next</a> </div> </div> <?php }
  4. Hi! I am currently making a really simple photo blog. The query fetches every reference to the images which are stored on the server. I have a problem when it comes to dynamically cycling through these though. After running the query, I store each image reference in a twodimensional array like this: [["id"], ["date"], ["title"], ["filename"]] (an Array of Arrays). The image displays just fine by doing this: $pointer; //starting from the last element (image) in the array <img src="images/gallery/<?php echo $images[3][$pointer] ?>" alt="<?php echo $images[2][$pointer] ?>"> The problem is that, when I update the pointer, say for instance pointer++, the current image on the screen doesnt update. I know for a fact that the pointer updates, because I have echoed it. The basic idea is to have a previous and next link just under the image, so that the viewer can cycle the available images. Any help is greatly appreciated
  5. Thank you for the quick reply. I'll just stick to headers then
  6. Hi! So I know that when redirecting to administrator pages after login is very often done like this: header(location:admin.php); But what if I didnt want to use header? I'm asking because I would just like to include the admin section within the part of the website I'm currently residing, if that makes any sense. Also, I think using headers is a bit cumbersome. I have just recently started learning PHP, so please excuse me if this is a dumb question
  7. Ok, thanks! I thought it could maybe work by only using php, but I guess not! I'll check out js then
  8. Hi! So I have got some code that looks like this: if (isset($_GET['view_log'])) { // show content (text from db) } When I click the button named "view_log" everything displays just fine, however I would like to be able to click the button again and make the content disappear. Is this possible using only PHP?? Thanks for the help! It is greatly appreciated!
  9. Thanks for the reply! ok, so any way I like. But do you think maybe this would be a bit overkill for a personal website? Also, do you know of any good books on CMS? Thanks!
  10. Hi! So I'm fairly new to PHP, and am currently making a website from scratch including as much PHP functionality as I can for learning purposes. As I have just finished making a blog function, I started to wonder. Is it normal to store every part of a website in a the database? The blog part of the website I just created has of course all the differet blog entries stored in a table in the db, but is it also normal practice to store about, contact etc. in tables too? Or should categories like these be created using brand new .php documents? I am in the progress of making a page controller and thought I should clearify things first, before I go any further. This question may seem stupid, but I don't know alot about what the normal practices of doing things like these in php are. Anyways, hope someone can help me out!
  11. Thanks to both of you! Much appreciated! I went for this solution: <?php $lines = explode('-', $text); array_shift($lines); foreach($lines as $line) { echo '*', $line, "<br />"; } ?>
  12. Hi! I have a problem when echoing some lines of an exploded string. The output of the code is: * [EMPRY LINE] * line with some writing #1 * line with some writing #2 * line with some writing #3 etc. I don't get why the first (empty) line is included.. <?php $lines = explode('-', $text); foreach($lines as $line) { echo '*', $line, "<br />"; } ?> any help is appreciated!
  13. Thank you! Btw, does anyone know of a good PHP book for learning about this topic? I'm looking at amazon.com and there are so many PHP books to choose from..
  14. Thank you! Yeah, I'm sure Google has got the answers, but I didn't know what to search for
  15. Hi! I am making a website from scratch to try to learn some basic PHP. Up untill recently I have made separate .php files for each part of my website (index.php, about.php, blog.php etc.) and just linked to these pages in HTML. I know there are better ways of doing this, so that I don't need to make as many separate pages. Something like just using PHP functionality to show different content on the same site, depending on which button is clicked. I don't want you to write any code for me, but if someone could point me in the right direction that would be great! . Any links to tutorials are also very welcome ! regards, Øyvind
  16. NEVERMIND! I got it working! You have been of great help! :D It works perfectly now.
  17. Well, that worked! ....The page displays fine now. Still doesn't jump to the next image in the result set though. When I click on the image, the address bar displays "http://localhost/photoblog/index.php?id=2", but the image doesn't actually change to image no. 2 Thank ou so much anyways
  18. Thank you so much for your reply! I tried out your suggestion, but now I am getting this error: "Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\photoblog\index.php on line 13" On this line: $result = $conn->query($sql) or die(mysqli_error()); Don't know what to make of this, there was no bitching about this before
  19. Hi! I want the image of my site to be clickable so that it shows the next image contained in the result set of the sql query. <?php require_once('includes/connection.inc.php'); $conn = dbConnect(); $sql = 'SELECT filename FROM images ORDER BY image_id DESC LIMIT 1'; $msg = ''; if(!$sql) { echo "Something went wrong with the query. Please try again."; } $result = $conn->query($sql) or die(mysqli_error()); if(mysqli_num_rows($result) == 0) { header('Location: empty_blog.php'); $conn->close(); } else { $row = $result->fetch_row(); $image = $row[0]; } ?> <?php include('header.php'); ?> <div class="content main"> <img id="image" src="images/<?php echo $image; ?>"/> </div> <?php include('includes/footer.inc.php'); ?> All the filenames of the images are contained correctly in the $result variable, all I need to do now is to fetch the next image in the set. How would I go about this? Any help is greatly appreciated!
  20. Hi, I have a problem regarding counting rows in a mysql table. Here is the code: <?php require_once('includes/connection.inc.php'); $conn = dbConnect('read'); $check = 'SELECT COUNT(*) FROM images'; $checkRes = $conn->query($check) or die(mysqli_error()); if($checkRes <= 0) { header('Location: empty_blog.php'); // redirect to another page } else { // do something else... } ?> The error I'm getting: "Notice: Object of class mysqli_result could not be converted to int in C:\xampp\htdocs\photoblog\index.php on line 6" Any help is greatly appreciated!
  21. Hi! I am new to PHP, and have got a problem when trying to insert some info into an sql table. $cat = 'architecture'; $fName = basename($_FILES['uploadedFile']['name']); // filename from image located locally on computer $capt = 'cool image'; require_once('includes/connection.inc.php'); $conn = dbConnect('write'); $sql = 'INSERT INTO images (category, filename, caption) VALUES ("'.$cat.', '.$fName.', '.$capt.'")'; $stmt = $conn->stmt_init(); $stmt = $conn->prepare($sql); $stmt->execute(); This is the error I'm getting: "Fatal error: Call to a member function execute() on a non-object in C:\xampp\htdocs\photoblog\upload.php on line 23" Must be something wrong with the SQL statement, I guess... Any help is greatly appreciated!
×
×
  • 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.