Link problem ..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the actual HTML source code that the browser gets.
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Hi,

Do you mean tha javascript that it links to .. imagepop.js?

Code: Select all

var opera=(navigator.userAgent.indexOf('Opera') != -1) ? true:false;
var operaVer=0;
if (navigator.userAgent.indexOf('Opera ') != -1)
{
	operaSplit=navigator.userAgent.split('Opera ');
	operaVer=parseInt(operaSplit[1]);
}
else if (navigator.userAgent.indexOf('Opera/') != -1)
{
	operaSplit=navigator.userAgent.split('Opera/');
	operaVer=parseInt(operaSplit[1]);
}
var opera7=(opera && operaVer >= 7) ? true:false;

var ie5mac=(navigator.platform.indexOf('Mac') != -1 && navigator.userAgent.indexOf('MSIE') != -1) ? true:false;
var dom=(document.getElementById && !opera) ? true:false;

var vertShift=100;
if (opera7) vertShift=200;

function imgPop(imageURL, imageTarget)
{
	
	imageTarget=(imageTarget) ? imageTarget:"_blank";

	if ((dom || opera7) && !ie5mac)
	{ 
		var imgWin = window.open('about:blank', imageTarget ,'width=200, height=200, left=0, top=0');

		with (imgWin.document) 
		{ 
			writeln('<html><head><title>Loading...</title>'); 
			writeln('<style type="text/css"><!-- body { margin:0px; padding:0px; } --></style></head>'); 
			writeln('<body onload="self.focus();"><img id="pic" style="display:none" /></body></html>'); 
			close();		 
		} 

		var img = new Image(); 
		img.onload = function() { sizeImgWin(imgWin, img); }; 
		img.src = imageURL; 
	} 

	else window.open(imageURL, imageTarget);
} 
	 
function sizeImgWin(win, img) 
{ 
	var new_w = img.width; 
	var new_h = img.height; 
	var old_w = win.innerWidth || win.document.body.offsetWidth; 
	var old_h = win.innerHeight || win.document.body.offsetHeight; 

	if (!new_w) { new_w = old_w; } 
	if (!new_h) { new_h = old_h; } 

	new_w -= old_w; new_h -= old_h; 
	win.resizeBy(new_w,new_h); 
	win.document.title = img.src.substring(img.src.lastIndexOf("/")+1); 
	var pic = win.document.getElementById('pic'); 
	pic.src = img.src; 
	pic.style.display = 'block'; 

	sw=screen.width; 
	sh=screen.height; 

	var leftPos=((sw-new_w)/2)-100; 
	var topPos=((sh-new_h)/2)-(vertShift+(((sh-new_h)/2))*0.1); 
	win.moveTo(leftPos, topPos); 
}
With <script language="JavaScript" type="text/javascript" src="imagepop.js"></script> at the top of the header page and link system in question ..

Thanks ..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

no. Last time I try to ask for it: I want to see the HTML generated by your php code that creates the link that is sent to the browser that gets displayed on your screen that goes into your eyes to be read by your mind.



Good grief, it's like pulling teeth sometimes. :?
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Hi,

Here is the page thats is used to view the gallerys, thumbnails and the full image .. I am trying to get the full image to open in the new window via the javascript .. rather in in the same window ..

Code: Select all

