Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Posts posted by PFMaBiSmAd

  1. The extra character is probably the newline at the end of each line from the file. The last line in the file probably does not have a newline after it.

     

    You can add the FILE_IGNORE_NEW_LINES flag as the second parameter in the file() function call to have the newline characters stripped off -

     

    $chars = file('file.txt',FILE_IGNORE_NEW_LINES);

  2. Firstly, the purpose of a programming help forum is for people to learn and to help others with the same problem. So please post the solution to the original problem so that someone who finds this thread and has the same symptoms will be able to see if your solution would help him solve his problem.

     

    For your current problem, you are obviously doing something in a non-standard way. You would need to post your main file and the file being included, along with their file names/extensions to get any specific help with what it is doing.

     

    We need to see the big picture of what you are actually doing in order to be able to help you without playing a game of 20 questions.

  3. First of all $_GET is not dependent on register globals to work and you should in fact turn register globals off (register globals are completely eliminated in PHP6 and php.net turned them off by default in php4.2 in the year 2002. No new code, tutorials, books... should have been written after then that relied on register globals being on.)

     

    However, either something your code is doing is clearing the $_GET values or because register globals are on, they (the $_GET variables) are being overwritten by another variable with the same name $f or $d.

  4. On the page, use their id and query the database for their record. If the query returned a row, put the values into the value="..." parameters in the form.

     

    When they submit the form, use their id and query the database for their record. If the query returned a row, they already have a row and you need to perform an UPDATE query. If the query did not return a row, you need to perform an INSERT query.

     

    Pretty basic if() {// a row was found, do an UPDATE } else {// no row found, do an INSERT } logic -

     

    if(mysql_num_rows($result) > 0)
    {
    // They already have a record, use an UPDATE query
    } else {
    // They don't have a record, use an INSERT query.
    }

  5. There is an install.txt file in there that has instructions for just about every possible combination of operating system and web server. The same information can be found in the installation section in the php manual. Find, read, and follow the instructions that apply to your operating system and web server.

  6. Actually I see that I left off an "as cnt" alias, which would have generated a syntax error in the ORDER BY clause, so it is unlikely that the code you executed was the code you just posted. It should not have given the same error as before.

     

    Here is the corrected code I meant to post -

     

    $query="SELECT ratings_winner, count(*) as cnt FROM `ratings` WHERE ratings_winner=$user";
    
    for ($i=0; $i<count($friends);$i++)
    {
    $query = $query . " OR ratings_winner=" . $friends[$i]['uid'];
    }
    
    $query .= " GROUP BY ratings_winner ORDER BY cnt DESC LIMIT 0 , 15";

     

    I just tested both your original query and the one I gave, and in mysql 5.0.45, they both work without any mysql error.

     

    My guess at this point is that your version of mysql does not support the combination of GROUP BY and ORDER BY.

  7. The last question is easy. Yes there is -

     

    Magic constants

    PHP provides a large number of predefined constants to any script which it runs. Many of these constants, however, are created by various extensions, and will only be present when those extensions are available, either via dynamic loading or because they have been compiled in.

     

    There are five magical constants that change depending on where they are used. For example, the value of __LINE__ depends on the line that it's used on in your script. These special constants are case-insensitive and are as follows:

     

     

    Table 13.1. A few "magical" PHP constants

     

    Name Description

    __LINE__ The current line number of the file.

     

    ... 

     

     

  8. The following part of the code is where the query is formed -

     

    $query="SELECT ratings_winner FROM `ratings` WHERE ratings_winner='$user'";
    
    for ($i=0; $i<count($friends);$i++)
    {
    $query = $query . " OR ratings_winner=" . $friends[$i]['uid'];
    }
    
    $query .= " GROUP BY ratings_winner ORDER BY count( ratings_winner ) DESC LIMIT 0 , 15";

     

    To make the changes that I believe will fix this, change those lines to the following (I also removed the single-quotes around the first value ) -

     

    $query="SELECT ratings_winner, count(*) FROM `ratings` WHERE ratings_winner=$user";
    
    for ($i=0; $i<count($friends);$i++)
    {
    $query = $query . " OR ratings_winner=" . $friends[$i]['uid'];
    }
    
    $query .= " GROUP BY ratings_winner ORDER BY cnt DESC LIMIT 0 , 15";

  9. The mysql error - Invalid use of group function - is most likely occurring because the count() function is being used in the ORDER BY clause.

     

    If your query was as follows, it should work -

     

    SELECT ratings_winner, count(*) as cnt FROM `ratings` WHERE ratings_winner='634794851' OR ratings_winner=305300379 OR ... all the OR'ed values, removed for clarity  ... GROUP BY ratings_winner ORDER BY cnt DESC LIMIT 0 , 15

     

    I just noticed in the query that the first ratings_winner = value is enclosed in single-quotes. While this will not prevent the query from working, the single-quotes should not technically be there.

     

     

  10. There is a 99.9% chance that it is the short php opening tag <? being used near the end of the file with the error (all the other files are irrelevant, why did you post them?)

     

    Always use full php opening tags <?php to make your code portable between any server configuration.

  11. The end of life for PHP4 is the end of this year, in a little more than 30 days. Your web host probably won't continue offering PHP4 for very long after that.

     

    Your problem is not PHP4 vs PHP5 but configuration differences in php.ini and since register_globals have been eliminated completely in PHP6, you're going to need to remove any dependencies on register_globals if you want your code to keep working when PHP6 is released.

  12. Check your web server log for errors and/or turn on full php error reporting in php.ini or a .htaccess file to get php to help you out. I suspect a problem with register_globals.

     

    session_register() and session_is_registered() functions are depreciated (a long time ago) and only work when register_globals are on.

  13. The IE cookie question is really very simple. Any cookie with a zero life time is kept in a cookie cache in memory (which is deleted when the browser closes.)

     

    For the second question, as long as the browser is left open (even if you browse to a different site) the session cookie is kept alive. However, if the session garbage collection runs on the server and deletes the corresponding session data file, then the session cookie would no longer have a corresponding session data file when the browser fetches a URL at your site.

  14. Seeing a visual representation of the data as an array (so you can see the indexes), the way php sees it, will probably help. See the following print_r() code added to your code and I believe the two foreach() loops that do what you want -

     

    <?php
    $PAT_ID = '1145566';
    
      $xmlstring = file_get_contents("patients.xml");
      $xml = new SimpleXMLElement($xmlstring);
    
    echo "<pre>";
    print_r($xml);
    echo "</pre>";
    
    foreach ($xml->Patient as $Patient)
    {
    foreach($Patient->Study as $Study)
    {
    	if (strtolower($Study->PatientID) == "$PAT_ID") {
    		$sid = $Study->StudyCode . "</p>";
    		echo($sid);
    	}
    }
    }
    ?>

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.