hi every body

i have template that it contains this type of java script for displaying wallpaper in the main screen :

<!-- JAVASCRIPT TRIGGERS -->
	<script type="text/javascript">	
		$(document).ready(function(){
			$("a[rel^='prettyPhoto']").prettyPhoto({
				theme: 'dark_square'
			});
		});	
		
		$.backstretch("images/background-home.jpg", {speed: 'slow'});		
	</script>

and i wanna change it to this form :

<!-- JAVASCRIPT TRIGGERS -->
	<script type="text/javascript">	
		$(document).ready(function(){
			$("a[rel^='prettyPhoto']").prettyPhoto({
				theme: 'dark_square'
			});
		});	
		
		$.backstretch("<? include "banner.php"; ?>", {speed: 'slow'});		
	</script>

but the problem is here because it doesn't work
i tested it in banner.php page and it is worked correctly and i don't have any problem with it .

banner.php :

<?php
include"db.php";

$sql=mysql_query("select * from banner where tf='1' ");

$r=mysql_fetch_array($sql);

	$name=$r['name'];

echo"<img src=\"admin/banner/images/$name\" width=\"1440\" height=\"900\">";
?>

is there any body to help me please ???

Recommended Answers

All 11 Replies

Check what values did the include insert. You can do it with any normal browser (like firebug plugin for firefox). Also could be that you have opened the PHP part with <? instead of <?php

Try the following:

<!-- JAVASCRIPT TRIGGERS -->
	<script type="text/javascript">	
		$(document).ready(function(){
			$("a[rel^='prettyPhoto']").prettyPhoto({
				theme: 'dark_square'
			});
		});	
		
		$.backstretch("<?php include ('banner.php'); ?>", {speed: 'slow'});		
	</script>
<?php
include"db.php";

$sql=mysql_query("select * from banner where tf='1' ");

$r=mysql_fetch_assoc($sql);

echo 'admin/banner/images/'.$r['name'];
?>

It doesn't work yet !!!!!


please it is necessary for me !!!

I wanna display the image in the main page too, the problem is for using php command in java script ...

It doesn't work yet !!!!!


please it is necessary for me !!!

I wanna display the image in the main page too, the problem is for using php command in java script ...

Are there any php errors or warnings? View the source if they aren't appearing in the browser to find the warnings php is generating and post them here. Also both files should end in .php . It is essential that they both end in .php otherwise php will not phrase them. But other than that, without much more debugging information there isn't a lot we can do.

I am familiar with these details

i was create 2 pages that named : index1.php banner.php

<!DOCTYPE html>
<html lang="en">
<head>
	
	<title>Sideways</title> 
	<meta charset="utf-8" />
	<meta name="description" content="" > 
	<meta name="keywords" content="" >
	
	<link rel="shortcut icon" href="http://templates.raw-brand.com/favicon.ico" /> 

	<!--[if lt IE 9]>
		<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
	<![endif]-->
	
	<!-- CSS -->
	<link rel="stylesheet" href="style.css" media="all" />
	<link rel="stylesheet" href="css/prettyPhoto_v.css" media="screen" />
	<!--[if lt IE 9]>
		<link rel="stylesheet" href="css/ie7.css" media="screen" />
	<![endif]-->
	
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body,td,th {
	font-family: Tahoma, Geneva, sans-serif;
}
</style>
</head>
<body>
<? include "db.php"; ?>
	<!-- JAVASCRIPTS -->
<script src="ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="js/raw.js"></script>
<script src="js/jquery.prettyPhoto.js"></script>
<script src="js/jquery.backstretch.min.js"></script>
	
	<!-- JAVASCRIPT TRIGGERS -->
	<script type="text/javascript">	
		$(document).ready(function(){
			$("a[rel^='prettyPhoto']").prettyPhoto({
				theme: 'dark_square'
			});
		});	
 
		$.backstretch("<?php include ('banner.php'); ?>", {speed: 'slow'});		
	</script>
    
<div id="wrapper">
	
	<!-- SEARCH BAR -->
	<div id="searchbar-holder">
	
		<div id="searchbar">
			
			<ul class="search">
				<li class="widget_search">
					<form method="get" class="searchform" action="#">
						<fieldset>
							<input class="searchsubmit" type="submit" value="Search">
							<input class="text s" type="text" value="" name="s">							
						</fieldset>
					</form>
				</li>
			</ul>
			
			<!-- SOCIAL BUTTONS -->
			<div id="share">
			
				<a href="#" class="share-button"><span>Share</span></a>
				
				<div id="share-box">
					
					<div id="share-holder" align="right" dir="rtl" title="قیمت ها بر حسب ریال می باشند">
						
						<script src='http://ghatreh.com/news/getarz.php'></script>
						
					</div>
				
				</div>
				
			</div>
			
		</div>
		
	</div>
	
  <div id="sidebar">
		
		<!-- LOGO -->
		<header>
		
			<img src="images/logo.png" alt="Website Logo" />
		
			<h1></h1>
			<h2></h2>
		
		</header>
		
		<!-- NAVIGATION -->
	<nav>		
			
			<ul id="navigation">
			
				<li><a href="home.html">Home</a></li>
				<li><a href="page.html">Templates</a>
					<ul>
						<li><a href="home.html">Home</a></li>
						<li><a href="blank.html">Blank</a></li>
						<li><a href="page.html">Page</a></li>
						<li><a href="full-width.html">Full Width</a></li>
						<li><a href="single.html">Single</a></li>
						<li><a href="blog.html">Blog</a></li>
						<li><a href="portfolio-horizontal.html">Horizontal Portfolio</a></li>
						<li><a href="portfolio-grid.html">Grid Portfolio</a></li>
						<li><a href="gallery.html">Gallery</a></li>
						<li><a href="contact.html">Contact</a></li>
					</ul>
				</li>
				<li><a href="typography.html">Typography</a>
					<ul>
						<li><a href="columns.html">Columns</a></li>
					</ul>
				</li>
				<li><a href="blog.html">Blog</a></li>
				<li><a href="portfolio-grid.html">Portfolios</a>
					<ul>
						<li><a href="portfolio-horizontal.html">Horizontal Portfolio</a></li>
						<li><a href="portfolio-grid.html">Grid Portfolio</a></li>
					</ul>
				</li>				
				<li><a href="contact.html">Contact</a></li>
			
			</ul>
			
			<a href="#" id="expand-button" class="collapse">Navigation</a>
			
	  </nav>
	
	</div>
	
