Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    New Coder
    Join Date
    Aug 2008
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Unexpected $end/T_VARIABLE

    Hey,
    I'm using this tutorial/snippet type thing:
    http://www.siteground.com/tutorials/...table_data.htm
    And modifying it for my own use. However I'm getting all sorts of errors thrown at me. This is the current code I'm using:
    PHP Code:
    <?php
    $username
    ="username";
    $password="password";
    $database="databasename";

    mysql_connect(localhost,$username,$password);
    @
    mysql_select_db($database) or die( "Unable to select database");
    $query="SELECT * FROM newpilots";
    $result=mysql_query($query);

    $num=mysql_numrows($result);

    mysql_close();

    $i=0;
    while (
    $i $num) {

    $Fullname=mysql_result($result,$i,"Fullname");
    $Callsign=mysql_result($result,$i,"Callsign");
    $Flag=mysql_result($result,$i,"Flag); 

    $i++;
    }
    ?>
    I'm getting an unexpected $end on line 24 though
    Can anyone tell what's wrong?
    Thanks.

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,312
    Thanks
    4
    Thanked 206 Times in 203 Posts
    This line is missing a closing double quote.

    PHP Code:
    $Flag=mysql_result($result,$i,"Flag"); 
    Dave .... HostMonster for all of your hosting needs

  • Users who have thanked djm0219 for this post:

    iKettles (08-04-2008)

  • #3
    New Coder
    Join Date
    Aug 2008
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks so much! It's working fine now. Few more questions though, any reason why all the stuff I echo is displayed twice? Is this because of the loop? Also on my index page I include the file that connects to the database just below the body tag however when I echo $Fullname only one name shows instead of them all. Any reason for this?
    Last edited by iKettles; 08-04-2008 at 03:27 PM.

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,312
    Thanks
    4
    Thanked 206 Times in 203 Posts
    This loop

    PHP Code:
    $i=0;
    while (
    $i $num) {

    $Fullname=mysql_result($result,$i,"Fullname");
    $Callsign=mysql_result($result,$i,"Callsign");
    $Flag=mysql_result($result,$i,"Flag"); 

    $i++;
    }
    ?> 
    will display the information as many times as there were rows found by your earlier search. You're only seeing one name because you are displaying the results of the last row retrieved. If you want all of them displayed try something like this:

    PHP Code:
    mysql_connect(localhost,$username,$password);
    @
    mysql_select_db($database) or die( "Unable to select database");
    $query="SELECT * FROM newpilots";
    $result=mysql_query($query);

    $myrow mysql_fetch_assoc($result);

    do {
         
    $Fullname=$myrow['Fullname'];
         
    $Callsign=$myrow['Callsign'];
         
    $Flag=$myrow['Flag']; 
        
    } while (
    $myrow mysql_fetch_assoc($result));
    ?> 
    Dave .... HostMonster for all of your hosting needs

  • #5
    New Coder
    Join Date
    Aug 2008
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Still seems to only want to display one result when using that code

  • #6
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,312
    Thanks
    4
    Thanked 206 Times in 203 Posts
    How many rows are you expecting for the SELECT * FROM newpilots query? The do-while will retrieve rows and display them as long as there is data available from the query.
    Dave .... HostMonster for all of your hosting needs

  • Users who have thanked djm0219 for this post:

    iKettles (08-04-2008)

  • #7
    New Coder
    Join Date
    Aug 2008
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Think I may have found the issue. The code I'm using to insert stuff into the database uses the CURL function to pull XML data from a website. Every time I update the stats by executing my update.php file if the new pilots hasn't changed it just duplicates them and adds another row. The maximum and minimum amount of records in the table needs to be 5 with only 1 row for each record. How do I set this? Also could I use the update function to replace the current 5 records with the latest 5 records?

  • #8
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,312
    Thanks
    4
    Thanked 206 Times in 203 Posts
    The number of records is something you have to control with your code. Updating the existing records should work as long as one of your columns is a "key" that you can use to relate what you already have with the data you are pulling.
    Dave .... HostMonster for all of your hosting needs

  • Users who have thanked djm0219 for this post:

    iKettles (08-04-2008)

  • #9
    New Coder
    Join Date
    Aug 2008
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by djm0219 View Post
    The number of records is something you have to control with your code. Updating the existing records should work as long as one of your columns is a "key" that you can use to relate what you already have with the data you are pulling.
    I've also tried using the replace section but it just keeps making duplicate rows. This is going to get out of hand as I'll be using a cron job to run the file every 30 minutes to update the stats database. If I use the UPDATE function will I get duplicate rows? If a new pilot joins will it still keep 5 records and not go to 6?

  • #10
    Regular Coder
    Join Date
    May 2008
    Location
    Ohio
    Posts
    231
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Yes, you can use the update function to keep the existing rows. I usually avoid doing this because I like to keep a record of what has been in the database. Instead I usually set an extra field in the table "active" so that when I 'delete' things I'm actually just changing that field. Then I can do something like "SELECT mydata FROM mytable WHERE active='true'"

    You could also just keep inserting things and ONLY select the latest 5 entries - that would be very easy to implement. Just append "ORDER BY column_name DESC LIMIT 5" to your query.
    zok@zoklet:~$ whereis zok
    zok: http://zoklet.net | http://zoklet.net/otg | /derzok/at/gmail/dot/com

  • #11
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Unexpected $end means your missing a single closing bracket }

  • #12
    New Coder
    Join Date
    Aug 2008
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Just FYI, this is the code I'm currently using to insert the data -
    PHP Code:
    <?php
    $ch 
    curl_init('http://www.vafinancials.com/xml/newpilots.php?id=504');
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
    curl_setopt($chCURLOPT_HEADER0);
    $data curl_exec($ch);
    curl_close($ch);
    $doc = new SimpleXmlElement($dataLIBXML_NOCDATA);
    foreach (
    $doc->pilot as $np) {


    $con mysql_connect("localhost","db_name","password");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db("flycayco_vafsupdate"$con);

    mysql_query("INSERT INTO newpilots (Callsign, FullName, Flag) 
    VALUES ('$np->cs.', '$np->name.', '$np->flag.')"
    );

    mysql_close($con);
    }
    ?>
    For the "ORDER BY column_name DESC LIMIT 5" does it matter what column I order by? There's no column for the date hired so I can't order by the latest entries, is there any order type within MYSQL I can order by to show only the latest entries? Also it's still choosing to only display 1 name when I echo the $Fullname variable outside of the main PHP code.
    Last edited by iKettles; 08-04-2008 at 05:38 PM.

  • #13
    New Coder
    Join Date
    Aug 2008
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Got the update working but it seems to replace all of the records with the data of 1 of the pilots :S This is the code I'm using:
    PHP Code:
    <?php
    $ch 
    curl_init('http://www.vafinancials.com/xml/newpilots.php?id=504');
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
    curl_setopt($chCURLOPT_HEADER0);
    $data curl_exec($ch);
    curl_close($ch);
    $doc = new SimpleXmlElement($dataLIBXML_NOCDATA);
    foreach (
    $doc->pilot as $np) {


    $con mysql_connect("localhost","db_name","password");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db("flycayco_vafsupdate"$con);

    mysql_query("UPDATE newpilots SET Callsign = '$np->cs.', FullName = '$np->name.', Flag = '$np->flag.'");

    mysql_close($con);
    }
    ?>
    I realise I haven't defined a WHERE because I want to update all of the records, not just specific ones. Is this causing it?

  • #14
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    WHERE clause?

  • #15
    New Coder
    Join Date
    Aug 2008
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rafiki View Post
    WHERE clause?
    Yeah, that's probably what's causing it. I want to update all 5 records in the table (no specific ones) but when I don't define a WHERE clause it updates all the records with one pilot's data.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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