Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Calling a specific line of text...

Posted on 2004-10-14
8
Medium Priority
?
192 Views
Last Modified: 2011-10-03
Right, basically, I'm creating an image gallery which will consist of 4 frames. Top frame will have a link back to main page in it, so that's a constant. The second frame down will be the page where the images are displayed, and I can do that... that's not a problem... The fourth (yes, I know, I missed one) frame will be where the thumbnails are displayed, again no problem... the third frame will be where the descriptions of the photos are displayed. This is where I find a problem.
My links from the thumbnail frame are going to look something like this:

../fullsize/get_file.php?id=0001&textid=0001

So, 'id=0001' refers to calling the picture 0001.jpg from the fullsize pictures folder.

'textid=0001' will, hopefully, refer to calling the line of text from a certain file...

So, for example...
The photos descriptions text file would be as follows:

0001 = A picture of me
0002 = A picture of my cat
0003 = A picture of me being eaten by my cat

etc...

How would I go about creating a text file or database with lines of text in which I can number and call on using server variables, and how would I go about calling from that file, and inserting the line into the third frame... I hope this is clear...

Thanks in advance.
0
Comment
Question by:cagsmith
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 33

Expert Comment

by:snoyes_jw
ID: 12309592
You could stick the whole thing in a database.  Each record would contain a unique id (0001, 0002, 0003...), the path to the picture, the path to the thumbnail, and the text.  Then all you have to pass around is the unique id.

Any database will work; MySQL is popular, free, well supported, and integrates very nicely with PHP.  It's pretty easy to install too, if you're happy with default configurations.  See http://www.mysql.com and http://www.php.net/mysql for details.

If you really want to use the text file instead, there are several PHP methods to read a file into either a string or an array of strings, and several string search functions.
http://www.php.net/function.file
http://www.php.net/strstr
http://www.php.net/preg_match
0
 

Author Comment

by:cagsmith
ID: 12310693
Ok, the MySQL database sounds like a plan... erm... any idea how I go about this one? I'm used to using PHP, just not MySQL.
0
 
LVL 33

Expert Comment

by:snoyes_jw
ID: 12310783
Download mysql from www.mysql.com and follow the documentation to get it installed and running.  Create a database, and create a table in that database, using fields as I mentioned above (id, picturePath, thumbnailPath, textDescription).  Add some records to this table.  There is good documentation on how to do all this at the mysql website.

Depending on how much is in each frame, you could write one page to return everything and pass a parameter for what you want returned, or you could use separate pages for each frame.

The page(s) will contain something like:

<?php
// connect to database server
mysql_connect("server', "username", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());

// fetch values from database
$sql = "SELECT textDescription FROM myTable WHERE id = " . $_GET['id'];
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);

echo $row['textDescription'];
?>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:cagsmith
ID: 12320967
Ok, I decided to stick with PHP after having a look at MySQL and it seems far to hard for someone of my means to try and learn :(
I had a look at those links to php.net and they none of them seemed to answer fully what I wanted...

I guess I'd have to load the file with the text descriptions and then call the respective line of text, but how...
What would I need to write as the link after, eg, 'fullsize/get_image.php?photoId=0001&*what goes here*

and how do I load the file with the text descriptions in? Also, I guess, what's easier than having 4 frames, I could just load the text into a cell in a table under the photo, but what sort of PHP command would I use for that?
0
 
LVL 33

Expert Comment

by:snoyes_jw
ID: 12322796
Ok, so you've got a text file.

You load it into an array:
$textFile = file("path/to/file.txt");

You run through the array and look for the id in question:
foreach($textFile as $text) {
    if(substr($text, 0, 4) == $_GET['id']) {
        echo substr($text, 8);
}
0
 

Author Comment

by:cagsmith
ID: 12328154
Simple question I guess, but how do I define the id of each particular line of text in the text file?
0
 
LVL 33

Accepted Solution

by:
snoyes_jw earned 1600 total points
ID: 12328453
The code above looks for the id in the first 4 characters of the text file, and takes the text from character 8 on (should be 7, since we're starting from 0).  So, you use the text file like you had it written:
0001 = text
0002 = text
0
 

Author Comment

by:cagsmith
ID: 12330719
That's great. Thanks a lot.
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question