<?php

        include("config.inc.php");
        
        
        $result_array = array();
        $counter = 0;

        $cid = (int)($_GET['cid']);
        $pid = (int)($_GET['pid']);

        

        if( empty($cid) && empty($pid) )
        {
                $number_of_categories_in_row = 2;

                $result = mysql_query( "SELECT c.category_id,c.category_name,COUNT(photo_id)
                                                FROM gallery_category as c
                                                LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
                                                GROUP BY c.category_id" );
                while( $row = mysql_fetch_array( $result ) )
                {
                        $result_array[] = "<a href='../data.php?action=gallery&cid=".$row[0]."'>".$row[1]."</a> "." - <font color=\"#000000\"><b>".$row[2]."</b> images</font>";
                }
                mysql_free_result( $result );        

				$result_final = "<div align=\"center\"><font class=\"txt\"><strong>Gallery Categories</strong></font></div><br>";
				
				$result_final .= "<tr>\n";

                foreach($result_array as $category_link)
                {
                        if($counter == $number_of_categories_in_row)
                        {        
                                $counter = 1;
                                $result_final .= "\n</tr>\n<tr>\n";
                        }
                        else
                        $counter++;

                        $result_final .= "\t<td><div align=\"center\"><font class=\"txt\">".$category_link."</font></div></td>\n";
                }

                if($counter)
                {
                        if($number_of_categories_in_row-$counter)
                                               $result_final .= "</tr>";
                }
        }


        

        else if( $cid && empty( $pid ) )
        {
                $number_of_thumbs_in_row = 3;

                
                if(!isset($_GET['page'])){
                    $page = 1;
                } else {
                    $page = $_GET['page'];
                }

                
                $max_results = 6;

                
                $from = (($page * $max_results) - $max_results);

                $result = @mysql_query( "SELECT photo_id,photo_caption,photo_filename FROM gallery_photos WHERE photo_category='".addslashes($cid)."' LIMIT $from, $max_results");

                $nr = @mysql_num_rows( $result );

                if( empty( $nr ) )
                {
                        $result_final = "\t<tr><td><div align=\"center\"><font class=\"txt\"><strong>No images in category found!</strong>
                                                <br><br><font size=\"2\"><a href='../data.php?action=gallery'>Back to Photo Gallery Category List</a></font>
                                                </div></td></tr>\n";
                }
                else
                {
                        while( $row = mysql_fetch_array( $result ) )
                        {
                                $result_array[] = "<a href='../index.php?pages=gallery&cid=$cid&pid=".$row[0]."'><img src='".$images_dir."/tb_".$row[2]."' border='1' alt='".$row[1]."' /></a>";

                        }
                        mysql_free_result( $result );

                        $result = @mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes($cid)."'" );
                        list($category_name) = mysql_fetch_array( $result );
                        mysql_free_result( $result );

                         $result_final = "<tr><div align=\"center\"><b><font class=\"txt\"><a href='../data.php?action=gallery'>Back to Categories</a></b><br><br> Viewing Category \"$category_name\"</b></font></div>";
        
                        foreach($result_array as $thumbnail_link)
                        {
                                if($counter == $number_of_thumbs_in_row)
                                {        
                                        $counter = 1;
                                        $result_final .= $category_link."\n</tr>\n<tr>\n";
                                }
                                else
                                $counter++;

                                $result_final .= "\t<td><div align=\"center\"><font class=\"txt\">".$thumbnail_link."</font></div></td>\n";
                        }
        
                        if($counter)
                        {
                                if($number_of_photos_in_row)
                        $result_final .= "\t<td colspan='".($number_of_thumbs_in_row)."'></td>\n";
                        $result_final .= "</tr>\n";
                        
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM gallery_photos WHERE photo_category=".addslashes($cid).""),0);


$total_pages = ceil($total_results / $max_results);

if ($total_pages >1)
{



$result_final .=  "<tr><td colspan='".$number_of_thumbs_in_row."'><br><center><font class=\"txt\">Showing Page: ".$page.' of '.$total_pages."</font><center><br>";


if($page > 1){
    $prev = ($page - 1);
    $result_final .=  "\n<font class=\"txt\"><a href=\"../data.php?action=gallery&cid=$cid&page=$prev\" title='Previous Page'><< Prev</a></font>";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        $result_final .= "<font class=\"txt\" color=\"red\">&nbsp;$i</font>";
        } else {
            $result_final .=  "\n<font class=\"txt\"><a href=\"../data.php?action=gallery&cid=$cid&page=$i\" title='Page ".$i."'>$i</a></font>";
    }
}


if($page < $total_pages){
    $next = ($page + 1);
    $result_final .=  "\n<font class=\"txt\"><a href=\"../data.php?action=gallery&cid=$cid&page=$next\" title='Next Page'>Next >></a></font>";
}
$result_final .=  "\n</td></tr>";

}
else
{
$result_final .=  "<br>\n";
}
}
}
}

        
        else if( $pid )
        {
                $result = mysql_query( "SELECT photo_caption,photo_filename FROM gallery_photos WHERE photo_id='".addslashes($pid)."'" );
                list($photo_caption, $photo_filename) = mysql_fetch_array( $result );
                $nr = mysql_num_rows( $result );
                mysql_free_result( $result );        

                if( empty( $nr ) )
                {
                        $result_final = "<tr><td><font class=\"txt\">No Photo found</font></td></tr><br><br>\n";
                }
                else
                {
                        $result = mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes($cid)."'" );
                        list($category_name) = mysql_fetch_array( $result );
                        mysql_free_result( $result );        

                        $result_final .= "<tr><td><font class=\"txt\"><center><b><a href='../data.php?action=gallery'>Categories</a></b> - 
												<a href='../data.php?action=gallery&cid=$cid'><b>Thumbnail Listing</a></b><br><br>
                                                Viewing Category \"$category_name\"<br><br><br><b>Photo caption:<br><br></b>$photo_caption</font><br></center></center></font></td></tr>";

						$result_final .= "<tr>\n\t<td align='center'>
                                        <br>
                                        <font class=\"txt\"><img src='".$images_dir."/".$photo_filename."' border='1' alt='".$photo_caption."'>
                                        </td>
                                        </tr><br>";
                }
        }


