Jump to content

click photo. go to next records in db? php or javascript?


Guest ldexterldesign

Recommended Posts

Guest ldexterldesign

hi guys,

 

i have, what i suspect, is a fairly basic task to perform, it's just i'm not sure how to approach it – client-side or server-side?

 

i load in an image (filename) from the db dynamically along with an image caption. my code is outlined below:

 

  <!-- begin content -->
  <div class="content">
    <div class="gallery_image"><img src="images/gallery/music_sized/<?php echo $row_gallery_musicGetRecords['image']; ?>" alt="<?php echo $row_gallery_musicGetRecords['image_alt_text']; ?>" /></div>
    <div class="caption">
      <p><?php echo $row_gallery_musicGetRecords['caption']; ?></p>
    </div>
  </div>
  <!-- end content -->

 

my header code, accessing the db 'n what not is below:

 

<?php require_once('Connections/emmadalzell.php'); ?>
<?php
mysql_select_db($database_emmadalzell, $emmadalzell);
$query_gallery_musicGetRecords = "SELECT * FROM gallery_music";
$gallery_musicGetRecords = mysql_query($query_gallery_musicGetRecords, $emmadalzell) or die(mysql_error());
$row_gallery_musicGetRecords = mysql_fetch_assoc($gallery_musicGetRecords);
$totalRows_gallery_musicGetRecords = mysql_num_rows($gallery_musicGetRecords);
?>

 

i'd like the image and caption (i.e the record in the db) to continue to the next one on every click of the photo.

 

atm, the only thing i can think to do would be to print out each record's array:

 

<?php print_r($row_gallery_musicGetRecords); ?>

 

... take this and use javascript to build the 'onclick event' and go to the next array element; loading in the respective image filename and caption into the 'gallery_image' div class outlined above.

 

a kick start with this from anyone experienced, or alternatively a refreshing approach would be really appreciated.

 

lewis

Guest ldexterldesign

ok, after some thought i've decided as long as i can extract this kind of information from/for each record of the db i can construct something client-side with javascript:

 

<img src="images/[dynamic:image0.jpg]" alt="[alt text0]" />

<img src="images/[dynamic:image1.jpg]" alt="[alt text1]" />

<img src="images/[dynamic:image2.jpg]" alt="[alt text2]" />

<img src="images/[dynamic:image2.jpg]" alt="[alt text3]" />

...

 

atm, this code spits out all the values i need from the 'row_gallery_musicGetRecords' array:

 

        <?php do { ?>
          <?php foreach ($row_gallery_musicGetRecords as $value) {
	  	print "$value\n";
		}?>
          <?php } while ($row_gallery_musicGetRecords = mysql_fetch_assoc($gallery_musicGetRecords)); ?>

 

... gives me xhtml:

 

      <p>

                  14 - record id (not sure how to omit this?)

nathan_fake5.jpg - dynamic:image0.jpg

gdhnmhn - alt text0

gndfgdh - caption

                    15 - record id (not sure how to omit this?)

animal_collective.jpg - dynamic:image1.jpg

animal - alt text0

animal - caption

                </p>

 

could someone aid me in turning this:

 

      <p>
                  14
nathan_fake5.jpg
gdhnmhn
gndfgdh
                    15
animal_collective.jpg
animal
animal
                </p>

 

into this:

 

<img src="images/nathan_fake5.jpg" alt="gdhnmhn" />

<img src="images/animal_collective.jpg" alt="animal" />

...

 

hope this makes sense,

lewis

Guest ldexterldesign

ok, realised my coding was far more elaborate than it needed to be.

 

      <?php
		do {
		?>
      <img src="images/gallery/music_sized/<?php echo $row_gallery_musicGetRecords['image']?>" alt="<?php echo $row_gallery_musicGetRecords['image_alt_text'];?>" />
      <?php
		} while ($row_gallery_musicGetRecords = mysql_fetch_array($gallery_musicGetRecords));
	?>

 

simply dropped in the dynamic bits i needed (image file name and alt text fields) into the generated xhtml (<img src="images/gallery/music_sized/['dynamic:image']" alt="['dynamic:image_alt_text']" />) and put that through a do while loop, looping for every row.

 

now i get clean img and alt tag elements generated.

 

hope this helps someone in the future.

 

lewis

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.