Jump to content

insejn

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

insejn's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello! Im trying to do a simple gallery where a simple script gets all images from a folder and puts them into a line of small thumbs. Each picture links to itself and displays it as a bigger one below the smaller ones.. This script also gets rows from a textfile and uses it as a description for the image depending on what picture you display.. 1.jpg, 2.jpg and so on. For example: I have a folder called "bilder" where I put all my pictures (1.jpg, 2.jpg and so on..). I use a script that gets all the pictures from the folder and lines them up in a row as small pictures/thumbs 40x40 pixels. I also put a link on them that links to the same picture. It links to the same page but with "?pic_id=1" and displays the picture I just clicked on below the row of thumbs.. but here is where my problem is: I dont know how to get right numbers on the right thumbs. My thought was that I somehow could use the names 1.jpg, 2.jpg and remove the ".jpg" and use the numbers to link to the right picture. Or is it possible to implement some sort of count-feature that puts the right "link number" on the right picture? For example, on the first picture 1.jpg it links to ?pic_id=1, and 2.jpg links to ?pic_id=2 and so on.. which way is the easiest? and how do I do it? This is what I use so far: //Folder where I have my pictures $path = "bilder/"; //using the opendir function $dir_handle = @opendir($path) ; //running the while loop while ($file = readdir($dir_handle)) { if($file!="." && $file!="..") echo "<a href='?pic_id=".$[color=red]????[/color]."'><img src='$path/$file' border='0' width='40' height='40'/></a> ";} closedir($dir_handle); Is this possible to solve?
  2. Thank you for the responses! Blueoden: I tried the first suggestion you gave, the result was that the page only showed the last "else" statement.. I thought I perhaps did something else wrong displaying the URL. I like the "www.website.com/?page=home" best, but it shows the "else" statement instead of the home content. This is what I wrote with the help of your code: if ($_get['page']=='home') { echo "content of Home"; } else if ($_get['page'] == 'products') { echo "content of Products"; } else if ($_get['page'] == 'contact') { echo "content of Contact"; } else { echo "..else content.."; } ..shouldn't this work if I enter www.website.com/?page=home ? ADDITIONAL COMMENT: Oh my god, I'm such a nOOb.. I just needed to change the small letters in get to GET. It seems to work much better now
  3. This is probably an easy task, but I cant seem to find a solution for it.. so I need some help I'm working on a website where I display different parts of the page depending on what comes after the questionmark (?), for example "www.website.com/index.php?home". if(isset($_GET['home'])) { echo "..the content for this page"; } ..that's working fine, the problem is how I do when I enter the index.php without anything after the questionmark, for example "www.website.com/index.php". I thought putting this code in would solve it: if(isset($_GET['home'])) { echo "..the content for this page"; } else { echo "..show something similar as the home-page"; } ..but then that ends up on every other page (products, sales, contact etc.). Is there a way to either show the same content for home or redirecting to index.php?home if someone enters www.website.com?
  4. Daniel0: Ahh thanks! I cant understand why I never thought of using the ID instead of the username ..that would make a lot of things a lot easier. Thanks for the quick responses!
  5. <p></p> I put the username that is in the logged in $_SESSION and store it in a variable, for example "Bengt", and then I use a script that shows everything in a folder that has the same name as the variable. Maq: Do I use that command to make sure that "Bengt" logs in with lower casing as "bengt"? Thank you for the responses!! =)
  6. I've created a simple admin-area where username/password is stored in a database. Pictures and files and so on are stored in folders connected to the username. So if someone named Bengt logs in he will open a folder called "Bengt" and show everything inside of that folder.. The problem here is if he logs in with the username "bengt", with the "b" as a lower case.. then the admin area can't find the folder because it searches for a folder with a big "B (Bengt).. Is there a smart solution for this? Perhaps make it impossible to log in with a lower case word? or is there something with PHP that can ignore big and small letters? ..but how do I do that? :S /Bjorn
  7. ..sorry its not that either. Is there a way to make a new variable containing the $row['article_id'] ? Like for example: $new_folder_name = $row['article_id']; ..but I dont seem to get that to work either. Or am I writing the code wrong? should I for example write: $new_folder_name = "$row['article_id']"; or $new_folder_name = ("$row['article_id']"); ..I think as I said the problem is when I try to write the code if (file_exists("images/$row['article_id']")) { I think that way of integrating $row['article_id'] is wrong somehow..
  8. I cant see what Im doing wrong here, I thought it would work but something simple must be wrong.. I'm trying to create a simple script that creates a new folder that has the same name as the latest id from my database table. I thought this code should do it but it doesn't, I guess the problem is when the folder is supposed to be created with the code: if (file_exists("images/$row['article_id']")) This is the existing code now, is there a right way to do this? <? $host="localhost"; // Host name $username="..."; // Mysql username $password="..."; // Mysql password $db_name="..."; // Database name $tbl_name="articles_table"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Query to get the latest ID (article_id) $result = mysql_query("SELECT * FROM articles_table ORDER BY article_id DESC LIMIT 1") or die(mysql_error()); //Make a while loop and display the right id number.. while($row = mysql_fetch_array( $result )) { echo "Latest id is: ".$row['article_id']."<br>"; } // Create a new folder with the latest id number... if (file_exists("images/$row['article_id']")) { print("Folder already exists!!\n"); } else { mkdir("images/$row['article_id']"); //If Success then print out this.. echo ("The new folder has been created for you!\n"); } ?> ..thanks in advance!
  9. I got it fixed! it was that query line that was wrong.. I changed it to: $query = ("SELECT article_id, article_title, article_body, article_written_by, article_console, article_date FROM articles_table WHERE article_id = '{$_GET['article_id']}'"); Thank you guys for all the help!
  10. Thank you very much! such an easy and noobish misstake that was I did ..but now I get an Error shown instead: "Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE article_id = '12'' at line 1". Is the line incorrect to use then? or might something else be the problem?
  11. Thanks for the answer it cleared up some confusions I had about that code. But the main problem I have is to get the "chosen" news on the read_news.php page. The code looks like this on the preview page news.php [color=orange]// Get 3 news from the "articles_table" table and order them with the latest first![/color] $result = mysql_query("SELECT * FROM articles_table ORDER BY article_id DESC LIMIT 3") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { [color=orange]// Print out the contents of each row into a table[/color] echo "<table width='400' border='0' cellspacing='1' cellpadding='2'>"; echo "<tr><td bgcolor='#CCFF00'><font color='#333333'>".$row['article_date']."</font></td></tr>"; echo "<tr><td><font size='+1'>".$row['article_title']."</font><font class='console'> [ ".$row['article_console']." ]</font></td></tr>"; echo "<tr><td>".$row['article_body']."</td></tr>"; echo "<tr><td><i><font class='console'>Skriven av: ".$row['article_written_by']."</font></i></td></tr></table><br>"; echo "<a href='read_news.php?article_id=$row[0]'>read more..</a>"; } ?> ..How do I get the read_news.php to display the selected news? some sort of $_GET['article_id'] code? And how do I limit the number of chars from the $row['$article_body'] to show for exampe the first 30 chars?
  12. Hi, This is my first post on any php-forum.. I have given up searching the net for my answer. It seems such a simple task but still I cant seem to find the solution. My problem is this: I'm creating a type of news section on my website where I want to display a preview of the last 3 articles in the database with a "read this.." link under each preview that takes the user to for example "read_news.php" and shows the chosen news from the database. The thing I cant seem to find the solution for is how to create the read this link on the preview-page that takes you to the "read_news.php?article_id=...." and displays the right $article_title + $article_body + $article_written_by + $article_date from the chosen $article_id.. I think I get the link to work on the preview.php page with this code: echo "<a href='read_news.php?article_id=$row[0]'>read this...</a>"; ..this links to the read_news.php and displays "read_news.php?article_id=14" in the adressfield but the page doesn't show anything. read_news.php looks at the moment like this: <? //database connection $dbhost = 'localhost'; $dbuser = '...'; $dbpass = '...'; $dbname = '...'; if(isset($_GET['article_id'])) { $query = "SELECT article_id, article_title, article_body ". "FROM articles_table ". "WHERE article_id = '{$_GET['article_id']}'"; $result = mysql_query($query) or die('Error : ' . mysql_error()); list($article_id, $article_title, $article_body) = mysql_fetch_array($result;) echo "$article_title<br>"; echo "$article_body<br>"; echo "$article_written_by<br>"; echo "$article_date<br>"; ?> ..and obviously this is'nt the right way of solving it. I'm totally lost here and there's probably a really simple solution to this but I cant seem to figure it out. Am I making any sense at all? /Björn (that's actually Bear in English:))
×
×
  • 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.