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
PHPMySQL Server

Avatar of undefined
Last Comment
piixeldesigns

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Chris Harte

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Lukasz Chmielewski

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
Lukasz Chmielewski

should be
ORDER BY startdate, starttime DESC") or die(mysql_error());

Open in new window

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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Lukasz Chmielewski

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

piixeldesigns

ASKER
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
piixeldesigns

ASKER
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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
SOLUTION
Lukasz Chmielewski

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Chris Harte

Remove the @ operator, it is for suppressing errors on expressions not for use with variables.
piixeldesigns

ASKER
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
piixeldesigns

ASKER
Never Mind Thanks Munter Man and everyone else I just found a stupid error which fixed the whole thing with your suggestions above!!!
Your help has saved me hundreds of hours of internet surfing.
fblack61
Lukasz Chmielewski

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
piixeldesigns

ASKER
THANKS FOR THE HELP GUYS!! :D
piixeldesigns

ASKER
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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Lukasz Chmielewski

Make sure your $row / $rows / $row1 variables don't intersect each other.
piixeldesigns

ASKER
Yes they don't seem to be intersecting from what I can see
Lukasz Chmielewski

Does the query return different rows from a sql command directly in the db ?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
piixeldesigns

ASKER
No The num_rows displays 3 results and the db displays 3 results however on the page itself just keeps repeating them.

Thanks