echo <<<__HTML_END
<table width='75%' cellspacing='0' cellpadding='5' border='0' bordercolor='' align='center'>
$result_final                
</table><br><br>
__HTML_END;

?>
Thanks ..
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

in your browser when you view the page.. and view its source

what html is returned?
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Hi ..

OMG ":oops:"

Code: Select all

<a href='../data.php?action=gallery&cid=1&pid=1' target='_blank' onclick='imgPop(this.href, this.target); return false;'><img src=../album/photos/tb_1.jpg border='1' alt=Bla></a>
Looks to be correct .. :?

3 images in the gallery show the correct paths ..

Thanks

Phenom | Please use

Code: Select all

tags where appropriate[/size][/color]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

So is there a problem? I'm confused
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Hi,

Yep .. you are ment to click on the thumbnail .. which then opens the full image in a new window .. which automatically resizes to the size of the image .. When the thumbnail is clicked .. the popup window opens .. but no image loads into it ..

Im guessing its this part of the html link posted above:

Code: Select all

<a href='../data.php?action=gallery&cid=1&pid=1' ..
The ../data.php?action part .. or maybe that the query to pull the full image out of the database hasnt been introduced in the popup window method ..

Thanks
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

Jim_Bo wrote:Hi ..

OMG ":oops:"

Code: Select all

<a href='../data.php?action=gallery&cid=1&pid=1' target='_blank' onclick='imgPop(this.href, this.target); return false;'><img src=../album/photos/tb_1.jpg border='1' alt=Bla></a>
Looks to be correct .. :?

3 images in the gallery show the correct paths ..

Thanks

Phenom | Please use

Code: Select all

tags where appropriate[/size][/color][/quote]

so your data.php is in a different directory than the original php script that calls it?  if your oringinal php script is in the SAME directory as data.php, then yeah the ../ should be ./

also, look in the href value itself... you have a lot more stuff in the URL itself you really don't need....

Also, one very [b]Final[/b] request... could you post the ENTIRE HTML that is generated when the new window opens?  IOW, post the html of the popup window that opens.
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Hi,

The html from the popup window is:

Code: Select all

html><head><title>Loading...</title>
<style type=&quote;text/css&quote;><!-- body { margin:0px; padding:0px; } --></style></head>
<body onload=&quote;self.focus();&quote;><img id=&quote;pic&quote; style=&quote;display:none&quote; /></body></html>
data.php is just the index.php that the header.php and footer.php are attached to ..

Thanks
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

where did you download this script you are running... cuz i did a search and found someone having the exact same code but with a different problem...

http://www.sitepoint.com/forums/showthread.php?t=177332
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Hi,

From some gallery tutorial I found searching google ..
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

well here is the thing jim bo. even say we correct this problem (and I think the solution has been given about 3 times and lack of information given more), there is gonna be another problem you are going to have related to this code. And it's not because the code is off, or because of a small problem, it's because you don't understand the language itself. If you did, you'd write your own.

Now, be sure to understand i'm not bashing you, merely explaning this current situation. What you are gonna need to do is discover the usage of php.net manual and google. The script you are needing to perform can be done in much simplier terms than the current app you downloaded. But before it can be written more simple, you must have understanding of how it works so you can write your own version.

You do this by looking up references to functions found within that script and trying to figure out HOW that particular function(s) work, and trying it out on your own towards the project you are trying to build.

I promise what you are wanting to do has been explained, reitterated,and redefined almost 15 times on these boards alone (just search for thumbnails in our search feature). That search alone will generate enough information for you to be able to get a really good understanding of how this sort of script works, and how you can begin to create it on your own.

