Jump to content

jcf

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

jcf's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Sorry ... FedEx11 is a diff accont i have .. seems to work now ...
  2. Hi, Easy enough question i just forget the exact method .. I have ... //count wins ... $count_wins = mysql_query("SELECT count(*) FROM `matches` WHERE result = 'W' AND Player1_ID = $player1_val AND Player2_ID = $player2_val "); Then i want to display this : echo "<h2><b> Wins ". $count_wins . "</h2></b>" ; But what is displayed is Wins Resource ID # 3 (or similar...) How to i convert this php variable to a normal int? becuase i didn't need to do this before in another query when i used to compare values ..
  3. jcf

    PHP question

    ok sorry i get it now.
  4. jcf

    PHP question

    [!--quoteo(post=371770:date=May 6 2006, 07:11 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 6 2006, 07:11 AM) [snapback]371770[/snapback][/div][div class=\'quotemain\'][!--quotec--] You mean it's not self explanatory? :-) [code]<?php $in = file('exam.txt'); // read the whole file into an array $out = array();          // initialize the array to hold the records to be written out foreach($in as $line) { // go through the array line by line     if (substr(trim($line),0,4) != 'S.L.') { // Only use those lines that don't start with "S.L."         $x = explode(' ',trim($line));    // explode the trimmed line on a space to form an array with two elements. Trimming will remove the newline character         $out[] = implode(' ',array_reverse($x)); // recreate a string with a space seperating the words after reversing the elements in the array         }     } $fp = f open('exam_out.txt','w'); f write($fp,implode("\n",$out). "\n");   // write all the lines to a file, using implode to put a newline character between each element of the array.  And add a newline character to the end of the last line. f close($fp); $results = file('exam_out.txt');  // read all the lines back into another array echo '<pre>' . print_r($results,true) . '</pre>';  // and display the results. Note you could also just display the contents of the $out array. ?>[/code] Ken [/quote] ok 1 more question, why here : if (substr(trim($line),0,4) != 'S.L.') why do you use 0,4 as an argument in substr() ?
  5. jcf

    PHP question

    [!--quoteo(post=371757:date=May 6 2006, 05:35 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 6 2006, 05:35 AM) [snapback]371757[/snapback][/div][div class=\'quotemain\'][!--quotec--] Here's the solution I came up with: [code]<?php $in = file('exam.txt'); $out = array(); foreach($in as $line) {     if (substr(trim($line),0,4) != 'S.L.') {         $x = explode(' ',trim($line));         $out[] = implode(' ',array_reverse($x));         }     } $fp = f open('exam_out.txt','w'); f write($fp,implode("\n",$out). "\n"); f close($fp); $results = file('exam_out.txt'); echo '<pre>' . print_r($results,true) . '</pre>'; ?>[/code] Note: remove the space from "f open", "f write", "f close" Ken [/quote] Wow!!! That is hard to understand, I looked up the functions on php.net, but still its tricky, Any chance you could comment that ?
  6. This question was on an exam : Write a PHP script that takes input as a data file with a list of names and companies, everyline that begins with "S.L." is a company , every other line is a person (2nd and 1st name) Re display the file with no companies and all the names reversed eg Murphy Paul S.L. Microsoft S.L. Sony Henderson Bill Jameson Harry S.L. Xerox Blair Andy Becomes : Paul Murphy Bill Henderson Harry Jameson Andy Blair So I wont bother putting my code in here (its awful as im new to PhP) but i used the strpos() function to remove all the companies, and then an array to swap around the 1st and last names ? Can anyone else post code that would do the above ?
×
×
  • 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.