Solved

Calling a specific line of text...

Posted on 2004-10-14
8
189 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 

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 400 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

Technology Partners: 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!

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

688 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