Javascript (which is in your app) can be used, and it can also not be used. The arrays that the app uses, can be used and they can also be done with out them. But before you can do any of them (and i can't stress this enough), you must first understand how this language itself works.

Now, I know you've been on the boards long enough to at least get a grasp of how php works and the simple what does what, but maybe it's time you read up on the GD Library, Header Relocation, and some other useful functions in order to get this script to work.

Don't feel like I'm just pushing you away on this.. Quite the contrary. I'm more so interested in seeing people, like yourself, who are interested in php go the extra mile to learn more than simple if/else statements. If you go through with this, and have trouble with your code (or have a misunderstanding about a subject), please do let us know cuz that's what we're here for. I simply just do not enjoy trying to correct 3rd party code that the user usually does not understand at all.. cuz it makes it nearly impossible to trouble shoot the issue with that user, and then makes our lives a living hell ;)
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Hi,

No offence taken, a tad embarrassed .. Its all pointers to a noobie like me.

The gallery is a tutorial that was put together to learn and understand photo galleries/GD .. Actually I understand most of the gallery code (well so I thought). I have infact modified much of the code to suit my sites needs .. But you are right, there are many more ways to create affective codeing with much less lines and much cleaner code, all to create the same effects, I see it all the time in these forums. I dont even bother posting answers to things I think I could pass an answer on, in the fact of been :oops: when a guru comes along and posts an l33t way around fixing the problem .. Some people are mathematically minded and some aren’t .. Personally I fall under the some aren’t category which makes the learning of php much harder for me :oops: .. I enjoy php/mysql greatly .. but do not have the hours to put into learning the thousands of techniques available, as this is more a hobby at this point of time.

In the case of this post I am most embarrassed that I cant get something that I class very simple to work :oops: .. The javascript is just something I wanted to incorporate into the gallery in question. I have used the JavaScript in question many times before, even to call image urls/names stored in the database .. In this case it has posed a problem that I personally haven’t figured out, which is from total lack of php knowledge and time. As I said I have modified/rewritten (what ever one wants to call it .. I would call it modified myself) much of the code to suit my needs .. But as for 4 thumbnails wide within tables I have never taken the time to understand .. So have left the main page as found to show the data/images from the database.

For me it is the fact that I read through the php manual and have a hard time understanding what I will call mathematical terms .. I guess it’s like talking to a doctor and he uses medical terms, which to the average person means nothing .. then he repeats it in plain english .. whamo it all makes sense straight away .. I guess in these forums .. when someone explains in another manner or shows the answer in code .. its like the doc just told you the term in plain old english ..

Anyway .. Thanks for your input .. Please class it as greatly appreciated.

Thanks

Jimbo
Last edited by Jim_Bo on Mon Apr 04, 2005 11:55 pm, edited 1 time in total.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

Well, I'm glad that you actually listen like so few ever do.. But keep in mind, even the most mathematically correct person can't learn everything there is about a language in a few days.

More than anything, coding takes patience and the mentality of never giving up. Coding is not easy, I don't care what language you use (well..except for maybe Basic/Html ;) ). In any case, if you haven't been coding in php for long, then you really shouldn't know how to do the more advanced things yet as you haven't ever had the need to do them. But where you are messing up is, instead of learning these techniques, you are finding someone's code, trying to get it to work, and when ti doesn't, you get lost going through all the functions you don't know and just give up and post it here.

That's where you are going wrong. People do it all the time. However, the way to become a more proficient coder is not to give up and have someone else fix the code for you, all the while not learning anything. The best way is to say "ok, what in the hell is GD", do a search on google and php.net, and read up on it, or even go so far as to spend a measly 60 bucks and get a book dedicated to php&mysql development (there are threads on the boards that can recommend a lot of good ones too..). If you can't learn by reading, and you can't pick up by example, the only other alternative is to try a php class (which are very, very hard to find).

And even if all these things fail, the very worst thing you can do is give up. You want to learn how to code, and that is what brought you to php. Therefore, you have the drive. The only thing you need to do now is say "ok, I'm not gonna think of this as impossible anymore. If this many people can learn this crap, I can too", and then just do it.

I learned by just jumping in head over heals into the middle of it, and working my way out on both sides of the language. Others will learn better by starting with the simple syntax's (if, else, define variable, mysql commands, etc).

The best approach though, is to determine what you think your strong point is in php. What is it you know the most about? Then, try to prove it by explaning how the function(s) you think you know a lot about work. If you can accurately explain their meanings, then find a function (just 1) that you know nothing about that's in the code you just posted. Array would be a really good one because there are a LOT of things you can do with an array tahn simply storing 1 piece of data per 1 key.

Maybe even learning more about the mysql commands would be great.

But eventually, you are gonna need to learn how GD works (and no, not the inside and out of it, but enough to get the job done).

Everyone I talk to who says coding is hard simply says it's hard cuz they think they need to understand each and every concept that a coding language has to offer and to me, that's just ridiculous. It's good to know them, but it s not by any means necessary.

Anyways, try what i said. At first, it's gonna get over whelming, ur not gonna think you can do it, but as you go and you learn a new function, try it out, and see it work, you gain confidence in yourself to want to learn more.

However, if you find yourself not wanting to learn any of it, or simply don't feel a drive for it, then you may need to accept the fact that coding just simply isn't for you.

In any case, ur gonna need to do something about your knowledge of php in general, or you aren't gonna get anywhere with it. Hope this helps you out man, and good luck!
Post Reply