Jump to content

What am I doing wrong?


Rheanna

Recommended Posts

I have this code:

<?php
 //get_additional is a custom funcion
ob_start();
echo get_additional($tcgname,'Trades');
echo nl2br("\n");
echo '<div class="tboxout" background='$tcgimg'>';
echo '<div class="tboxin">';
$buffered = ob_get_clean();
echo $buffered;
$times = $buffered;
$imgurl = 'myimage.png';

for($i=0;$i<$times;$i++){
    echo '<img src="'.$imgurl.'" />';
}
echo '</div>';
echo '</div>';
?>

and I reference it on a separate page, with this code:

<?php 
$tcgname = "Cosmos";
$tcgimg = "wantedbackgroundimage.png";
?>

<?php include("/stamps.php"); ?>
// this is the name of the first file

For some reason the background image is not showing up at all and I can't figure out why. Can anybody explain to me why this isn't working?

Link to comment
Share on other sites

Let's examine what the code is doing.

 //get_additional is a custom funcion
ob_start(); // start output buffering
echo get_additional($tcgname,'Trades');
echo nl2br("\n");
echo '<div class="tboxout" background='$tcgimg'>';
echo '<div class="tboxin">';
$buffered = ob_get_clean(); // get contents of output buffer
echo $buffered;  // echo contents
$times = $buffered;  // assign $times the contents of output buffer
$imgurl = 'myimage.png';

// this never runs as $times in not a digit higher than 1
// $times was assigned the contents of the output buffer
for($i=0;$i<$times;$i++){    
    echo '<img src="'.$imgurl.'" />';
}
Edited by hansford
Link to comment
Share on other sites

This line:

 

echo '<div class="tboxout" background='$tcgimg'>';
 

isn't going to do what you think.  Your background isn't going to anything.  Need double quotes around a string containing a php var, or double quotes around the var itself.

echo "<div class='tboxout' background='$tcgimg'>";
 

Link to comment
Share on other sites

<?php
 //get_additional is a custom funcion
ob_start();
echo get_additional($tcgname,'Trades');
echo nl2br("\n");
echo '<div class="tboxout" style="background: url('$tcgimg')">';
echo '<div class="tboxin">';
$buffered = ob_get_clean();
echo $buffered;
$times = $buffered;
$imgurl = 'http://rheanna.magical-me.net/cosmos/cosmoscards/check.png';

for($i=0;$i<$times;$i++){
    echo '<img src="'.$imgurl.'" />';
}
echo '</div>';
echo '</div>';
?>

I fixed what I found wrong with it, the style tags in the div, but it's still pulling an error because of this line:

echo '<div class="tboxout" style="background: url('$tcgimg')">';

The whole purpose of this code is to take an image and repeat it based on the number pulled by 

echo get_additional($tcgname,'Trades');

The problem I'm having is posting a background image to the div that encases the repeating image div. Does that make sense?

Link to comment
Share on other sites

It doesn't even appear you need output buffering. I ran a mock-up of your code using the following and it works fine.

//get_additional is a custom funcion

$times = get_additional($tcgname,'Trades'); // this should be returning an integer value
echo "<div class='tboxout' style='background: url($tcgimg);'>";
echo '<div class="tboxin">';
$imgurl = 'http://rheanna.magical-me.net/cosmos/cosmoscards/check.png';

for($i=0;$i<$times;$i++){
    echo '<img src="'.$imgurl.'" />';
}
echo '</div>';
echo '</div>';
Link to comment
Share on other sites

I finally figured out what I was doing wrong!! It was super simple and totally not worth stressing over:

 

All I had to do was change this:

echo '<div class="tboxout" style="background: url('$tcgimg')">';

to this:

echo '<div class="tboxout" style="background: url('.$tcgimg.')">';
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.