Jump to content

Samuz

Members
  • Posts

    80
  • Joined

  • Last visited

Everything posted by Samuz

  1. I don't really understand the question. Where does this XML file reside? And are you processing it on a different server? And which server do "other people" not have access to? Sorry I should have been more clear. The server is public, what I meant is that i'm the only one that has to the source and i'd like it so that other users would be able to generate their own data from the feed. Something like what twitter does. Thank i'll look into that abit and see how it goes.
  2. Hi there hoping someone can help me with this little problem I can't seem to get around. Okay I have a large XML file with quite abit of information. It looks something like this: <nationlist> <nation data="Kanden"> <nationid>254470</nationid> <ruler>Samus</ruler> <nation_name>Kanden</nation_name> <resource1>Cow</resource1> <resource2>Water</resource2> <alliance>Independent Republic Of Orange Nations</alliance> </nation> <nation data="Bubbler Nation"> <nationid>13778</nationid> <ruler>Matt Miller</ruler> <nation_name>Bubbler Nation</nation_name> <resource1>Aluminum</resource1> <resource2>Lumber</resource2> <alliance>Independent Republic Of Orange Nations</alliance> </nation> </nationlist> In my PHP file, I grab the content based on a $GET request. $simplexml = simplexml_load_file('test.xml'); $myDataObjects = $simplexml->xpath('//nation[@data="'.$_GET['nation'].'"]'); So if I had 'Kanden' in the GET request, it'll return information for Kanden in an array. Abit like this: Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [data] => Kanden ) [nationid] => 254470 [ruler] => Samus [nation_name] => Kanden [resource1] => Cow [resource2] => Water [alliance] => Independent Republic Of Orange Nations ) ) Now my problem, how would I go about retrieving specific values from the array, like if I wanted to retrieve the 'ruler' index, what would I do to get 'Samus'. And also how would I make it possible so that other people without server access, can grab data from this page and use it in their own scripts? Sorry for the wall of text! Just wanted to explain it properly. Regards
  3. Thanks that solution would make more sense now that I think of it. Now if I want to use url parameters, all i'd have to do is use the $GET array right? (Ensuring everything is sanitized of course)
  4. Hi there thorpe. I need to generate actual files, because the content within them need to be specific to the actual user account. Would you recommend another solution for my situation?
  5. Example is: https://twitter.com/statuses/user_timeline/kevinhart4real.xml I have all the relevant information I need that i'd like to go in the field, I just need to know how to dynamically create the file with the content and have it update at specific intervals. Any one have any ideas (with PHP) So far I have come up with this: $link = mysql_connect('localhost','root',''); mysql_select_db('test',$link); $result = mysql_query('SELECT `nationid`,`ruler`,`nation`, `resource1`, `resource2`, `alliance` FROM `nation`'); $doc = new DomDocument('1.0'); $root = $doc->createElement('nationlist'); $root = $doc->appendChild($root); while($row = mysql_fetch_assoc($result)) { $nation= $doc->createElement('nation'); $nation = $root->appendChild($nation); foreach($row as $fieldname => $fieldvalue) { $child = $doc->createElement($fieldname); $child = $car->appendChild($child); //add data to the new element $value = $doc->createTextNode($fieldvalue); $value = $child->appendChild($value); } } $doc->save("nations.xml"); Now that generates 1 .xml file with all the details returned from my query. (also don't bash me for using mysql, it's a quick test) What I would like to do is create a new file for each record in my table and have only the values in that recorded saved to its respective file.
  6. Samuz

    Date regex

    Thanks all. Solved.
  7. Samuz

    Date regex

    Thanks for that. But i'm still getting the same problem with $date = '01/02/20033'; Problem being it returning true
  8. Samuz

    Date regex

    of course 1/2/20033 will return false, as it should be. Sorry. I meant it returned true.
  9. Samuz

    Date regex

    Someone tell me why this returns true when it should return false $date = '1/2/2004'; if(!preg_match('/(\d{1,2})\/(\d{1,2})\/(\d{4})/', $date)) : echo 'false'; else : echo 'true'; endif; } This works all fine and dandy and returns true. But if I were to do something like $date = '1/2/20033'; It'll return false. How can I make it so that it's only limited to the (dd/mm/yyyy) format and nothing else?
  10. Thanks mate. Nice & fast response.
  11. Okay i'm trying to compare these sets of variables. code looks like this.. if( $row->cash > $finalcash && $row->core1 > $finalcore1 && $row->core2 > $finalcore2 && $row->core3 > $finalcore3 && $row->core4 > $finalcore4 ) { return true; } else { return false; } First question is this the appropriate way of doing this? Or would a nested if statement work better? example: if ($row->cash > $finalcash) { if ($row->core1 > $finalcore1) { if ($row->core2 > $finalcore2) { if ($row->core3 > $finalcore3) { if ($row->core4 > $finalcore4) { } else { return false; } } else { return false; } } else { return false; } } else { return false; } } else { return false; } I know it looks pretty messy, so i'm wondering if anybody is aware of an alternative to achieving this?
  12. Thank you.
  13. Or you could just extract the posted values and use the variables like so. So, start of your script will be: extract($_POST); Then let's say you had an input field with the 'samus' as the name attribute. You could just use $samus instead of $_POST['samus'] and it'll return the posted value for that input field.
  14. "im looking for time based rotator that doesnt require a page reload." Sounds like you may want to look into ajax a bit.
  15. $sql="UPDATE `slogin` SET `data`='$me' WHERE username= '$_SESSION[name]'"; No single quotes. $_SESSION['name'] :V
  16. Hey guys, quick question. The array_rand() function. How random is it? I'm building an app in codeigniter where i'd need to return 2/6 keys from an array and store them in a DB. I don't want it to return a key that has already been returned. I'm sure logically there's always a chance that I could get back something that has already been returned. Also i'm using the function at the same time, so it isn't over any period of time or within different methods. Are there any other recommendations apart from array_rand() ? Thanks!
  17. Thank you guys. "It means that 441492111.66667 is converted to a string "441,492,111.66667". When you try to add 10 to it, this string is converted to number 441!!!" That makes perfect sense. So the ideal procedure would be to leave it as an integer while doing the math and then format it after i've generated the result?
  18. So I added a number unformatted and got the expected value, but after I formatted it I received an incorrect value? The Number unformatted looks like this: 441492111.66667. So did $number + 10 and got = 441492121.66667. That's all fine and correct. But after I formatted like so: $final = number_format($number) + 10; I got 451. Not too sure why that would happen, can someone explain to me please?
  19. Thanks for the reply. I'm still abit confused and not totally sure how I can use abs() in this situation. I first converted the date stamps to unix and then tried to subtract them from each other. Is that logically the correct way to go about it?
  20. Okay guys. My brain has completely froze and I can't figure out how to do this. I have one date, that is somewhat static it doesn't change regularly but it changes. Anyway let's say this timestamp is: 2011-07-12 10:30:00 and the current timestamp is 2011-07-13 10:30:00 That's exactly a day difference, which will produce 86400 seconds. How would I write this in PHP?
  21. Thank you for your fast reply. I just took out the foreach loop and access the $column array directly. Working as should now thanks!
  22. Got a little stuck here. I'm trying to format an existing .txt file, format it and then write it to .sql file. Here's my code: $handle = @fopen("nations.txt", "r"); if ($handle) { while (($buffer = fgets($handle, 1024)) !== false) { $column = explode("|",$buffer); // format file $myFile = "nation_dump_".date("Y-m-d").".sql"; // create file $fh = fopen($myFile, 'w') or die("can't open file"); foreach($column as $col) { fwrite($fh, $col[0]); //write the first broken segment from explode() to file } fclose($fh); } if (!feof($handle)) { echo "Error: unexpected fgets() fail\n"; } fclose($handle); } The error is on this line, within the foreach loop. fwrite($fh, $col[0]); When I removed the index it only wrote the last line to the file, but I want it to loop through all the lines.. What am I doing wrong here?
  23. Thanks, makes perfect sense.
  24. Because the counter has to start from somewhere (0 in this example). I was thinking about just going ahead and incrementing it with it without defining the starting point, but i'm not sure that will work because i'm sure PHP will return an undefined variable error. right?
  25. Yeah that's a problem. Because $var is still being reset back to 0 everytime and so will the session variables..
×
×
  • 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.