thephoneguy87 Posted April 27, 2010 Share Posted April 27, 2010 I cant figure out how to order by a set paramater ie in my script online/offline. I was told by a wise man (salathe) that i could put all the data into an array and then loop back and output. however i do not know how to do this. Any help would be greatly appreciated. <?php $hostname='*****'; $username='*****'; $password='*****'; $dbname='*****'; mysql_connect($hostname,$username,$password); @mysql_select_db($dbname) or die( "Unable to select database"); $query="SELECT * FROM gamertags"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"first"); $i++; $xml = simplexml_load_file("http://xboxapi.duncanmackenzie.net/gamertag.ashx?GamerTag=".urlencode($f1)); { foreach( $xml->PresenceInfo as $lvl1 ) { echo 'Status: '.$lvl1->Info.'<br />'; echo 'Online/Offline: '.$lvl1->StatusText.'<br />'; echo 'Game: '.$lvl1->Title.'<br />'; echo 'Likes Sex: Yes'.'<br />'; } } { foreach( $xml->Gamertag as $lvl2 ) { echo 'Gamertag: '.$lvl2.'<br />'; } } { foreach( $xml->ProfileUrl as $lvl3 ) { echo 'Page Url: '."<a href=\"$lvl3\">Profile url</a>".'<br />'; } } { echo("<a href=\"http://live.xbox.com/profile/FriendsMgmt.aspx?gt=".urlencode($f1)."&act=Add\">Add as friend</a>".'<br />'); echo("<a href=\"http://live.xbox.com/profile/MessageCenter/SendMessage.aspx?gt=".urlencode($f1)."\">$Send Message</a>".'<br /><br />'); } } ?> Quote Link to comment Share on other sites More sharing options...
freelance84 Posted April 27, 2010 Share Posted April 27, 2010 Pretty new to PHP myself but shouldn't "mysql_close();" be after all your MySQL commands? In your script you close the connection then try to use "$f1=mysql_result($result,$i,"first");" Quote Link to comment Share on other sites More sharing options...
dgoosens Posted April 27, 2010 Share Posted April 27, 2010 not quite sure I got this right, but if you want to put the offlines after the onlines, you could just add an if statement in you foreach loop: foreach( $xml->PresenceInfo as $lvl1 ){ if($lvl1->StatusText == "Online"){ echo 'Status: '.$lvl1->Info.'<br />'; echo 'Online/Offline: '.$lvl1->StatusText.'<br />'; echo 'Game: '.$lvl1->Title.'<br />'; echo 'Likes Sex: Yes'.'<br />'; } else { $arrayForLater[] = $lvl1; } } then, after this foreach loop, you just have to go through the offlines: foreach ($arrayForLater as $id => $lvl1) { echo 'Status: '.$lvl1->Info.'<br />'; echo 'Online/Offline: '.$lvl1->StatusText.'<br />'; echo 'Game: '.$lvl1->Title.'<br />'; echo 'Likes Sex: Yes'.'<br />'; } Quote Link to comment Share on other sites More sharing options...
thephoneguy87 Posted April 27, 2010 Author Share Posted April 27, 2010 That doesnt work actually. It just doesnt show the data for that one part of it. I recoded the main part a bit maybe that will help. Thanks for trying . <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <table border="2" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif">Tag</font></th> <th><font face="Arial, Helvetica, sans-serif">Online?</font></th> <th><font face="Arial, Helvetica, sans-serif">Game</font></th> <th><font face="Arial, Helvetica, sans-serif">URL</font></th> <th><font face="Arial, Helvetica, sans-serif">Gamertag</font></th> <th><font face="Arial, Helvetica, sans-serif">Add</font></th> <th><font face="Arial, Helvetica, sans-serif">Send MSG</font></th> </tr> <?php $hostname='----'; $username='-----'; $password='-----'; $dbname='------'; mysql_connect($hostname,$username,$password); @mysql_select_db($dbname) or die( "Unable to select database"); $query="SELECT * FROM gamertags"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"first"); $i++; $xml = simplexml_load_file("http://xboxapi.duncanmackenzie.net/gamertag.ashx?GamerTag=".urlencode($f1)); { foreach( $xml->PresenceInfo as $lvl1 ) { $status = 'Status: '.$lvl1->Info.'<br />'; $online = 'Online/Offline: '.$lvl1->StatusText.'<br />'; $Game = 'Game: '.$lvl1->Title.'<br />'; $sex = 'Likes Sex: Yes'.'<br />'; } } { foreach( $xml->Gamertag as $lvl2 ) { $tag = 'Gamertag: '.$lvl2.'<br />'; } } { foreach( $xml->ProfileUrl as $lvl3 ) { $url = "<a href=\"$lvl3\">Profile url</a>".'<br />'; } } { $add = ("<a href=\"http://live.xbox.com/profile/FriendsMgmt.aspx?gt=".urlencode($f1)."&act=Add\">Add as friend</a>".'<br />'); $msg = ("<a href=\"http://live.xbox.com/profile/MessageCenter/SendMessage.aspx?gt=".urlencode($f1)."\">$Send Message</a>".'<br />'); } // Spot for styled data here { // echo $status,$online,$Game,$sex,$tag,$url,$add,$msg; ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><? echo $status; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo $online; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo $Game; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo $sex; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo $tag; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo $add; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo $msg; ?></font></td> </tr> <? } } ?> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
dgoosens Posted April 27, 2010 Share Posted April 27, 2010 what output are you getting ? and... on an other matter... try to avoid this kind of inline styling in your html: <table border="2" cellspacing="2" cellpadding="2"> <th><font face="Arial, Helvetica, sans-serif">Tag</font></th> [...] do use CSS, inline if you like: <table style="border:2px solid #000000; margin:2px; padding:2px;"> <th style="font-family:Arial, Helvetica, sans-serif;">Tag</th> [...] Quote Link to comment Share on other sites More sharing options...
thephoneguy87 Posted April 27, 2010 Author Share Posted April 27, 2010 http://purewebz.com/delta2/index.php Thats the current output with code as shown in my most recent post. I havent even moved to styling that was just so i could see it better . Quote Link to comment Share on other sites More sharing options...
dgoosens Posted April 27, 2010 Share Posted April 27, 2010 Oh... just got it... in fact, it is because you print out everything right away try something like this: while ($i < $num) { $f1=mysql_result($result,$i,"first"); $i++; $xml[] = simplexml_load_file("http://xboxapi.duncanmackenzie.net/gamertag.ashx?GamerTag=".urlencode($f1)); } then, after that, do a foreach loop on $xml and then you'll be able to put them aside as I explained above Quote Link to comment Share on other sites More sharing options...
thephoneguy87 Posted April 27, 2010 Author Share Posted April 27, 2010 After playing with it it just doesnt seem this method is very effective. I think i am going to pull the data inta a database every 5 minutes Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.