I'm making a photo album with my own CMS, part of it is adding photoalbums to it, but i'm having some trouble linking the "click on album name" to the loading of the correct photo album.
my 2 tables are gallery_categories, primary key: id
and gallery_assests, primary key: cat_id

What i need to do is when i click on a link, cat_id and id match so it loads the correct images.

Currently it only takes the last item in my $row array and puts it into the $check and gives it to the other SQL qry.

<?php
		$connection = mysqli_connect('localhost','xxxx','xxxx','xxxx');
		
		$sql= "SELECT title,id FROM gallery_categories ORDER BY order_id ASC";
		$result = mysqli_query($connection,$sql);
	
		while ($row = mysqli_fetch_array($result)) {
		$title = $row['title'];
		$id = $row['id'];
		?>
		<li><a href="<?php $check=$id; ?>"><p id='opmaak'><?php echo $title; echo $check; ?></a></p></a></li><?php
		}
		mysqli_close($connection);
?>
</ul>
</div>
<div id="main_image"></div>
<ul class="gallery_demo_unstyled">
<?php
		$connection = mysqli_connect('localhost','xxxx','xxxx','xxxx');
		
		$sql= "SELECT cat_id, thumbnail, caption FROM gallery_assets WHERE cat_id=$check ORDER BY order_num ASC";

...

Thanks in advance

It's a little bit confuzing the code

<li><a href="<?php $check=$id; ?>"><p id='opmaak'><?php echo $title; echo $check; ?></a></p></a></li><?php

If I will undersand what this link really has to do, maybe I'll help you.

That line should display all the photo album titles in a list and when you click on it link it should connect to the correct images.

My problem lies in the <a href="<?php $check=$id; ?>" bit i don't know how to link it to the correct database part

Still bit confuzed about how your application looks. If I would now for clear I would solution you. However.. by guessing:
I don't know where $checkid variable comes from but I guess it's an ID from images table and you want it to match the ID from the images INFO table and make a link to that image right?
If I understood well... there are some posibilities: let's try this:

<?php
if($check==$id){?>
<li><a href="<?php echo $IMAGE_URL; ?>"><p id='opmaak'><?php echo $title; echo $check; ?></a></p></a></li>
<?php } ?>
//you must query IMAGE_URL from the database

Maybe I gave you a point...

$check is just a made up value to test, the main problem is that all images are in the same folder and i cant really change that because that's how the CMS works, but all the images are linked to the cat_id and the cat_id represents the album.

the problem lies in

<li><a [B]href="<?php $check=$id; ?>[/B]"><p id='opmaak'><?php echo $title; echo $check; ?></a></p></a></li><?php
$sql= "SELECT cat_id, thumbnail, caption FROM gallery_assets WHERE [B]cat_id=$check[/B] ORDER BY order_num ASC";

the bold value should make it into the SQL qry, but what happens now is that the $id only takes the last value (due to the while loop)
what i need is that value to be in there for every link it makes.

example:
album names
--------------
Summer 1
Forrest 2
Flowers 3

so when i click on 1 it should take it to the SQL qry and check it with cat_id if they match the images behind that id will load into the picturebox, but currently the id doesn't stick to the href="" when i click on it.

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.