Rheanna Posted October 3, 2015 Share Posted October 3, 2015 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? Quote Link to comment Share on other sites More sharing options...
hansford Posted October 3, 2015 Share Posted October 3, 2015 (edited) 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 October 3, 2015 by hansford Quote Link to comment Share on other sites More sharing options...
scootstah Posted October 3, 2015 Share Posted October 3, 2015 Why are you using output buffering and then echo'ing it 4 lines later? Completely unnecessary. What are you trying to achieve with your code? What problem are you trying to solve? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted October 3, 2015 Share Posted October 3, 2015 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'>"; Quote Link to comment Share on other sites More sharing options...
Rheanna Posted October 3, 2015 Author Share Posted October 3, 2015 <?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? Quote Link to comment Share on other sites More sharing options...
Rheanna Posted October 3, 2015 Author Share Posted October 3, 2015 I need it to be a variable, because the background image can change based on the page it is on. Quote Link to comment Share on other sites More sharing options...
scootstah Posted October 3, 2015 Share Posted October 3, 2015 echo get_additional($tcgname,'Trades'); Can we see what that function does? Quote Link to comment Share on other sites More sharing options...
Barand Posted October 3, 2015 Share Posted October 3, 2015 ... but it's still pulling an error because of this line: echo '<div class="tboxout" style="background: url('$tcgimg')">'; ginerjm told you what was wrong with that line (in reply #4)and re-wrote it for you Quote Link to comment Share on other sites More sharing options...
Rheanna Posted October 3, 2015 Author Share Posted October 3, 2015 his code didn't work either Quote Link to comment Share on other sites More sharing options...
scootstah Posted October 3, 2015 Share Posted October 3, 2015 We cannot see your screen. You're going to have to be more specific when you say things like "didn't work". Quote Link to comment Share on other sites More sharing options...
hansford Posted October 3, 2015 Share Posted October 3, 2015 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>'; Quote Link to comment Share on other sites More sharing options...
Rheanna Posted October 3, 2015 Author Share Posted October 3, 2015 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.')">'; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.