Jump to content

php help need with storing a value that does not increment


izza56

Recommended Posts

Hi folks,

 

first post, so apologies if this is in the wrong place. 

 

I am using php to connect with a mysql database back end.

I am developing a twitter like application for college...

 

I am currently working on a users subscriptions page that lists both their own and all subscribed to users feeds'

 

From the database I am pulling back the person who made the comment, the comment itself, and the date it was posted.

 

This is done using a while loop.  I have to make the person who made the comment a link to their own individual feed page.  But the issue i am having is that when i click on the comment authors link, it is bringing me to the comment page of the last listed author - this is because of the while looping with [$i] being the last person...

 

Here is a snippet of the code (where $followinguser is just a link to another page that should retain the individual authors name):

$i = 0;

$result = mysql_query($query, $connection);

if(!$result) {
	die("could not query database");
}


while($row = mysql_fetch_array($result)) {

	$commentby[$i] = $row['username'];
	$_SESSION['followfeed'] = $commentby[$i];	
		echo("<b>". "Comment by:" ."</b>" .$followinguser .$commentby[$i] ."</a>" ."<br />"); 
	$comment[$i] = $row['comment'];
		echo ($comment[$i] ."<br />");
	$commentdate[$i] = $row['commentdate'];
		echo ("<b>" .$commentdate[$i] ."</b>" ."<br />");
	$i++;	
}

-------------

 

Anyone have any ideas as to how i could ignore the loop struture and 'remember' who the autor is?

 

if you need any more info, just lettuce know.

Thanks.

 

edit: apologies, code tags updated.

I'm having a little bit of trouble understanding exactly what you are trying to say.

 

Also It's hard to understand the $followinguser thing because you haven't shown how it works.

 

The only suggestion I can offer is put the $i++ at the beginning of the while loop to make it so that it increases to be the current user.

 

Sorry without a little more info I can't be too helpful.

I'm having a little bit of trouble understanding exactly what you are trying to say.

 

Also It's hard to understand the $followinguser thing because you haven't shown how it works.

 

The only suggestion I can offer is put the $i++ at the beginning of the while loop to make it so that it increases to be the current user.

 

Sorry without a little more info I can't be too helpful.

 

Hi,  I am returning a result set that match a sql query i have called - which basically states return all rows in the database of comments to members who i have subscribed to.  To achieve this, i have used a while loop.

 

The tricky part is for each row returned, i have to make the 'comment by' field a hyperlink to a page that just shows their comments alone.  But because of the loop structure, all 'comment by' are defaulting to the 'comment by' that was last in the loop run.

 

the followinguser is a link to a userfeed page that displays their content alone:

$followinguser = "<a href = 'http://127.0.0.1/userfeed.php'>";

 

Hope this clears it up.

Cheers.

hey, sorry for the #bump# on this thread.

 

I guess what the issue is here, is that lets say you have a list of users in a forum who make posts.  I am running a simple "select user, comment, commentdate from comments" and returning it to the page using a while loop.  Now, for each user I want to have their userid as a hyperlink to another page that shows only their posts.  Unfortunately, no matter which user i click on, it goes to the page of the last person listed from the loop that was run.

Hope this makes sense.  wrecking my head in college at the moment trying to nail this one.

Cheers

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.