Jump to content

php_beginner_83

Members
  • Posts

    89
  • Joined

  • Last visited

    Never

Everything posted by php_beginner_83

  1. Hi I'm trying to create an online photo gallery and I'm pretty new to php. My problem is when I try and search my database. When I use the following code.. $result = mysql_query("SELECT * FROM Images INNER JOIN Images_In_Album ON Images.ID = Images_In_Album.PicID INNER JOIN Albums ON Images_In_Album.AlbumID = Albums.ID WHERE Albums.ID = 1"); I get all the photos in the album with ID = 1. So when I click my 'Next' link to browse through the pics they are all there. However, when I use this code... $result = mysql_query("SELECT * FROM Images INNER JOIN Images_In_Album ON Images.ID = Images_In_Album.PicID INNER JOIN Albums ON Images_In_Album.AlbumID = Albums.ID WHERE Albums.ID = \"$albumID\""); Only the first picture is there. When I click the 'Next' link, the wee box with the red cross in it appears. Do you have any idea why this happens and how I can fix it?? This is my complete code... $albumID comes from the previous page and changes depending on which photo album the user has clicked. <?php $username = "root"; $password = ""; $hostname = "localhost"; //connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); //echo "Connected to MySQL<br>"; $selected = mysql_select_db("MyWebsite",$dbhandle) or die("Could not select examples"); //code here to determine what link has been clicked. $albumID = $_GET['ID']; //sql query to get records from that album. $result = mysql_query("SELECT * FROM Images INNER JOIN Images_In_Album ON Images.ID = Images_In_Album.PicID INNER JOIN Albums ON Images_In_Album.AlbumID = Albums.ID WHERE Albums.ID = \"$albumID\""); //arrays to hold the titles, descriptions and paths separately $titles = array(); $descriptions = array(); $paths = array(); $counter = 0; //fetch tha data from the database while ($row = mysql_fetch_array($result)) { $titles[$counter] = $row['Title']; $descriptions[$counter] = $row['Description']; $paths[$counter] = substr(strrchr($row['Path'],92),1); $counter++; } $imgIndex = $_GET['img']; if(!isset($paths[$imgIndex])) { $imgIndex = 0; } $currentImage = "images\\" . $paths[$imgIndex]; if ($imgIndex<=0) { $prev = "Previous"; } else { $prev = "<a href=\"".$_SERVER['SCRIPT_NAME']."?page=photo&img=".($imgIndex-1)."\">Previous</a>"; } if ($imgIndex>=(count($paths)-1)) { $next = "Next"; } else { $next = "<a href=\"".$_SERVER['SCRIPT_NAME']."?page=photo&img=".($imgIndex+1)."\">Next</a>"; } echo " albumID " . $albumID; echo "<pre>$prev $next</pre><br>"; echo "<div id='photoBody'></br><h2>$titles[$imgIndex]</h2>"; echo "<img src=\"{$currentImage}\"></br></br>"; echo "<p>$descriptions[$imgIndex]</p></div>"; mysql_close($dbhandle); ?> Thank you.
  2. Hi I need some advice about the best way to go about something. I'm creating a website to display my photos. On one of my pages, at the top, I'm displaying my photo albums. This consists of a thumbnail and the name of the album. On the lower part of my page is going to be the photo gallery, where the user can browse through the pictures of the album they have just selected. So my problem is, when a user clicks an album how to requery my database so I can search for the pics in the album just selected. Currently, I have it as two separate pages. On the first page are the albums. When the user clicks on the name of the album (which is a link) another pages opens, the photo gallery, which displays the pictures one at a time from the album selected and the user can browse through these using next and previous buttons. To put these both on one page should I use a form and a button. Use the button where the link (Album title) used to be so now when the user clicks on the buttons (Album titles), I can run a different mysql query to return the pictures from that album. I'm new at php and mysql and was wondering if this way is doable or is there a better way to do it. This is the code that displays the photo albums.. <?php $username = "root"; $password = ""; $hostname = "localhost"; //connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); //echo "Connected to MySQL<br>"; $selected = mysql_select_db("MyWebsite",$dbhandle) or die("Could not select examples"); $result = mysql_query("SELECT * FROM albums WHERE Place=2"); $row = mysql_fetch_array($result); echo "<table border='0' cellspacing='50'>"; $title = $row['Title']; $table1 = "<td><a href=DatabaseConnection.php?link=$title>" . $row['Title'] . "</a></td>" . $table1; $thumb = "images\\" . $row['AlbumCover']; $table2 = "<td><img src=\"$thumb\"></td>" . $table2; $table3 = "<td>" . $row['Description'] . "</td>" . $table3; echo "<td><a href=DatabaseConnection.php?link=$title>" . $row['Title'] . "</a><br/><br/><img src=\"$thumb\"><br/><br/>" . $row['Description'] . "</td>"; while($row = mysql_fetch_array( $result )) { $title = $row['Title']; $table1 = "<td><a href=DatabaseConnection.php?link=$title>" . $row['Title'] . "</a></td>" . $table1; $thumb = "images\\" . $row['AlbumCover']; echo "thumb " .$thumb; $table2 = "<td><img src=\"$thumb\"></td>" . $table2; $table3 = "<td>" . $row['Description'] . "</td>" . $table3; echo "<td><a href=DatabaseConnection.php?link=$title>" . $row['Title'] . "</a><br/><br/><img src=\"$thumb\"><br/><br/>" . $row['Description'] . "</td>"; } echo "</table>"; ?> And this is my code that'll show the pictures from the selected photo album... <?php $username = "root"; $password = ""; $hostname = "localhost"; //connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); //echo "Connected to MySQL<br>"; $selected = mysql_select_db("MyWebsite",$dbhandle) or die("Could not select examples"); //code here to determine what link has been clicked. $getValue = $_GET['link']; //sql query to get records from that album. $result = mysql_query("SELECT * FROM Images INNER JOIN Images_In_Album ON Images.ID = Images_In_Album.PicID INNER JOIN Albums ON Images_In_Album.AlbumID = Albums.ID WHERE Albums.Title = \"$getValue\""); //arrays to hold the titles, descriptions and paths separately $titles = array(); $descriptions = array(); $paths = array(); $counter = 0; //fetch tha data from the database while ($row = mysql_fetch_array($result)) { $titles[$counter] = $row['Title']; $descriptions[$counter] = $row['Description']; $paths[$counter] = substr(strrchr($row['Path'],92),1); $counter++; } $imgIndex = $_GET['img']; if(!isset($paths[$imgIndex])) { $imgIndex = 0; } $currentImage = $paths[$imgIndex]; if ($imgIndex<=0) { $prev = "Previous"; } else { $prev = "<a href=\"".$_SERVER['SCRIPT_NAME']."?page=photo&img=".($imgIndex-1)."\">Previous</a>"; } if ($imgIndex>=(count($paths)-1)) { $next = "Next"; } else { $next = "<a href=\"".$_SERVER['SCRIPT_NAME']."?page=photo&img=".($imgIndex+1)."\">Next</a>"; } echo "<pre>$prev $next</pre><br>"; echo "<div id='photoBody'></br><h2>$titles[$imgIndex]</h2>"; echo "<img src=\"{$currentImage}\"></br></br>"; echo "<p>$descriptions[$imgIndex]</p></div>"; mysql_close($dbhandle); ?>
  3. Forget my last post there, I've got it working the way I want. Thanks everyone that lended me some help and advice.
  4. Thanks Andy-H for your help, that worked great. There's just one problem I'm not sure how to deal with. When I click on the 'San Francisco' link shown in screen1.jpg, screen2.jpg opens and automatically displays the photo albums. I was hoping that when screen2 opens the content would be blank coz I later want to add a intro there and then when the user clicks on 'Photos' on the menu bar, then the photo albums of San Francisco would be displayed. Then I would be able to do this for all my options in the menu bar. For example, when a user clicks 'San Francisco' from screen1, screen2 opens a intro will appear (a separate html file) and then when a user clicks on 'Photos' from the menu bar, San Francisco photo albums will appear, when a user clicks 'Sights' from the menu bar a list of sights or info about sights in San Francisco will appear. I'm sorry I should of made myself more clear. I really appreciate your help.
  5. Thanks everyone who posted constructive comments. I understand that I didn't explain my problem very well, I find it hard to do without talking to someone face to face. I've made a much better attempt this time. I've attached 2 screen shots (sorry I dont have the website up and working yet so cant provide a link)to try and explain what I'm trying to do. I'm hoping this will make sense. screen1.jpg is my web page where the user can select which city they want to view. At the minute i have my website set up so that when a user clicks on one of the links, eg. San Francisco, this is the code. <?php echo "<a href=America1.php?place=sanfrancisco>"; ?><h3>San Francisco</h3></a> The full code behind screen1.jpg is.... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Language" content="zh"> <title>My Travel Website</title> <link href="americanStyle.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="americaHeader"> <div id="logo"> <h1><a href="#">My American Adventures</a></h1> </div> </div> <div id="menu"> <ul> <li><a href="#">Home</a></li> <li><a href="#">America</a></li> <li><a href="#">Europe</a></li> <li><a href="#">Asia</a></li> </ul> </div> <div id="page"> <div id="content"> <div id="piclinks"> <table border="0" cellpadding="5" width="300"> <tr> <td><img src="images/sanFranThumb.jpg" align="middle"/></td> <td><?php echo "<a href=America1.php?place=sanfrancisco>"; ?><h3>San Francisco</h3></a> </td> </tr> <tr> <td><img src="images/memphisThumb.jpg" align="middle"/></td> <td><a href="#"><h3>Memphis</h3></a> </td> </tr> <tr> <td><img src="images/nashvilleThumb.jpg" align="middle"/> </td> <td><a href="#"><h3>Nashville</h3></a></td> </tr> <tr> <td><img src="images/newyorkThumb.jpg" align="middle"/></td> <td><a href="#"><h3>New York</h3></a></td> </tr> </table> </div> </div> </div> </div> </body> </html> When the link is clicked, another page will open. This is screen2.jpg that I've attached. So I'm trying to pass the name of the city that has been selected previously to this page so I can display the appropriate info. So now on this page, say for example San Francisco was selected, when the user clicks on 'Photos' on the menu only photo albums (stored in a database) from San Francisco will be displayed. On this page I was trying to display, for example the Photos, in the content section of the page rather than a new webpage, that's why I was using the Include. So the value that had been passed from screen1 I was trying to use to get, for e.g. San Franciscos, photo albums. Searching the database on this value. <?php echo"<a href=America1.php?page=main>"; ?>Photos</a> When the user clicks this on the menu then from the code below the photos would be displayed in the content section. This was the only way I could get this to work, by doing it this way. $index = array( "main" => "DisplayAlbums.php?title=$getValue" , "photo" => "DatabaseConnectionBackup.php" ); if ( !empty( $_GET["page"] ) ) { $page = $_GET["page"]; if ( array_key_exists( $page , $index ) ) include( $index[$page] ); My intentions were then when I tried to call 'DisplayAlbums.php' to show the photo albums in the content section, to pass $getValue which would store the city that the user had selected to view. And from DisplayAlbums.php then I could search my database on this value. The code between screen2 is..... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Language" content="zh"> <?php $getValue = $_GET['place']; ?> <title>My Travel Website</title> <link href="americanStyle.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="americaHeader"> <div id="logo"> <h1><a href="#">My American Adventures</a></h1> </div> </div> <div id="menu"> <ul> <li><a href="#">Home</a></li> <li><?php echo"<a href=America1.php?page=main>"; ?>Photos</a></li> <li><a href="#">Sights</a></li> <li><a href="#">Dos & Donts</a></li> </ul> </div> <div id="page"> <div id="content"> <?php // build an array for the pages you have. $index = array( "main" => "DisplayAlbums.php?title=San" , "photo" => "DatabaseConnectionBackup.php" ); if ( !empty( $_GET["page"] ) ) { $page = $_GET["page"]; if ( array_key_exists( $page , $index ) ) include( $index[$page] ); ?> </div> </div> </div> </body> </html> Also to lonewolf, I tried your suggestion ... and this was the result... Array ( ) I'm still very new to php and trying to find my way, so I know that I'm probably doing this all wrong. I would appreciate any suggestions or ideas you would have to make this work. I'm sure there's a much better way than what I'm trying. Thank you. [attachment deleted by admin]
  6. Hi I'm trying to pass values between web pages using php and have come across a problem. On the first page, when a user clicks on the 'Photos' link, I want the photo albums to display in the content section of the page. To make sure the correct albums are displayed I want to pass a value to search the database where my photos are stored. The value I want to search the database on is passed from a previous web page. This value is $getValue. Is the way I'm doing this wrong????? This is the code for this page.. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <<?php $getValue = $_GET['place']; ?> <title>My Travel Website</title> <link href="americanStyle.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="americaHeader"> ......... </div> <div id="menu"> <ul> <li><a href="#">Home</a></li> <li><?php echo"<a href=America1.php?page=main>"; ?>Photos</a></li> <li><a href="#">Sights</a></li> <li><a href="#">Dos & Donts</a></li> </ul> </div> <div id="page"> <div id="content"> <?php $index = array( "main" => "DisplayAlbums.php?title=$getValue" , "photo" => "DatabaseConnectionBackup.php" ); if ( !empty( $_GET["page"] ) ) { $page = $_GET["page"]; if ( array_key_exists( $page , $index ) ) include( $index[$page] ); ?> </div> </div> </div> </body> </html> Thank you.
  7. Hi All At the minute I am trying to create a database driven photo gallery. I have one page that will display the photo albums. I display the album title, the albums cover picture and a brief description of the album. From here I want to create a link using the album title. When the user clicks this link, a gallery will open where users can view the pictures from the selected album. The problem I have is when a user clicks the link. I'm not entirely sure how to do this. My idea was to have the link open a php file and in this php file determine which link had been clicked. Depending on which link, there would be a number of functions. A different function for every photo album. Having figured out which link was clicked, the appropriate function would be called. In this function, I would query the database and only return the pictures that belong to the album that was selected by the user. Is this a suitable way to do this? And if it is I dont know how I would determine which link was clicked by the user. I would appreciate any help and advice. Thank you.
  8. Hi All I'm currently trying to develop a database driven photo gallery. So far I have it working and displaying images no problem. The next step I want to take is to create seperate photo albums, e.g an album with my Christmas photos, another for holiday photos etc. The idea I had was in the table in my database to include 2 additional fields, one to record the name of the album the photo belongs to and another to indicate whether that picture is the cover photo of the album. Then I could use a MySQL query to get all the photos that belong to the albums and get the cover picture. On my webpage, I would like to display the cover picture with the name of the album beneath it and when the user clicks the name of the album, a page will open displaying the contents of the selected album. I would like your opinion of my way of thinking. Do you think it is a good way to do this or do you have a more simple idea. I would really appreciate any advice you have to give. Thank you.
  9. I read that tutorial and it doesn't really help me. It gives an example and talks through it but that's it and I seem to be doing something pretty similar. I need help with my code. Can you see anything that's wrong with it. I appreciate the help.
  10. Hi All Can anyone help me with this..please. I'm still pretty new to PHP and am slowly figuring it out. I have a photo gallery, that you can navigate through the pics to view each one using 'Next' and 'Previous' links. I want to include this in a website I'm creating. On the website's main page I have a menu. On the menu is the option to select 'Photos'. When you select this, the file that creates the photo gallery is included. However, when I click the 'Next' link to move through the photos, it disappears. Can anyone explain to me why this happens and how I can fix it. Thanks much. My website code is.... <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="sclMenu.js"></script> <style type="text/css"> // css styles here </style> </head> <body bgcolor="#000000"> <div id="header"> <img src="Banner_USA.jpg" alt="header image"> </div> <div id="menuNav" > <ul id="dd"> <li><a href="#" class="menu" id="mmenu1" onmouseover="mopen(1);" onmouseout="mclosetime();">Home</a> <div class="submenu" id="menu1" onmouseover="mcancelclosetime()" onmouseout="mclosetime();"> <a href="menu_2.php?page=main">Sights</a> <a href="menu_2.php?page=photo">Photos</a> <a href="#">Test 3</a> <a href="#">Test 4</a> </div> </li> <li><a href="#" class="menu" id="mmenu2" onmouseover="mopen(2);" onmouseout="mclosetime();">New York</a> <div class="submenu" id="menu2" onmouseover="mcancelclosetime()" onmouseout="mclosetime();"> </div> </li> <li><a href="#" class="menu">Memphis</a></li> <li><a href="#" class="menu">Nashville</a></li> <li><a href="#" class="menu" id="mmenu3" onmouseover="mopen(3);" onmouseout="mclosetime();">San Francisco</a> <div class="submenu" id="menu3" onmouseover="mcancelclosetime()" onmouseout="mclosetime();"> <a href="#">Office</a> <a href="#">Sales</a> <a href="#">Customer Service</a> <a href="#">Shipping</a> </div> </li> </ul> </div> <div id="content"> <?php // you build an array for the pages you have. $index = array( "main" => "Sights_text.php" , "photo" => "My_Try_At_Album.php" ); if ( !empty( $_GET["page"] ) ) { $page = $_GET["page"]; if ( array_key_exists( $page , $index ) ) include( $index[$page] ); } ?> </div> </body> </html> And the code for my photo gallery is... <?php // directory where photos are kept $directory = 'images/thumbnails/'; $photos = array(); if($handle = opendir($directory)) { while(false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." ) { $photos[] = $file; } } closedir($handle); } $imgIndex = $_GET['img']; if(!isset($photos[$imgIndex])) { $imgIndex = 0; } $currentImage = $photos[$imgIndex]; if ($imgIndex<=0) { $prev = "Previous"; } else { $prev = "<a href=\"".$_SERVER[php_SELF]."?img=".($imgIndex-1)."\">Previous</a>"; } if ($imgIndex>=(count($photos)-1)) { $next = "Next"; } else { $next = "<a href=\"".$_SERVER[php_SELF]."?img=".($imgIndex+1)."\">Next</a>"; } ?> <html> <body> <?php echo "$prev $next<br>"; echo "<img src=\"{$directory}/{$currentImage}\">"; ?> </body> </html>
  11. Thanks fellas for your help and advice. I do eventually plan to use a database. I'm still pretty new to php so thought this would be an easier way to start off and build up to the database. Thanks again :-)
  12. Hi All I'm been messing around with my code and finally have something working, but I'd like to ask your opinion on something. So I'm trying to create a photo gallery and so far I have 2 links, Previous and Next. Clicking on these will navigate through the pictures. However, at the minute I only have it displaying one predefined picture when you click 'Previous' and another when you click 'Next'. I want to ask your opinion on which way or how would be the best way to loop through the pictures or determine which one is being displayed and then get the next one or previous one in the sequence, depending on which link the user clicks. My code so far is.. <?php // directory where photos are kept $dir = "images/thumbnails/"; $photos = array(); if($handle = opendir($dir)) { while(false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." ) { $photos[] = $file; } } closedir($handle); } // count the no of photos $noOfPics = count($photos); $prev = 2; $next = 4; echo '<a href=My_Try_At_Album.php?p=' . $prev . '>Previous!!</a>'; echo '</br></br><a href=My_Try_At_Album.php?p=' . $next . '>Next!!</a>'; if (isset($_GET['p'])) { if (is_numeric($_GET['p'])) { $picIndex = $_GET['p']; } else { $picIndex = 1; } $currentPic = $photos[$picIndex]; echo '</br></br><img src="' . $dir . $currentPic .'"/>'; } ?> Thanks again :-)
  13. Hi All I'm having a problem with the php include. I'm sure it's very simple but I'm still new at this and trying to find my way. This is my code (very basic) and all I'm trying to do is add content to a web page. However, my problem is that when the web page is displayed there are white spaces between each element. Is there a way I can get rid of this so they all connect together. The files that I'm trying to include..'home page.php', 'nav_include.php' & 'body_include.php' all just have one line of code ..<img src="image_i_want_to_display.jpg"> <html> <head> <title>Title_Menu</title> </head> <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <?php include("home page.php"); ?> <?php include("Nav_include.php"); ?> <?php include("Body_Include.php"); ?> </body> </html> I've attached a picture of what I'm talking about. Thanks much! [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.