PDA

View Full Version : looping through DB and displaying captions via JS/PHP


deafboyzaudio
01-26-2010, 12:54 AM
Wasn't sure whether to put this in JS or PHP since it involves both so here goes....

I have done some mods so that I can use php code in my JS....
I use it to dynamically pull the caption for a pic from the DB.The problem is that I keep getting the same caption for each pic.

This is what I have for the actual pics....on the main page$query = "SELECT * FROM pics";
mysql_select_db($database_db294582132, $db294582132);
$result = mysql_query($query, $db294582132) or die(mysql_error());

while($row = mysql_fetch_assoc($result)){
//get the name and caption for the main image
$big_image = $row['pic_filename'];
$thumbnail = $row['pic_t_filename'];
$caption = $row['pic_caption'];
//$per_column = 5;
echo '<a class="photo-link" rel="one-big-group" href="images/uploads/',$big_image,'.jpg"><img src="images/uploads/thumbs/',$thumbnail,'.jpg" width="100" height="75" alt="',$caption,'"/></a>'; if($count % 5 == 0) { echo '<div class="clear"></div>'; }
} NOW, I have a separate file with my JS used to display the pics that is included via php.
this is the code for the loop through the DB to get the captions that i have:require_once('Connections/db294582132.php');
$query = "SELECT * FROM pics";
mysql_select_db($database_db294582132, $db294582132);
$result = mysql_query($query, $db294582132) or die(mysql_error());

while($row = mysql_fetch_assoc($result)){
//get the name and caption for the main image
$big_image = $row['pic_filename'];
$thumbnail = $row['pic_t_filename'];
$caption = $row['pic_caption'];
}THen there is some JS and then this particular JS code is what formats the divs for the captions:
$('<div id="fancy_bg"><div class="fancy_bg fancy_bg_n"></div><div class="fancy_bg fancy_bg_s"><?php echo $caption;?></div><div class="fancy_bg fancy_bg_w"></div></div>').appendTo("#fancy_inner");As you can see the $caption is displayed dynamically from the DB...

I have a felling that the reason im getting the same caption for each pic is b/c the JS that generates the pics is not included in my loop, (like the main pic page keeps looping through the DB and formatting each result with html)

My PROBLEM is that im not sure how to do this, tried a bunch of stuff with no luck.

How would I put the JS used to create each div & caption in my loop so that I can get the correct caption for each pic?

deafboyzaudio
02-03-2010, 08:55 PM
I still need help with this....

I can display the last caption in the DB with each pic.... but thats not what i want.

How do I do the loop through the DB and include the JS formatting in the loop each and every time... you know, just like my main page does(see first code block)

I cant get the syntax right to make it work.... any help? thanks in advance