Jump to content

[SOLVED] PHP do x2


amwd07

Recommended Posts

I not sure if we are talking nested regions here, or how to change my code?

 

<?php do { 
$commentid = $row_rs3['rating_id']; //// this coming from another recordset this bit is correct
mysql_select_db($database_connDW, $connDW);
$query_rs4 = "SELECT * FROM restaurant_ratings WHERE rating_id = '$commentid'";
$rs4 = mysql_query($query_rs4, $connDW) or die(mysql_error());
$row_rs4 = mysql_fetch_assoc($rs4);
$totalRows_rs4 = mysql_num_rows($rs4);
$name = $row_rs4['name'];
$created = $row_rs4['created'];
$title = $row_rs4['title'];
$comments = $row_rs4['comments'];
$commentid = $row_rs4['rating_id'];
?>

/// code on page ///

<?php do { 
mysql_select_db($database_connDW, $connDW);
$query_rs5 = "SELECT * FROM restaurant_comments WHERE rating_id = '$commentid'";
$rs5 = mysql_query($query_rs5, $connDW) or die(mysql_error());
$row_rs5 = mysql_fetch_assoc($rs5);
$totalRows_rs5 = mysql_num_rows($rs5);
$cmessage = $row_rs5['message'];
$cname = $row_rs5['name'];
$ccreated = $row_rs5['created']; 
?>
        
<p><strong><?php echo $cname ?></strong> comments <br>
<?php echo $ccreated ?><br>
<?php echo $cmessage ?></p>
                
<?php } while ($row_rs5 = mysql_fetch_assoc($rs5)); 
mysql_free_result($rs5); ?>

/// code on page ///


<?php } while ($row_rs3 = mysql_fetch_assoc($rs3)); 
mysql_free_result($rs4);
?>

Link to comment
Share on other sites

All I need is to have a repeat region for my ratings and each ratings would have a repeat region for the comments on that rating

 

rs3 is to link them by the outlet

rs4 is the ratings

rs5 is the comments

 

It works until I put the rs5 in then the script times out?

 

 

<?php do {

 

<?php do {

<?php } while ($row_rs5 = mysql_fetch_assoc($rs5));

 

<?php } while ($row_rs3 = mysql_fetch_assoc($rs3));

Link to comment
Share on other sites

rs5 will neverend, as it starts the search over evertime

 

/// code on page ///
<?php 
/*MOVED out of loop*/
mysql_select_db($database_connDW, $connDW);
$query_rs5 = "SELECT * FROM restaurant_comments WHERE rating_id = '$commentid'";
$rs5 = mysql_query($query_rs5, $connDW) or die(mysql_error());
$row_rs5 = mysql_fetch_assoc($rs5);
$totalRows_rs5 = mysql_num_rows($rs5);


while ($row_rs5 = mysql_fetch_assoc($rs5))
{ 
$cmessage = $row_rs5['message'];
$cname = $row_rs5['name'];
$ccreated = $row_rs5['created']; 
?>
        
<p><strong><?php echo $cname ?></strong> comments <br>
<?php echo $ccreated ?><br>
<?php echo $cmessage ?></p>
                
<?php
}
mysql_free_result($rs5); ?>

 

**UPDATED.. try the above

Link to comment
Share on other sites

you don't need the do unless you have the condition at the end of the loop.. as you need the condition at the start (to set $row_rs5) do is unneed..

as for the results i have to assume their are connect..

 

you could try this

echo $query_rs5; //<--Add this
while ($row_rs5 = mysql_fetch_assoc($rs5))

then copy the statement into PMA and run it..

Link to comment
Share on other sites

got it working looks like I did need the do in after all ;D ;D ;D

 

<?php 
mysql_select_db($database_connDW, $connDW);
$query_rs5 = "SELECT * FROM restaurant_comments WHERE rating_id = '$commentid'";
$rs5 = mysql_query($query_rs5, $connDW) or die(mysql_error());
$row_rs5 = mysql_fetch_assoc($rs5);
$totalRows_rs5 = mysql_num_rows($rs5);

do
{ 
$cmessage = $row_rs5['message'];
$cname = $row_rs5['name'];
$ccreated = $row_rs5['created']; 
?>
        
<p><strong><?php echo $cname ?></strong> comments <br>
<?php echo $ccreated ?><br>
<?php echo $cmessage ?></p>
                
<?php
} while ($row_rs5 = mysql_fetch_assoc($rs5));
mysql_free_result($rs5); ?>

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.