SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: dots in php scripts
-
Aug 5, 2000, 06:54 #1
- Join Date
- Jun 2000
- Location
- Slovenia, Europe
- Posts
- 205
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This block of code generates parse error in line with echo.
// Display the text of each joke in a paragraph
while ( $row = mysql_fetch_array($result) ) {
echo("<P>".$row['ID']." ".$row['JokeText']."</P>");
$jokeid = $row["ID"];
$joketext = $row["JokeText"];
echo("<a href='$PHP_SELF?deletejoke=$jokeid'>". "Delete Joke</a>");
I've managed to correct the mistakes and then it worked. There is something wrong with these dots . in the code. I know what's wrong in this case, but I don't know what these dots stand for and how to use them. Could some1 explain that?
Thanks,
Marko
-
Aug 5, 2000, 07:30 #2
- Join Date
- Jul 1999
- Location
- Powder Springs GA (Atlanta)
- Posts
- 1,238
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The dot's tell the PHP code to add this onto your block of either code or text. It's kind of like saying "do this and then add this and add this etc"
I think the problem with your code was that you didn't have any spaces before and after the dots. PHP is pretty lax on some things but i've found spaces and ; to be something you just don't mess with.
i'm not sure of the exactness of this reply but i think if you add a space before and after your dots you should be ok.
------------------
Eric Jones - SitePoint Administrator
http://www.sitepoint.com
eric@sitepoint.com
-
Aug 5, 2000, 14:25 #3
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I would prefer to handle something like this in the following manner:
while ( $row = mysql_fetch_array($result)) {
printf('<P>%s %s</P>', $row['ID'], $row['JokeText']);
printf('<a href='%s?deletejoke=%s'>Delete Joke</a>', $PHP_SELF, $myrow["ID"]);
}
-
Aug 6, 2000, 02:49 #4
- Join Date
- Jun 2000
- Location
- Slovenia, Europe
- Posts
- 205
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you both. I figured out that you have to put dots wherever you insert any kind of variable or function call. I still have problems sometimes, but I just try to put dots where I think they should be and then move them until it works
thanks again
-
Aug 6, 2000, 06:56 #5
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That is correct, but if you notice the printf statement in my code, you will see that a much easier way to do this is to use printf, you simply put %s wherever you need a variable, then at the end you simply put your variables, delimited by a comma, this way you don't have to worry about the dots, and it will make your code a lot easier to change later on.
-
Aug 7, 2000, 11:14 #6
- Join Date
- Jul 1999
- Location
- Derbyshire, UK
- Posts
- 4,411
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I have never had any problem with . in PHP, I never leave spaces between them and it always works. Obviously in a few peoples' cases it makes a difference.
------------------
Karl Austin
KDA Web Services
"Everyone has a photographic memory. Some just don't have film."
Bookmarks