Jump to content

JQuery & PHP problem


son.of.the.morning

Recommended Posts

I am actauly mind blank on this one...

 

PHP & HTML

<?php 
				$rowNum = "0";
				while($record_rows = mysql_fetch_array($records_returned)){
					if(++$rowNum % 2 == 1 ) {


			?>
                <div class="Record">
                     <div id="VeiwRecord">More Details</div>
               </div>
                </div>
                 //THE HIDDEN DIV
                <div id="ViewMoreHidden"><?php echo substr($record_rows['post'], 0,500)."..."; ?></div>
                <?php } else {?>
                <div class="Record_i">
                    <div id="VeiwRecord">More Details</div>
               </div>
                //THE HIDDEN DIV
                <div id="ViewMoreHidden"><?php echo substr($record_rows['post'], 0,500)."..."; ?></div>
                <?php }} mysql_close();?>

 

JQUERY

$('document').ready(function() {

	$('#VeiwRecord').click(function() {
		$('#ViewMoreHidden').slideToggle(2000);

	});

});

Link to comment
Share on other sites

$('document').ready(function() {

	$('#VeiwRecord').each(function() {
                               $(this).click(function(){
                                               $('#ViewMoreHidden', this).slideToggle(2000);
                                                      }):


	});

});

 

havent tested it, but should point you in the right direction

Link to comment
Share on other sites

sorry, didnt look at your code properly. iterating over the worng thing:

 


$('document').ready(function() {

	$('.Record').each(function() {
                               $('#VeiwRecord',this).click(function(){
                                               $('#ViewMoreHidden', this).slideToggle(2000);
                                                      }):


	});

});

 

have a play round with that

Link to comment
Share on other sites

Here is the full php/html code

 

<?php 
				$rowNum = "0";
				while($record_rows = mysql_fetch_array($records_returned)){
					if(++$rowNum % 2 == 1 ) {


			?>
                <div class="Record">
                	<div class="Thumbnail"><img src="../img/articles/thums/<?php echo $record_rows['img_url']; ?>" class="RecordThumbnail"/></div>
                    <div class="RecordContent">
                    	<div class="PostTitle"><?php echo $record_rows['title']; ?></div>
                        <div class="PostSnipit"><?php echo substr($record_rows['post'], 0,50)."..."; ?></div>
                    </div>
                    <div class="SelectOptions">
                        <div class="DeleteRecord">Delete Article</div>
                        <div id="VeiwRecord">More Details</div>
                    </div>
                </div>
                <div id="ViewMoreHidden"><?php echo substr($record_rows['post'], 0,500)."..."; ?></div>
                <?php } else {?>
                <div class="Record_i">
                	<div class="Thumbnail"><img src="../img/articles/thums/<?php echo $record_rows['img_url']; ?>" class="RecordThumbnail"/></div>
                    <div class="RecordContent">
                    	<div class="PostTitle"><?php echo $record_rows['title']; ?></div>
                        <div class="PostSnipit"><?php echo substr($record_rows['post'], 0,50)."..."; ?></div>
                    </div>
                    <div class="SelectOptions">
                        <div class="DeleteRecord">Delete Article</div>
                        <div id="VeiwRecord">More Details</div>
                    </div>
                </div>
                <div id="ViewMoreHidden"><?php echo substr($record_rows['post'], 0,500)."..."; ?></div>
                <?php }} mysql_close();?>
            </div>

Link to comment
Share on other sites

he is correct, id's are meant to be unique, am javascript will only execute the first instance it finds, but using the each function correctly in jquery means you can refer to the Record divs child elements within a local scope. i have tried this locally and it works fine. treating each one individually:

<div class="Record">
<div id="VeiwRecord">click me</div>
<div id="ViewMoreHidden">Im hidden</div>
</div>

<div class="Record">
<div id="VeiwRecord">click me</div>
<div id="ViewMoreHidden">Im hidden</div>
</div>

<div class="Record">
<div id="VeiwRecord">click me</div>
<div id="ViewMoreHidden">Im hidden</div>
</div>

<div class="Record">
<div id="VeiwRecord">click me</div>
<div id="ViewMoreHidden">Im hidden</div>
</div>

$('document').ready(function() {

	$('.Record').each(function() {
		var obj = $(this);
                               $('#VeiwRecord',obj).click(function(){
                                               $('#ViewMoreHidden',obj).slideToggle(2000);
                                                     });


	});

});

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.