</div>

<!-- FOOTER -->
<footer>
	
	<nav>
		
		<ul>
			<li><a href="#">Home</a></li>
			<li><a href="#">About</a></li>
			<li><a href="#">Services</a></li>
			<li><a href="#">Blog</a></li>
			<li><a href="#">Contact</a></li>
		</ul>
		
	</nav>
	
	<p>&#169; 2011 Sideways. All rights reserved.</p>
	
</footer>

</body>
</html>

there are all of the commands that i used in my ( index1.php ) page

is there any way to changing the codes i don't know i feel some things missing ...

you need to remove include "db.php"; from the one you highlighted in red because when it comes to banner.php db.php gets included again which currently causes an error. Perhaps that's your problem and php should have spat an error out about that. You should really go to view->source and check what is happening in that section of the source.

the problem is it that i didnt see any warning or error msgs

also i was wrote the include command in the outside of java tags and surprisingly it worked correctly with/without include "db.php"; in (index1.php) so please excuse my question again is there any way to changing the codes and writing the php code outside of java script tags ?????

You could take a different approach and make your banner.php output itself as an image, this requires the GD library to be installed on your php server which is pretty common now.

<?php
include"db.php";

$id = $_GET['image'];
if(!ctype_digit($id)){$id=0;}
$sql=mysql_query("select * from banner where `id`='{$id}' ");
$r=mysql_fetch_assoc($sql);
 
$target = 'admin/banner/images/'.$r['name'];
$dotcount = substr_count($target,'.');
$splitstr = explode('.',$target);
$imagetype = $splitstr[$dotcount];
//echo $imagetype;
$url = $target;//might want to add direct link
$imagetype = strtolower($imagetype);
if($imagetype == 'jpg' || $imagetype == 'jpeg'){
	try {$im = @imagecreatefromjpeg($url);}
		catch (Exception $e){
		}
}elseif($imagetype == 'gif'){
	try {$im = @imagecreatefromgif($url);}
		catch (Exception $e){
		}
}elseif($imagetype == 'png'){
	try {$im = @imagecreatefrompng($url);}
		catch (Exception $e){
		}
}else{
}
if(!$im){
	// Create a blank image 
	$im = imagecreatetruecolor (150, 30);
	$bgc = imagecolorallocate ($im, 255, 255, 255);
	$tc = imagecolorallocate ($im, 0, 0, 0);
			
	imagefilledrectangle ($im, 0, 0, 150, 30, $bgc);
			
	// Output an error message 
	imagestring ($im, 1, 5, 5, $message, $tc);
	$imagetype = 'gif';
}
if($imagetype == 'jpg' || $imagetype == 'jpeg'){
	Header('Content-Type: image/jpeg'); 
	imagejpeg($im);imagedestroy($im);
}elseif($imagetype == 'gif'){
	Header('Content-Type: image/gif');
	imagegif($im);imagedestroy($im);
}elseif($imagetype == 'png'){
	Header('Content-Type: image/png');
	imagepng($im);imagedestroy($im);
}
?>

after making that you need to save it to what you like ( admin/banner/images/image.php would make it easy)change the javascript line

$.backstretch("images/background-home.jpg", {speed: 'slow'});
to 
$.backstretch("admin/banner/images/image.php?image=*dbid*", {speed: 'slow'});

However while looking back up for your database setup i realised the error is probably cause your php is outputting doublequotes and erroring your js

$.backstretch("<img src="admin/banner/images/image.jpg" width="1440" height="900">", {speed: 'slow'})

making all that image stuff obsolete, but would make it easy to access images whenever you like

thanks my friend but there is an error in the line 17 .

Parse error: parse error, unexpected '{' in w:\easyphp1-7\www\turk-marka\banner.php on line 17

it seems difficult to understand for me but i hope it will work

ah maybe it doesn't understand 'try', it was introduced in php 5

you could replace that section with

if($imagetype == 'jpg' || $imagetype == 'jpeg'){
	$im = @imagecreatefromjpeg($url);
}elseif($imagetype == 'gif'){
	$im = @imagecreatefromgif($url);
}elseif($imagetype == 'png'){
	$im = @imagecreatefrompng($url);
}else{
}

you can run phpinfo(); to view all your php server settings, simply "phpinfo();" by itself and it exits and displays php data - it will tell you if GD library is installed and running.

btw the '@' symbol suppresses error's so you might want to take it off for testing

Maybe using the files on your first post you could using the following banner.php

<?php
include_once "db.php"; //probably not needed

$sql=mysql_query("select * from banner where tf='1' ");

$r=mysql_fetch_array($sql);

	$name=$r['name'];

echo"<img src='admin/banner/images/$name' width='1440' height='900'>";
?>
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.