I have a main page where the user will select an image between 32 others. Each image has its own category. I then need to open my Categories php page (no need to have 32 I'm sure), where the image selected will display THAT images categories.

I have no idea where to start with this. Any ideas?

Once the page unloads, categories is "emptied" so that the next category can be selected from the main page and be displayed again on categories.php.

Recommended Answers

All 15 Replies

Note: I have no problem in loading the php page, only getting the categories from a text file to display (also, no problem in getting the text to display), only the correct text file to be selected depending on the users selection of an image from the main page.

Not so clear as to what you want to get:

1. Your main page have links (images) all to the same categories.php page, and you want this categories.php page to call for different content depending on what image link is clicked on?

2. You don't want to go from main page to a categorie page when a category image is clicked on, you want a type of frame/pop-up/or similar to appear on your main page?

If you have code already, please post it here to see.

That my problem, no code as yet, just the empty categories.php.

After searching some more, I think the following should clear all confusion.

User click on image "Parts" on the main page. The variable "Parts" need to be used on the Categories php page so that all the categories (25) in my catParts text file can be loaded to the categories php page. If the page is unloaded, all is cleared.

User now click on image "wheels", variable "wheels" needs to be used in categories page so that all text from catWheels can be loaded.

Makes sense?

This piece of code might also help. It will load the Categories.php page. How do I load the text though when the categories page is loaded. Keep in mind, this is based on different text files, one for each category, 32 categories.

<div id="menu8"><a href="Categories.php"><img src="Images/Left Menu/CarParts.png" alt="View Vehicle Parts." width="130" height="50" title="Click to view all vehicle part categories." /></a></div>

This is now where the page need to determine which text file to read from.

I can run the php page by using the text file name in code, I need to get a variable and then read from that. This is the code I am using in loading the text from a text file, all fine. It is the CatCarParts.txt that needs to be defined, depending on which category the user selected on the main page -

<body>
<?php 
function LoadCategory() 
{
$myFile = "CatCarParts.txt";//This needs to be returned from the variable....
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
echo '<font color="#0FF">' . $theData . '</font><br>';
}
?>

<p style="text-align: justify"><strong><a class="Colorlink"<a href="?run=LoadCarParts">Vehicle Parts Category</strong></a></p>

<?php 
if (isset($_GET['run'])) $linkchoice=$_GET['run']; 
else $linkchoice=''; 

switch($linkchoice){ 

case 'LoadCarParts' : 
    LoadCategory(); 
    break; 
} 
?>
</body>

Okay, I think I understand what you need to do, by calling different text files in one php page on click of a button/image-link.

Now, again, I am no php expert, and learns more about it as I go along, so there may be some experts here who can correct me where I mistake, but the way I see it, is that you need to call the variable of the spesific text file in the URL where the image is linking to the php page. In other words, the URL calls the variable for the categories.php, different categories, different variables in the different URL's to the txt files.

Does that make sense?

It does. I could get a lot on GET and POST statements, no code or where to call or use it though. The above functions can do what I need, IF I knew how to use it...

Any ideas on these? Also how to use it in my select case function. That way I can get the variable, say "Parts", let the case go to the "Parts" selection, and then call the load text function with the correct text file data.

I will try my hand on this, it may or may not work, but say for example your first variable to link is "text1". Replacing my example "text1" with what ever variable you named.

Try this code on the php page:

<?php
$text1 = @file_get_contents("http://www.yoursite.com/yourdirectory/".$_GET['text1']) or die("File not found!");
print "$text1";
?>

Try this in the url linking the clickable image to the php page.

http://www.yoursite.com/yourdirectory/categories.php?text1=desired-file.txt

Thanks Kraai.

I found the solution. I'll mark this as solved.

For future readers - how to pass a variable to other forms...:)

<li class="lineup"><a href="Categories.php?name=Parts"><img src="Images/Categories/Parts.png" alt="Vehicle Parts" name="Parts" width="130" height="130" title="Click to view vehicle part categories" /></a></li>

This goes into the form that you will call from, i.e. in my case, the main form.

In the form that you need the variable, at THE TOP OF THE PAGE, before ANY codes -

<?php 
$VarToHold = $_GET['name'];
echo $VarToHold;
?>

Will display "Parts" in this case. Just remove the echo part if you do not want it visible. "name" is the call from the <a href> from the main page...

Cool, glad you solved it, and me learning something more about it!

No prob. 4 *&%%^ HOURS to get 6 lines of code!, I'm sure I'll be bald by the end of this week. Funny enough, I had a breeze with MySql into all different pages. vb6 is just soooo much easier, or until I have this under foot at least.;)

No prob. 4 *&%%^ HOURS to get 6 lines of code!, I'm sure I'll be bald by the end of this week. Funny enough, I had a breeze with MySql into all different pages. vb6 is just soooo much easier, or until I have this under foot at least.;)

AndreRet,

Glad to hear that you solved your problem!

I'm not sure how knowledgeable you are with Web Development, seeing how you mentioned VB was more your style, but may I suggest that you use titles more descriptive and closer to your goal? For instance, "Determine previous page click event" sounds a lot like JavaScript, right? Especially the part about "click event", which tends to be associated with JavaScript (at least to me). A title like "Determine previous page via query string" would be much closer to what you seek. Although, if you don't know about query strings, my point is moot.

I've spent the last 5 minutes thinking of whether to post this or not, simply because it SOUNDS like a jackass comment, but it's not meant to be, honest! I skipped over it for quite a while thinking it was a JavaScript issue, not a PHP one.

Not meant to be critical, promise...

commented: Thanks.:) +7

@floatingDivs, no problem.;)

I'm very new to web dev, 2 weeks to be exact, although I have a vast vb background. Thanks for the pointers, I was obviously thinking with my "vb" hat on.

Some kudos for the rap over the fingers.:)

All my other questions regarding web dev will be in this forum. I'm using dreamweaver cs5, css, html, php, mysql.

Just out of curiousity, why are'nt you using a database and SQL to handle all this? Maybe I'm not understanding exactly what you're doing. I know you have it solved, but I was just wondering.

It will be pointless and performance consuming to add a variable to a database, load the new page and then recall the variable. It all was done with six lines of code, better performance I'm sure.:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.