Jump to content

[SOLVED] Proper syntax to dynamically generate lines of code


imimin

Recommended Posts

I just need my output to print like this:

 

fadeimages[0]=["http://www.patternsofjoy.com/images/thumbs/POJ00210.jpg", "", ""]
fadeimages[1]=["http://www.patternsofjoy.com/images/thumbs/POJ00222.jpg", "", ""]
fadeimages[2]=["http://www.patternsofjoy.com/images/thumbs/POJ00224.jpg", "", ""]

 

maybe my choice of words was not correct when I mentioned putting a <BR> between each line.  I just assumed that is what I needed to get the output to look like the above output?

Thank you!

 

I set it up like this:

 

<?php

/*$cat = mysql_real_escape_string($_GET['cat']);*/
$cat='all';

$get_items = "SELECT * FROM poj_products WHERE cat='$cat'";
$get_items = mysql_query($get_items);
   while($item_row = mysql_fetch_assoc($get_items))
   {
   extract($item_row);
   echo 'fadeimages[0]=["http://www.patternsofjoy.com/images/thumbs/'.$item_row['img-no_path'].'", "", ""]';
   \n;
   }
?>

 

and I am still getting:

 

fadeimages[0]=["http://www.patternsofjoy.com/images/thumbs/POJ00241.jpg", "", ""]fadeimages[0]=["http://www.patternsofjoy.com/images/thumbs/POJ00256.png", "", ""]fadeimages[0]=["http://www.patternsofjoy.com/images/thumbs/POJ00257.png", "", ""]

You have absolute no clue as to what you're doing I assume?  ;)

 

echo 'fadeimages[0]=["http://www.patternsofjoy.com/images/thumbs/'.$item_row['img-no_path'].'", "", ""]' . '\n';

 

You need to learn the basics of both php and html it seems. Also, I would advice you to read about new line characters. <br> is a line break in html, nowhere else.

I just ordered a good book on the subject, looking for ward to it  8) !

 

Just tried the last code you gave me and now I get this as an output:

 

fadeimages[0]=["http://www.patternsofjoy.com/images/thumbs/POJ00241.jpg", "", ""]\nfadeimages[0]=["http://www.patternsofjoy.com/images/thumbs/POJ00256.png", "", ""]

Being generated server side so when you look at source on a web browser you see it.  It's the first part of a JS.  I know the code works with the JS, my only problem is at this point to get it to print correctly to:

 

fadeimages[0]=["http://www.patternsofjoy.com/images/thumbs/POJ00210.jpg", "", ""]
fadeimages[1]=["http://www.patternsofjoy.com/images/thumbs/POJ00222.jpg", "", ""]
fadeimages[2]=["http://www.patternsofjoy.com/images/thumbs/POJ00224.jpg", "", ""]

Yeah, I knew it was generated serverside but not where it was displayed, that is the only thing that matters  ;)

 

Now that we know it's javascript you're producing I was a bit too quick. \n will work fine but since you use single quotes for the echoed strings it will not work properly. You need to break out of them:

 

echo 'fadeimages[0]=["http://www.patternsofjoy.com/images/thumbs/'.$item_row['img-no_path'].'", "", ""]' . "\n";

 

That should do it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.