Author Topic: Not all values from MySQL  (Read 999 times)

0 Members and 1 Guest are viewing this topic.

Offline NLCJTopic starter

  • Enthusiast
  • Posts: 129
  • Gender: Male
    • View Profile
Not all values from MySQL
« on: January 27, 2010, 03:59:18 PM »
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.

Offline akitchin

  • chemical pirate
  • Global Moderator
  • Fanatic
  • *
  • Posts: 4,198
  • Gender: Male
  • YARR
    • View Profile
    • http://www.akitchin.com
Re: Not all values from MySQL
« Reply #1 on: January 27, 2010, 04:04:06 PM »
it's hard to tell what's wrong without seeing the query that grabs the guestbook entries.

Offline NLCJTopic starter

  • Enthusiast
  • Posts: 129
  • Gender: Male
    • View Profile
Re: Not all values from MySQL
« Reply #2 on: January 27, 2010, 04:06:38 PM »
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");

Offline akitchin

  • chemical pirate
  • Global Moderator
  • Fanatic
  • *
  • Posts: 4,198
  • Gender: Male
  • YARR
    • View Profile
    • http://www.akitchin.com
Re: Not all values from MySQL
« Reply #3 on: January 27, 2010, 04:11:53 PM »
so the script currently echoes all but one of the replies? how and when are they being inserted?

Offline NLCJTopic starter

  • Enthusiast
  • Posts: 129
  • Gender: Male
    • View Profile
Re: Not all values from MySQL
« Reply #4 on: January 27, 2010, 04:15:10 PM »
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)."')");

Offline akitchin

  • chemical pirate
  • Global Moderator
  • Fanatic
  • *
  • Posts: 4,198
  • Gender: Male
  • YARR
    • View Profile
    • http://www.akitchin.com
Re: Not all values from MySQL
« Reply #5 on: January 27, 2010, 04:18:33 PM »
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?

Offline NLCJTopic starter

  • Enthusiast
  • Posts: 129
  • Gender: Male
    • View Profile
Re: Not all values from MySQL
« Reply #6 on: January 27, 2010, 04:20:47 PM »
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 ;)).

Offline akitchin

  • chemical pirate
  • Global Moderator
  • Fanatic
  • *
  • Posts: 4,198
  • Gender: Male
  • YARR
    • View Profile
    • http://www.akitchin.com
Re: Not all values from MySQL
« Reply #7 on: January 27, 2010, 04:27:09 PM »
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.

Offline NLCJTopic starter

  • Enthusiast
  • Posts: 129
  • Gender: Male
    • View Profile
Re: Not all values from MySQL
« Reply #8 on: January 27, 2010, 04:29:39 PM »
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]
« Last Edit: January 27, 2010, 04:37:07 PM by NLCJ »

Offline akitchin

  • chemical pirate
  • Global Moderator
  • Fanatic
  • *
  • Posts: 4,198
  • Gender: Male
  • YARR
    • View Profile
    • http://www.akitchin.com
Re: Not all values from MySQL
« Reply #9 on: January 27, 2010, 04:41:51 PM »
this is the problem:

Code: [Select]
$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.

Offline NLCJTopic starter

  • Enthusiast
  • Posts: 129
  • Gender: Male
    • View Profile
Re: Not all values from MySQL
« Reply #10 on: January 27, 2010, 04:45:11 PM »
Thank you very much! It was useless over there, just forgot to delete it after I defined it in the while function. :)  ::)