Link to home
Start Free TrialLog in
Avatar of piixeldesigns
piixeldesigns

asked on

Can't Display information in this while loop???

Hey All,

I am having some trouble with the below code as I can't seem to display the information in the while loop or any simply echo past this while line. Anything inside the while will not display anything above it will show and I have tested the query in the database and it works perfectly. Any help would be appreciated.

Here is my code:
$today = date("Y-m-d");
$result1 = mysql_query("
SELECT * FROM tbl_outing INNER JOIN bp_frieds
ON `tbl_outing`.`userid` = `bp_frieds`.`uid` 
WHERE startdate >= '$today' 
AND friendstype='Public' 
AND uid
IN (SELECT fuid FROM bp_frieds WHERE uid='$getuserData')
GROUP BY userid 
ORDER BY startdate, starttime DESC");

while ($row = mysql_fetch_array($result1)) {
    echo "test";
}

Open in new window


Thanks,
PD
ASKER CERTIFIED SOLUTION
Avatar of Chris Harte
Chris Harte
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try with error reporting:

$today = date("Y-m-d");
$result1 = mysql_query("
SELECT * FROM tbl_outing INNER JOIN bp_frieds
ON `tbl_outing`.`userid` = `bp_frieds`.`uid` 
WHERE startdate >= '$today' 
AND friendstype='Public' 
AND uid
IN (SELECT fuid FROM bp_frieds WHERE uid='$getuserData')
GROUP BY userid 
ORDER BY startdate, starttime DESC") or die(mysql_error);

while ($row = mysql_fetch_array($result1)) {
    echo "test";
}

Open in new window


I suspect there's something wrong with the ' signs around field names
should be
ORDER BY startdate, starttime DESC") or die(mysql_error());

Open in new window

Avatar of piixeldesigns
piixeldesigns

ASKER

Hi Roads Roads,

That displays no error....MunterMan - it says returned 0 rows yet when I run that query in the database it returns 3 records.

Any ideas?

Thanks
Then try like this (use the output query to run this on the database)

$query1 = "
SELECT * FROM tbl_outing INNER JOIN bp_frieds
ON `tbl_outing`.`userid` = `bp_frieds`.`uid` 
WHERE startdate >= '$today' 
AND friendstype='Public' 
AND uid
IN (SELECT fuid FROM bp_frieds WHERE uid='$getuserData')
GROUP BY userid 
ORDER BY startdate, starttime DESC";

echo"$query1";

$result1 = mysql_query($query1) or die(mysql_error);

Open in new window

OK I found where the issue was and I have fixed that in the query however now that it works I get this displayed where each of my outputs should be instead of the actual content:

Warning: mysql_num_rows() expects parameter 1 to be resource, null given in

Any Ideas on this.

Thanks Again for the Help! :D
OK I found where the issue was and I have fixed that in the query however now that it works I get this displayed where each of my outputs should be instead of the actual content:

Warning: mysql_num_rows() expects parameter 1 to be resource, null given in

Any Ideas on this.

Sorry here is the extra code as the error is saying it is occuring on line 375 which is this line:
$comment_num_row = mysql_num_rows(@$comments);
                  if($comment_num_row > 0) {
                        while ($rows = mysql_fetch_array($comments)) {
$today = date("Y-m-d");
$query1 = "
SELECT * FROM tbl_outing INNER JOIN bp_frieds
ON `tbl_outing`.`userid` = `bp_frieds`.`uid` 
WHERE startdate >= '$today' 
AND friendstype='Public' 
AND uid
IN (SELECT fuid FROM bp_frieds WHERE uid='$getUserData')
GROUP BY userid 
ORDER BY startdate, starttime DESC";

$result1 = mysql_query($query1) or die(mysql_error);
while ($row = mysql_fetch_array($result1)) {

if($row['friendstype'] == "Public") {
?>

<div class="friends_area" id="record-<?php  echo $row['outing_id']?>">
	<div class="fleft">
		<div class="profilePic">
			<?php imageurl($row['p_Image'],'102px','');  ?>
		</div>
	</div>
	
	<div class="fleft" style="margin-left: 7px;">
		<label style="float:left">
			<h5 style="margin-bottom: 0px; font-size: 12px;"><?php echo $row['outing_name']." - ".$row['location'];?></h5>
			<span><?php display_date($log_date); ?></span>		  
			<a href="javascript: void(0)" id="post_id<?php  echo $row['outing_id']?>" class="showCommentBox links" style="text-decoration:underline;">Comments</a><br />
		
			<p><?php echo "Date: ".$row['startdate']." Time: ".$row['starttime']." - ".$row['endtime'] ?></p><br clear="all" />
		</label>
	</div>
	
	<br clear="all" />
	
	<div id="CommentPosted<?php  echo $row['outing_id']?>">
		<?php
			$comment_num_row = mysql_num_rows(@$comments);
			if($comment_num_row > 0) {
				while ($rows = mysql_fetch_array($comments)) {
					//display_date($rows['CommentTimeSpent']);
		?>
					
					<div class="commentPanel" id="record-<?php  echo $rows['c_id'];?>" align="left">
						<div class="fleft">
							<div class="profilePicSmall">
								<?php Commentimageurl($rows['comment_image'],'60px',''); ?>
							</div>
						</div>
						
						<div class="fleft">
							<label class="postedComments">
								<?php  echo $rows['comments'];?>
							</label><br clear="all" />
						
							<span style="margin-left:7px; color:#666666;"><?php display_date($rows['date_created']); ?></span>

							<?php if($rows['userid'] == $getUserData) { ?>
								<a href="#" id="CID-<?php  echo $rows['c_id'];?>" class="comment_delete">Delete</a>
							<?php  }  ?>
						</div>
						
						<br clear="all" />
					</div>				
			<?php	
					} 
				} 
			?>				
	</div>

	<div class="commentBox" align="right" id="commentBox-<?php  echo $row['outing_id'];?>" <?php echo (($comment_num_row) ? '' :'style="display:none"')?>>			
		<?php 
			//Commentimageurl($row['p_Image'],40,40); 
			$Comment_data1=mysql_query("SELECT bname,b_Image  FROM bp_details_tab where userid=".$getUserData."
			UNION ALL
			SELECT CONCAT(firstname,'  ',lastname) bname ,p_Image b_Image FROM public_details_tab where userid=".$getUserData);
			while ($photo_comment_data = mysql_fetch_array($Comment_data1)) {
	
				echo '<div class="profilePicSmall" style="float: left;">';
					Commentimageurl($photo_comment_data['b_Image'],'60px','');
				echo '</div>';
	
				//echo $photo_comment_data['bname'];
			}
		?>

		<label id="record-<?php  echo $row['outing_id'];?>">
			<textarea name="commentMark" cols="60" rows="2" class="commentMark" id="commentMark-<?php  echo $row['outing_id'];?>"></textarea>
		</label><br clear="all" />
			
		<a id="SubmitComment" class="small button comment">Comment</a>
	</div>
</div><br /><br />

<?php	
}

Open in new window



Thanks Again for the Help! :D
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Remove the @ operator, it is for suppressing errors on expressions not for use with variables.
Sorry here is the missing query
$comments = mysql_query("SELECT outing_comment_table.*,outing_comment_table.date_created AS CommentTimeSpent,public_details_tab.p_Image as comment_image  FROM outing_comment_table INNER JOIN public_details_tab ON outing_comment_table.userid=public_details_tab.userid where outing_comment_table.post_id = ".$row['outing_id']."
UNION ALL
SELECT outing_comment_table.*,outing_comment_table.date_created AS CommentTimeSpent,bp_details_tab.b_Image as comment_image  FROM outing_comment_table INNER JOIN bp_details_tab ON outing_comment_table.userid=bp_details_tab.userid where outing_comment_table.post_id = ".$row['outing_id'].""); //get comment table data

Open in new window



And here is the full code again with this in:
$today = date("Y-m-d");
$query1 = "
SELECT * FROM tbl_outing INNER JOIN bp_frieds
ON `tbl_outing`.`userid` = `bp_frieds`.`uid` 
WHERE startdate >= '$today' 
AND friendstype='Public' 
AND uid
IN (SELECT fuid FROM bp_frieds WHERE uid='$getUserData')
GROUP BY userid 
ORDER BY startdate, starttime DESC";

$result1 = mysql_query($query1) or die(mysql_error);
while ($row = mysql_fetch_array($result1)) {


$comments = mysql_query("SELECT outing_comment_table.*,outing_comment_table.date_created AS CommentTimeSpent,public_details_tab.p_Image as comment_image  FROM outing_comment_table INNER JOIN public_details_tab ON outing_comment_table.userid=public_details_tab.userid where outing_comment_table.post_id = ".$row['outing_id']."
UNION ALL
SELECT outing_comment_table.*,outing_comment_table.date_created AS CommentTimeSpent,bp_details_tab.b_Image as comment_image  FROM outing_comment_table INNER JOIN bp_details_tab ON outing_comment_table.userid=bp_details_tab.userid where outing_comment_table.post_id = ".$row['outing_id'].""); //get comment table data

if($row1['friendstype'] == "Public") {
?>

<div class="friends_area" id="record-<?php  echo $row['outing_id']?>">
	<div class="fleft">
		<div class="profilePic">
			<?php imageurl($row['p_Image'],'102px','');  ?>
		</div>
	</div>
	
	<div class="fleft" style="margin-left: 7px;">
		<label style="float:left">
			<h5 style="margin-bottom: 0px; font-size: 12px;"><?php echo $row['outing_name']." - ".$row['location'];?></h5>
			<span><?php display_date($log_date); ?></span>		  
			<a href="javascript: void(0)" id="post_id<?php  echo $row['outing_id']?>" class="showCommentBox links" style="text-decoration:underline;">Comments</a><br />
		
			<p><?php echo "Date: ".$row['startdate']." Time: ".$row['starttime']." - ".$row['endtime'] ?></p><br clear="all" />
		</label>
	</div>
	
	<br clear="all" />
	
	<div id="CommentPosted<?php  echo $row['outing_id']?>">
		<?php
			$comment_num_row = mysql_num_rows(@$comments);
			if($comment_num_row > 0) {
				while ($rows = mysql_fetch_array($comments)) {
					//display_date($rows['CommentTimeSpent']);
		?>
					
					<div class="commentPanel" id="record-<?php  echo $rows['c_id'];?>" align="left">
						<div class="fleft">
							<div class="profilePicSmall">
								<?php Commentimageurl($rows['comment_image'],'60px',''); ?>
							</div>
						</div>
						
						<div class="fleft">
							<label class="postedComments">
								<?php  echo $rows['comments'];?>
							</label><br clear="all" />
						
							<span style="margin-left:7px; color:#666666;"><?php display_date($rows['date_created']); ?></span>

							<?php if($rows['userid'] == $getUserData) { ?>
								<a href="#" id="CID-<?php  echo $rows['c_id'];?>" class="comment_delete">Delete</a>
							<?php  }  ?>
						</div>
						
						<br clear="all" />
					</div>				
			<?php	
					} 
				} 
			?>				
	</div>

	<div class="commentBox" align="right" id="commentBox-<?php  echo $row['outing_id'];?>" <?php echo (($comment_num_row) ? '' :'style="display:none"')?>>			
		<?php 
			//Commentimageurl($row['p_Image'],40,40); 
			$Comment_data1=mysql_query("SELECT bname,b_Image  FROM bp_details_tab where userid=".$getUserData."
			UNION ALL
			SELECT CONCAT(firstname,'  ',lastname) bname ,p_Image b_Image FROM public_details_tab where userid=".$getUserData);
			while ($photo_comment_data = mysql_fetch_array($Comment_data1)) {
	
				echo '<div class="profilePicSmall" style="float: left;">';
					Commentimageurl($photo_comment_data['b_Image'],'60px','');
				echo '</div>';
	
				//echo $photo_comment_data['bname'];
			}
		?>

		<label id="record-<?php  echo $row['outing_id'];?>">
			<textarea name="commentMark" cols="60" rows="2" class="commentMark" id="commentMark-<?php  echo $row['outing_id'];?>"></textarea>
		</label><br clear="all" />
			
		<a id="SubmitComment" class="small button comment">Comment</a>
	</div>
</div><br /><br />

<?php	
}
}//end bind outing details

Open in new window


Now it is back displaying nothing again...hmmm
Never Mind Thanks Munter Man and everyone else I just found a stupid error which fixed the whole thing with your suggestions above!!!
Remove @ as MunterMan's suggested and  - did you check for the result of the first query ?
Does it run on the DB ? If so, try the same as with query1
THANKS FOR THE HELP GUYS!! :D
Sorry one last quick question it works perfectly and displays the correct results which is 1 record but for some reason it keeps looping through and showing this one result many times over!

Thanks Again Guys,
PD
Make sure your $row / $rows / $row1 variables don't intersect each other.
Yes they don't seem to be intersecting from what I can see
Does the query return different rows from a sql command directly in the db ?
No The num_rows displays 3 results and the db displays 3 results however on the page itself just keeps repeating them.

Thanks