Het volgende script:


<p><strong>Nummer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bericht</strong></p>
<?
mysql_connect("localhost", "UNAME", "PASS") or die(mysql_error());
mysql_select_db("db_name") or die(mysql_error());
$query = "SELECT * FROM db"; 
	 
$result = mysql_query($query) or die(mysql_error());
// $stringe = "&nbsp;&nbsp;&nbsp;"

while($row = mysql_fetch_array($result)){
// echo $row['number'] ;

$string .= "(" .substr($row['number'], -4). ") " .$row['text']. "<BR>";
echo $string;
}
?>


Blijft echo'en, waardoor je dus dubbele entry's krijgt, hoe kan ik de query stoppen als er geen entry's meer zijn in de database?
De echo stopt als ie alle records uit de database heeft neergezet.
Hmm, vreemd. Ik keek net in de database, en daar staan geen subbele entry's. Als ik het script uitvoer, krijg ik dit:


(5555) hello, this is a test sms
(5555) hello, this is a test sms
(1111) hello, this is a test sms
(5555) hello, this is a test sms
(1111) hello, this is a test sms
(2222) hello, this is a test sms
(5555) hello, this is a test sms
(1111) hello, this is a test sms
(2222) hello, this is a test sms
(3333) hello, this is a test sms
(5555) hello, this is a test sms
(1111) hello, this is a test sms
(2222) hello, this is a test sms
(3333) hello, this is a test sms
(4444) hello, this is a test sms
(5555) hello, this is a test sms
(1111) hello, this is a test sms
(2222) hello, this is a test sms
(3333) hello, this is a test sms
(4444) hello, this is a test sms
(6666) hello, this is a test sms


Terwijl ik dit wil hebben:


(5555) hello, this is a test sms
(1111) hello, this is a test sms
(2222) hello, this is a test sms
(3333) hello, this is a test sms
(4444) hello, this is a test sms
(6666) hello, this is a test sms


Enig idee hoe dit op te lossen is?
Haal die punt(.) op regel 13 voor de = eens weg.
Zorgt dit er nog steeds voor dat alle echo's in een variabele komen (wat ik deed met $string .=)?
$var = '....'; // toekennen van tekst
$var .= '.....'; // de tekst achteraan $var knopen.


1e while
(5555) hello, this is a test sms

2e while
(5555) hello, this is a test sms
(1111) hello, this is a test sms

3e while
(5555) hello, this is a test sms
(1111) hello, this is a test sms
(2222) hello, this is a test sms

4e while
(5555) hello, this is a test sms
(1111) hello, this is a test sms
(2222) hello, this is a test sms
(3333) hello, this is a test sms

5e while
(5555) hello, this is a test sms
(1111) hello, this is a test sms
(2222) hello, this is a test sms
(3333) hello, this is a test sms
(4444) hello, this is a test sms

6e while
(5555) hello, this is a test sms
(1111) hello, this is a test sms
(2222) hello, this is a test sms
(3333) hello, this is a test sms
(4444) hello, this is a test sms
(6666) hello, this is a test sms
Net getest, en hij paky nu inderdaad maar een regel. Ik ga ns kijken wat ik eraan kan doen.
Het eenvoudigst lijkt mij dit:
<?php
while($row = mysql_fetch_array($result))
{
echo "(" . substr($row['number'], -4) . ") " . $row['text'] . "<br/>";
}
?>
Fixed! Bedankt voor je hulp, SanThe!
Hmm, ik ben nu bezig met het toevoegen van de MySQL connectie en ik krijg deze fout steeds:

<b>Parse error</b>:  parse error, unexpected T_STRING in <b>C:\PHP\responder.php</b> on line <b>107</b><br />


Op line 107 staat dit:


mysql_connect("localhost", "user", "pass") or die(mysql_error());


Enig idee wat hier fout aan is?

Gelieve Niet Bumpen:

Twee of meer keer achter elkaar in een topic posten heet bumpen. Bumpen is pas na 24 uur toegestaan en kan een reden zijn voor de admins en moderators om een topic te sluiten. Gebruik indien nodig de knop om je tekst aan te passen.

SanThe.
Aan die regel zie ik niets fout... maar sluit je regel 106 wel goed af? Geen punt of puntkomma vergeten?

Reageren