View Single Post
Old 05-23-2009, 08:46 AM   #17 (permalink)
Sirupsen
The Contributor
 
Sirupsen's Avatar
 
Join Date: May 2009
Posts: 53
Thanks: 2
Sirupsen is on a distinguished road
Default

Alright, here is how it all ended up..

I felt like I needed to create a Thumb BOOL, as I have > 1 pictures in one gallery, which are invisible on the page before the thumb is opened, and you can browse them in the Thumbail.


After that, I began the coding part. I realised the hard part was to tell the image which "hidden gallery" it was in, so I decided to use functions, to check that - my first use of functions effectively!

Here's how it all ended up:
PHP Code:
<?                    
                            $result 
mysql_query("SELECT * FROM Portfolio");
                            
                                while(
$row mysql_fetch_array($result)) {
                                
                                        if(
$row['thumb'] == '1') {
                                        
                                            function 
boundToMe($id) {
                                                
$res mysql_query("SELECT * FROM Portfolio WHERE boundTo = '$id' ORDER BY id ASC LIMIT 0,1");                        
                                                while(
$func mysql_fetch_array($res)) {
                                                            echo 
$func['picture'];
                                                }
                                            }
                                            
                                            echo 
'<a rel="shadowbox['.$row['id'].'];" href="';
                                            
boundToMe("".$row['id']."");
                                            echo 
'"   class="option" id="thumb" title="'.$row['pictureDesc'].'" ><img src="'.$row['picture'].'" / class="thumbs"></a> ';
                                        } else {
                                        
                                        function 
WhoAmIBoundTo($bound) {
                                                
$res mysql_query("SELECT * FROM Portfolio WHERE id = '$bound' ORDER BY id ASC LIMIT 0,1");                        
                                                while(
$func mysql_fetch_array($res)) {
                                                            echo 
$func['id'];
                                                }
                                            }
                                            
                                             echo 
'<a rel="shadowbox[';
                                             
WhoAmIBoundTo("".$row['boundTo']."");
                                             echo 
'];" href="'.$row['picture'].'" class="hidden" title="'.$row['pictureDesc'].'" ></a>'
                                        
                                        }
                                    }
                        
?>
I got one question though..!
How do I just make the echo's one long line, with the functions in? I couldn't manage to do that! Like this:

PHP Code:
echo '<a rel="shadowbox[WhoAmIBoundTo("".$row['boundTo']."")']" href="'.$row['picture'].'" class="hidden" title="'.$row['pictureDesc'].'" ></a>'; 
Edit: Fuck, for some reason it bugs when there's > 1 image bound to the thumb.
Edit2: It seems like that the HTML just stops after this PHP, even though theres around 100 lines more HTML. Anyone got an idea of what's going on?! :O
Edit3: It gotta be in the else{ ], since it only runs one of those, and is supposed to do 3 with my current database.
Edit4:
It looks like this when I view the HTML source on my page:
PHP Code:
<a rel="shadowbox[1];" href="http://www.sirup.netau.net/2009-05-21_0944.png" class="option" id="thumb" title="Thumbail!" ><img src="http://www.sirup.netau.net/2009-05-21_1006.png" / class="thumbs"></a

<
a rel="shadowbox[1];" href="http://www.sirup.netau.net/2009-05-21_0944.png" class="hidden" title="Description lalala" ></a
So we can see it does only run the else { } one time, but it should run it two times:

Edit5:
It's fixed! I just cleaned up the code on the couch watching a movie! Macbook ftw.
PHP Code:
<?                    
                $result 
mysql_query("SELECT * FROM Portfolio");
                                    
                    function 
boundToMe($id) {
                        
$res mysql_query("SELECT * FROM Portfolio WHERE boundTo = '$id' ORDER BY id ASC LIMIT 0,1");                        
                        while(
$func mysql_fetch_array($res)) {
                            echo 
$func['picture'];
                        }
                    }
                    
                    function 
WhoAmIBoundTo($bound) {
                        
$res mysql_query("SELECT * FROM Portfolio WHERE id = '$bound' ORDER BY id ASC LIMIT 0,1");                        
                        while(
$func mysql_fetch_array($res)) {
                                    echo 
$func['id'];
                        }
                    }
                            
                while(
$row mysql_fetch_array($result)) {
    
                    if(
$row['thumb'] == '1') {
                                                                        
                        echo 
'<a rel="shadowbox['.$row['id'].'];" href="';
                        
boundToMe("".$row['id']."");
                        echo 
'" class="option" id="thumb" title="'.$row['pictureDesc'].'" ><img src="'.$row['picture'].'" / class="thumbs"></a> ';
                        
                    } else {
                                                                                    
                        echo 
'<a rel="shadowbox[';
                        
WhoAmIBoundTo("".$row['boundTo']."");
                        echo 
'];" href="'.$row['picture'].'" class="hidden" title="'.$row['pictureDesc'].'" ></a>'
                                        
                    }
                }
?>
It seems to work fine! Haven't tested it with more thumbs yet though. :(
I'm just gonna clean up the rest of the code first.
Edit6: Worked great.

Last edited by Sirupsen : 05-23-2009 at 03:11 PM.
Send a message via AIM to Sirupsen Send a message via MSN to Sirupsen Send a message via Yahoo to Sirupsen Send a message via Skype™ to Sirupsen
Sirupsen is offline  
Reply With Quote