Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 25th, 2004, 12:58 PM
Authorized User
 
Join Date: Jul 2004
Location: rajshahi, , Bangladesh.
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rajuru Send a message via Yahoo to rajuru
Default include file error

in my index.php file i used include function

<?php include ('ads/result/ads.php'); ?>

in ads.php I used to this code

<?php
$add="add";
$add .=mt_rand(1,2);
$add .=".jpg";
echo "<img border='0' src='$add'>";
?>

but it does not show any picture.

the <img> tag src value should be if random function generates value 1

<img src="ads/result/add1.jpg">
but the src value i see,

<img src="add1.jpg">

how i can solve this problem




Best Regard:
Md. Zakir Hossain (Raju)
www.rubd.net
www.xenex.rubd.net
www.forum.rubd.net
__________________
Best Regard:
Md. Zakir Hossain (Raju)

www.rajuru.xenexbd.com - my blog with PHP scripts, PHP Book Review and many more
 
Old December 27th, 2004, 02:57 AM
Authorized User
 
Join Date: Feb 2004
Location: Karachi, , Pakistan.
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to knight
Default

dear as i think the following line should be
$add .=mt_rand(1,2);
$add .=".jpg";
--------------
this right syntax is
$add=.mt_rand(1,2);
$add=.".jpg";

try this
:)


 
Old December 27th, 2004, 05:35 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

what is wrong? $add="add";
use $add="/images/add"; or echo "<img border='0' src='/images/$add'>";
or whatever is ur images folder.

but, u r using echo "<img border='0' src='$add'>";($add is not a path)

 
Old December 27th, 2004, 05:28 PM
Authorized User
 
Join Date: Dec 2004
Location: Tunkhannock, PA, USA.
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to peg110
Default

Quote:
quote:Originally posted by knight
 dear as i think the following line should be
$add .=mt_rand(1,2);
$add .=".jpg";
--------------
this right syntax is
$add=.mt_rand(1,2);
$add=.".jpg";

try this
:)

Atually

  $add .=mt_rand(1,2);
  $add .=".jpg";

IS the correct syntax. I am not saying that the =. won't work, but it DIDN'T work on my system.

Paul Gardner
------------------
PHP-LIVE help
Via Web @ http://www.mnetweb.co.uk/irc
Via IRC Client pgardner.net:6667
room #PHP
 
Old December 28th, 2004, 05:01 AM
Authorized User
 
Join Date: Jul 2004
Location: rajshahi, , Bangladesh.
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rajuru Send a message via Yahoo to rajuru
Default

Thanks Knight for your time. but your concatenation syntax is not right. (dot). must precede = sign
Peg is right

ahsanul did not understand my problem.
there are three images in my directory
add1.jpg
add2.jpg
add3.jpg

so i used the code
$add="add";
$add.=mt_rand(1,3);
$add.=".jpg";
if second line code generates a random value such as 2 then the final value of $add is add2.jpg
now i echo the variable with img tag
echo "<img src=$add>";
my codes are very fine if i run the ads.php file directly
but problem is when i include this file from another file (not in same path)

i think all of you can understand me now

Best Regard:
Md. Zakir Hossain (Raju)
www.rubd.net
www.xenex.rubd.net
www.forum.rubd.net
 
Old December 28th, 2004, 09:52 AM
Authorized User
 
Join Date: Dec 2004
Location: Tunkhannock, PA, USA.
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to peg110
Default

because your script runs relative to the scripts location, you must put the path to the images relative from the point where the script is located and not where the INCLUDED file is located. So anshul is correct (with the exception that his path is different then the one you desire.)
You could do this one of 2 ways: (again as anshul suggested)


  <?php
    $add="ads/result/add";
    $add .=mt_rand(1,2);
    $add .=".jpg";
    echo "<img border='0' src='$add'>";
  ?>


or


  <?php
    $add="add";
    $add .=mt_rand(1,2);
    $add .=".jpg";
    echo "<img border='0' src='ads/result/$add'>";
  ?>


Either one should give you the results you want.

Paul Gardner
------------------
PHP-LIVE help
Via Web @ http://www.mnetweb.co.uk/irc
Via IRC Client pgardner.net:6667
room #PHP
 
Old December 29th, 2004, 03:06 PM
Authorized User
 
Join Date: Jul 2004
Location: rajshahi, , Bangladesh.
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rajuru Send a message via Yahoo to rajuru
Default

yes peg110

i can do this if you use ads.php from only one location.

but i want to use it from different page at different location.


Best Regard:
Md. Zakir Hossain (Raju)
www.rubd.net
www.xenex.rubd.net
www.forum.rubd.net
 
Old December 29th, 2004, 04:52 PM
Authorized User
 
Join Date: Dec 2004
Location: Tunkhannock, PA, USA.
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to peg110
Default

then make the path ABSOLUTE instead of relative.

i.e.

<?php
    $add="/wwwroot/ads/result/add";
    $add .=mt_rand(1,2);
    $add .=".jpg";
    echo "<img border='0' src='$add'>";
  ?>


obviously my "Absolute" path is not necessarily your absolute path.


Paul Gardner
------------------
PHP-LIVE help
Via Web @ http://www.mnetweb.co.uk/irc
Via IRC Client pgardner.net:6667
room #PHP
 
Old December 30th, 2004, 04:48 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

when you include files path will be taken from the file in which you included other file, not from the included file.

 
Old December 31st, 2004, 11:57 AM
Authorized User
 
Join Date: Jul 2004
Location: rajshahi, , Bangladesh.
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rajuru Send a message via Yahoo to rajuru
Default

thanks peg110
i also decided this option

anshul, it is not matter while using absolute path, I think

Best Regard:
Md. Zakir Hossain (Raju)
www.rubd.net
www.xenex.rubd.net
www.forum.rubd.net




Similar Threads
Thread Thread Starter Forum Replies Last Post
Include file morpheus BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 April 23rd, 2006 08:20 AM
difference between include file & include virtual crmpicco Classic ASP Basics 2 January 23rd, 2006 11:50 AM
Include File morpheus Beginning PHP 8 January 17th, 2006 09:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.