Solved

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

Posted on 2011-03-08
18
254 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:piixeldesigns
  • 9
  • 7
  • 2
18 Comments
 
LVL 17

Accepted Solution

by:
Chris Harte earned 250 total points
ID: 35068688
Is the query returning anything? Try this before the while loop

$row_num = mysql_num_rows($result1);
echo "number of rows returned $row_num";
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35068704
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
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35068708
should be
ORDER BY startdate, starttime DESC") or die(mysql_error());

Open in new window

0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 1

Author Comment

by:piixeldesigns
ID: 35068770
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
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35068836
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

0
 
LVL 1

Author Comment

by:piixeldesigns
ID: 35068904
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
0
 
LVL 1

Author Comment

by:piixeldesigns
ID: 35068910
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
0
 
LVL 27

Assisted Solution

by:Lukasz Chmielewski
Lukasz Chmielewski earned 250 total points
ID: 35068975
$comment_num_row = mysql_num_rows(@$comments);

So the $comments should be existing mysql_query(...) result but I can't see anything of that up in the code ?
0
 
LVL 17

Expert Comment

by:Chris Harte
ID: 35068978
Remove the @ operator, it is for suppressing errors on expressions not for use with variables.
0
 
LVL 1

Author Comment

by:piixeldesigns
ID: 35069116
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
0
 
LVL 1

Author Comment

by:piixeldesigns
ID: 35069129
Never Mind Thanks Munter Man and everyone else I just found a stupid error which fixed the whole thing with your suggestions above!!!
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35069139
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
0
 
LVL 1

Author Closing Comment

by:piixeldesigns
ID: 35069141
THANKS FOR THE HELP GUYS!! :D
0
 
LVL 1

Author Comment

by:piixeldesigns
ID: 35069159
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
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35069218
Make sure your $row / $rows / $row1 variables don't intersect each other.
0
 
LVL 1

Author Comment

by:piixeldesigns
ID: 35069335
Yes they don't seem to be intersecting from what I can see
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35071373
Does the query return different rows from a sql command directly in the db ?
0
 
LVL 1

Author Comment

by:piixeldesigns
ID: 35081634
No The num_rows displays 3 results and the db displays 3 results however on the page itself just keeps repeating them.

Thanks
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question