Jump to content

Archived

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

NLCJ

Not all values from MySQL

Recommended Posts

Hello,

I've got a problem with creating my own guestbook. It doesn't 'echo'  all replies, it doesn't show the last value. So you've got to wait until it someone else replies before you can see it.

		<?php
		}elseif($p == gastenboek) {
	?>
	<center>[<a href="?p=ngastenboek">Nieuwe reactie</a>]</center><br>
	<?php 
	while($berichten = mysql_fetch_array($d_getberichten)) {
	?>
	<div class="gastenboek">
		<div class="informatie">
		<?php 
		$d_getgastenboekusers = mysql_query("SELECT * FROM users WHERE id='".mysql_real_escape_string($berichten['userid'])."'");
		$d_gastenboekusers = mysql_fetch_array($d_getgastenboekusers);
		echo "Verzonden door <i>".$d_gastenboekusers['voornaam']." ".$d_gastenboekusers['achternaam']."</i> op ".$berichten['datum']." om ".$berichten['tijd'].".";				?>
		</div>
		<div class="bericht">
		<?php 
		echo "<b>".$berichten['titel']."</b><br>".$berichten['tekst'];
		?>
		</div>
	</div>
	<?php 
	} 
                ?>

 

Thank you.

Share this post


Link to post
Share on other sites

it's hard to tell what's wrong without seeing the query that grabs the guestbook entries.

Share this post


Link to post
Share on other sites

it's hard to tell what's wrong without seeing the query that grabs the guestbook entries.

Sorry  :o

$d_getberichten = mysql_query("SELECT * FROM gastenboek ORDER BY datum,tijd DESC");

 

Share this post


Link to post
Share on other sites

so the script currently echoes all but one of the replies? how and when are they being inserted?

Share this post


Link to post
Share on other sites

so the script currently echoes all but one of the replies? how and when are they being inserted?

It echoes every reply except the last one that is added, when somebody else adds another one that one won't show up, but others will.

mysql_query("INSERT INTO gastenboek (userid,titel,tekst,datum,tijd) VALUES ('".mysql_real_escape_string($d_usergegevens['id'])."','".mysql_real_escape_string($titel)."','".mysql_real_escape_string($tekst)."','".mysql_real_escape_string($date)."','".mysql_real_escape_string($time)."')");

Share this post


Link to post
Share on other sites

is the SELECT query being performed before the INSERT query on the same PHP page? does simply reloading the page without posting a new comment force the newest comment to be displayed? if not, have you checked what data your tables contain?

Share this post


Link to post
Share on other sites

is the SELECT query being performed before the INSERT query on the same PHP page? does simply reloading the page without posting a new comment force the newest comment to be displayed? if not, have you checked what data your tables contain?

Refreshed the page endless times, no result. The database sees the value, but it just doesn't work. See it for yourself:

http://melkwegstelsel.co.cc/?p=gastenboek

You're free to register. :) (Password is encoded ;)).

Share this post


Link to post
Share on other sites

it doesn't help to see the page if i don't know what's in the database...

 

try posting the entire page and we'll see if we can't spot something that's wrong elsewhere, because at the moment, i can't see any issues. i would guess it's something in the if() block you've got leading up to the data echoes.

Share this post


Link to post
Share on other sites

it doesn't help to see the page if i don't know what's in the database...

 

try posting the entire page and we'll see if we can't spot something that's wrong elsewhere, because at the moment, i can't see any issues. i would guess it's something in the if() block you've got leading up to the data echoes.

 

Since I was trying to get all the commands in one page it is over 600 lines at this moment... Is gonna be a bit hard. I can remember I had this problem before, with the menu since that one is also dynamic. I cannot remember how I solved that (it was the day before yesterday  :confused:).

 

EDIT:

I've added the file. At line 567 starts the part of the guestbook.

At line 238 is the part where it inserts the values if you're registered.

At line 251 starts the part when you're not registered.

 

[attachment deleted by admin]

Share this post


Link to post
Share on other sites

this is the problem:

 

$d_berichten = mysql_fetch_array($d_getberichten);

 

you're moving the resource ID one position forward when you use mysql_fetch_array() the first time. that means when you go to run your while() loop later, it starts one record late. if you don't necessarily need that first row, you can delete this line to avoid moving the counter forward. otherwise, use mysql_data_seek to reset the pointer to 0 before looping through when displaying the entries.

Share this post


Link to post
Share on other sites

Thank you very much! It was useless over there, just forgot to delete it after I defined it in the while function. :)  ::)

Share this post


Link to post
Share on other sites

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