SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Addict mh8759's Avatar
    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


  2. #2
    SitePoint Wizard jonese's Avatar
    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

  3. #3
    Dumb PHP codin' cat
    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"]);
    }

  4. #4
    SitePoint Addict mh8759's Avatar
    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

  5. #5
    Dumb PHP codin' cat
    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.

  6. #6
    SitePoint Wizard silver trophy Karl's Avatar
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •