Jump to content

Recommended Posts

I have been working on cleaning up the code in this script, trying to move all of the queries and functions, etc to the top of the script instead of all mixed in with the html. It worked before I started moving stuff around. I have highlighted the areas that I am having the problem in with / comments and is line 37-68 in my code. The output I have from echoing out the variables  is:

 

SELECT * FROM piccomment WHERE picid = 670 ORDER BY commentdatetime DESC

Resource id #8

0

 

<?php 
/*----------------------------------------------------------|
| TO DO LIST:												|	
| 	1. comments funtion needs to be fixed   				|
|   2. Picture tag query needs to be moved out of html code	|
-----------------------------------------------------------*/


session_start(); // START SESSION (MUST BE FIRST ON EVERY PAGE)
include("db_connect.php");

//GET PICTURE AND EVENT INFO
$strippicid = stripslashes(strip_tags($_GET['id'])); 
$getid = mysql_real_escape_string($strippicid);  
$picture_query = $query = "SELECT * FROM pic LEFT JOIN event ON pic.pictureeventid = event.pictureeventid WHERE pictureid = '$getid'";  
query_db2($picture_query); 
$picture_num_results = mysql_num_rows($result2);

if ($picture_num_results > 0) //If picture is in DB  display page
{ 
$show_page = "yes";
$picture_array = mysql_fetch_array($result2);
extract($picture_array);


//GET MEMBER INFO
$member_query = "SELECT * FROM member WHERE memberid = '$pictureuserid'";
query_db($member_query);
$member_array = mysql_fetch_array($result);
extract($member_array);
$timestamp = strtotime($picturedate);
$format_date = date("F j",$timestamp);
$mfname = $fname;
$mlname = $lname;


//////////////////THIS IS WHERE IT IS BROKEN!!////////////////////////////
// GET COMMENTS
function get_comments($show,$picture_id)
{
//if ($show == 1) {$query = "SELECT * FROM `piccomment` WHERE `picid` = '$pictureid' ORDER BY `commentdatetime` DESC ";}
//if ($show != 1) {$query = "SELECT * FROM `piccomment` WHERE `picid` = '$pictureid' ORDER BY `commentdatetime` DESC LIMIT 5 ";}
$comment_query = "SELECT * FROM piccomment WHERE picid = '$picture_id' ORDER BY commentdatetime DESC ";
//query_db($comment_query);
echo $comment_query. "<br>";
$comment_result = mysql_query($comment_query) or die (mysql_error());
echo $comment_result . "<br>";
$num_comments = mysql_num_rows($comment_result); 
echo $num_comments;
	while ($comment_array = mysql_fetch_array($comment_result))
	{
		extract($comment_array);
		$timestamp = strtotime($commentdatetime);
		$showdate = date('F j', $timestamp);
		$showtime = date('g:i a', $timestamp); 

		echo "<div id='comments'>";
		echo "<img class='commentpic' src='thumb.php?src=member$posterid.jpg&display=comment'>";
		echo "<div class='commenttext'>";
		echo "<h4><a href='profile.php?id=$posterid'> $postername</a> wrote: (on  $showdate at $showtime )	";	
		echo "</h4>";
		echo "<p>$comment;</p>";
		echo "</div>";
		echo "</div>";
	}
return $num_comments;
} 
////////////////////////////////////////////////////////////////////////////

function picture_tags($picturetag)
{			
	if ($picturetag != "")
	{ 
		$query = "SELECT * FROM member";
		$result = mysql_query($query) or die (mysql_error());
		//query_db($query);
		$row = mysql_fetch_array($result);

		$query2 = "SELECT fname,lname,memberid FROM `member` WHERE `memberid` IN ($picturetag)";
		$result2 = mysql_query($query2) or die (mysql_error());
		//query_db2($query2);
		while (list($fname,$lname,$number) = mysql_fetch_row($result2))
		{
    			echo "<a href='gallery.php?id=$number'>$fname $lname</a>, "; 
		}
	}
}

}
else
{ 
header('location:error.php'); // REDIRECT TO ERROR PAGE 
} 
?>

<?php 
if ($picture_num_results > 0){ // Picture is in DB
?> 
<?php include("header.php"); ?>
<div id="container">
	<div id="left">
		<div id="gallerynav">
		<center>
		<a href="gallery.php">Go back to the gallery</a>
		</center>
		</div>
	</div>

	<div id="right">
		<div id="gallery">
			<h2 class="floatleft"><?php echo $mfname." ".$mlname; ?>'s Photos - <?php if ($picturetitle == ""){ echo "Untitled"; } else {echo $picturetitle;} ?></h2>
			<div class="floatright"><a href="#">Edit</a></div>
			<div class="floatleft"> <?php echo $event; ?><div>
		</div>

		<div id="gallery">
		<center>
		<br />
		<img src="thumb.php?src=<?php echo $picturefile; ?>&display=medium" />
		</center>
		</div>

		<div id="gallery">
			<div class="floatleft">In this photo:  
			<?php picture_tags($picturetag); ?>
			</div>
		</div> 

		<? if ($_SESSION['auth'] == "yes"){ 
		$randnum = rand(0,99999);
		?>
		<div id="gallery">
		<h2>Add a comment:</h2>
		<form name="addcomment" method="post" action="comment_action.php">
		<input type="hidden" name="randnum" value="<?php echo $randnum; ?>">
		<input type="hidden" name="picid" value="<?php echo $pictureid; ?>">
		<input type="hidden" name="posterid" value="<?php echo $_SESSION['user']; ?>">
		<input type="hidden" name="postername" value="<?php echo $_SESSION['firstname']; ?> <?php echo $_SESSION['lastname']; ?>">
		<textarea name="text" cols="75" rows="4"></textarea><br><br>
		<input name="submitcomment" type="submit" value="submit"><br><br>
		</form>
		</div>

		<?php } ?>

		<?php
		if ($num_comments > 0)
		{
		?>
		<div id="gallery">
			<h2 class="floatleft">Comments</h2>
			<div class="floatright">    
			<?php if (($_GET['show'] != 1) and ($num_comments > 5)){?>
			<br /><a href="<?php echo $_SERVER['PHP_SELF']; ?>?id=<?php echo $pictureid; ?>&show=1">View All</a>
			<?php 
			}
			else { echo "&nbsp"; }
			?>
			</div>
		</div>
		<?php } ?>
		<?php 
		//////////////////////////////////////////////
		get_comments(1,$getid); 
		/////////////////////////////////////////////
		?>
	</div>
</div>
<?php include("footer.php"); ?>
<?php 
} //pic was in db
?>

Link to comment
https://forums.phpfreaks.com/topic/88145-solved-query-not-working/
Share on other sites

I have surounded the areas where the trouble is happening with ///.

 

This is the query:

$comment_query = "SELECT * FROM piccomment WHERE picid = '$picture_id' ORDER BY commentdatetime DESC ";

 

I am not getting an error. Instead nothing was happening. I echo'd some of the variables to trouble shoot, and this is what I got:

 

SELECT * FROM piccomment WHERE picid = 670 ORDER BY commentdatetime DESC 
Resource id #8
0

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.