Jump to content

johnslater

Members
  • Posts

    31
  • Joined

  • Last visited

    Never

Everything posted by johnslater

  1. I have a question, something i SHOULD be able to do but i seem to be having a lapse in capabilities right now. Basically i have a MySQL database with a number of tables. One table called 'Users' and one called 'Scores'. Basically Scores are linked to Users by a UserID because a user may have multiple scores for different games and levels. Basically i want to output an overall scoreboard which adds up all the scores for each users and then outputs them in a big scoreboard. So for example USER - SCORE John - 20 Dave - 140 John - 70 John - 200 Dave - 200 Would output on the scoreboard as... Dave - 340 John - 290 etc.. Thanks guys.
  2. I've had this issue before and someone created a new function that did the job, however that function doesn't work in this case which is a pain. I'm pulling an XML file and outputting the contents of the "album" tag and need to output each child element of album (name, playcount etc). I think the problem is with the album tag having a rank="1" attribute on it, so i can only output the first album, no further albums. Here is what i have so far that outputs album one... $artists_xml = simplexml_load_file('http://ws.audioscrobbler.com/2.0/?method=artist.gettopalbums&artist='.$artist.'&api_key=b25b959554ed76058ac220b7b2e0a026'); $artists_array = $artists_xml->topalbums; //print_r($artists_array); foreach ($artists_array as $value) { //VARS $album_title = $value->album->name; return $album_title; } I want to be able to loop through all of the albums, not just the first and be able to drill into each one and get the child elements. Thanks in advance.
  3. For some reason it started working, i'm thinking maybe Twitter was having issues or something. Either way it works now and your method fixed it, thanks.
  4. Warning: Invalid argument supplied for foreach() in /mounted-storage/home114b/sub005/sc49493-NOAI/ifestapp.com/iphone/twitter.php on line 6 still get the same error
  5. I'm having some trouble with JSON, i'm new to it and i did my research and thought i had a good understanding of it. I was wrong. Basically the code i have is below, i want to loop out results from the JSON search results from Twitter (in this example the profile picture) but something is wrong and i can find little help online. I hope i'm on the right lines, help would be great. <? $jsonurl = "http://search.twitter.com/search.json?q=twitter"; $json = file_get_contents($jsonurl,0,null,null); $json_output = json_decode($json); foreach ($json_output->results[0]->profile_image_url as $trend ) { echo $trend; } ?>
  6. <image size="small">http://userserve-ak.last.fm/serve/34s/8634917.jpg</image> <image size="medium">http://userserve-ak.last.fm/serve/64s/8634917.jpg</image> <image size="large">http://userserve-ak.last.fm/serve/126/8634917.jpg</image> − <image size="extralarge"> http://userserve-ak.last.fm/serve/300x300/8634917.jpg </image> The XML only pulls the small image (the first one) and i want to be able to select an image size, for example "extralarge" but i cannot select an image by size.
  7. <? $xml = simplexml_load_file('http://ws.audioscrobbler.com/2.0/user/slaterjohn/topartists.xml?period=12month'); $array = $xml->artist; foreach ($array as $value) { $name = $value->name; $playcount = $value->playcount; $url = $value->url; $image = $value->image; $i++; echo $i.'.) '; echo '<a href="'.$url.'">'.$name.'</a>'; echo ' - <strong>'.$playcount.'</strong>'; echo $image; echo '<br />'; } ?> this is what i have so far.
  8. I have a problem while parsing xml in PHP using the PHP function "simplexml" THe problem i'm facing i believe is mainly down to the xml but i wondered if there is a solution anyway. In my XML i have these lines... <image size="small">http://userserve-ak.last.fm/serve/34/25607637.jpg</image> <image size="medium">http://userserve-ak.last.fm/serve/64/25607637.jpg</image> <image size="large">http://userserve-ak.last.fm/serve/126/25607637.jpg</image> <image size="extralarge">http://userserve-ak.last.fm/serve/252/25607637.jpg</image> ... i want to be able to select a specific image from the size attribute. Here is what i'm using to grab it in PHP... $xml->artist->image['size']; but this only grabs the value of the "size" attribute, i want the value between the tags. Thanks in advanced.
  9. That worked a treat, cheer Russell.
  10. Cheers but i get this error... Warning: preg_replace() [function.preg-replace]: Unknown modifier 'g' in /mounted-storage/home114b/sub005/sc49493-NOAI/www/_functions.php on line 191
  11. I'm trying to get my head around preg_match or preg_replace because i need it for something i'm building. The problem is it is very confusing and i'm not sure my keyboard can take any more of my mental ranges. Basically i want to replace this... <img:image_name_here_etc:/img> with... crazy_image_function('image_name_here_etc'); So that all of the tags in the content (there may be more than one) will be replaced my the function which outputs optimised images. The function words like a charm, but i can't get my head around preg_replace or preg_match. Thanks.
  12. I'm running a PHP script that runs through an array containg quite a few records. This array has each row outputted and then this row is placed into the database. The problem is MySQL decides to stop half way through the query and say "MySQL has gone away" or "Lost connection to MySQL server during query" meaning nothing every gets entered into the database anyway. Don't suppose there is a way to split the query so it only inserts 100 at a time rather than trying to get all of them in?
  13. Solved. It appears inserting lots of rows in one go can cause MySQL to DIE! - fixed by simply lowering the number of rows per time.
  14. Nothing at all inserts. But as i say this query works fine outside of the ForEach loo. Not sure why the connection would fail now.
  15. this is the error i get. sorry i forgot to post earlier "Lost connection to MySQL server during query" Why would the connection be lost?
  16. That doesnt make any difference. From what i can gather i believe the query is fine - i just think im missing some secret code that allows me to insert rows into a database using loops which i possible surly. Thanks for your help though :-)
  17. I'm using a foreach loop to output all of the information from an array. Within this while loop i have a MySQL query that is supposed to insert the outputted array into the database, each record on a new row as you would expect. Yet for some reason it refuses to write to a database at all. I know the MySQL query is because i have tried it outside of the Foreach loop and it inserts perfectly. Not sure what could cause this or whether i'm over looking someone massivly obvious. Below is the code i'm using. foreach ($feed->get_items() as $item){ $feed = $item->get_feed(); $favico = $feed->get_favicon(); $feedtitle = $feed->get_title(); $link = $item->get_permalink(); $title = $item->get_title(); $content = $item->get_content(); $date = $item->get_date('U'); $favico = mysql_real_escape_string($favico); $feedtitle = mysql_real_escape_string($feedtitle); $link = mysql_real_escape_string($link); $title = mysql_real_escape_string($title); $content = mysql_real_escape_string($content); $date = mysql_real_escape_string($date); //Determine better source name if($feedtitle == "") {$source = "";} elseif($feedtitle == "Twitter / slaterjohn") {$source = "Twitter"; $prefix = "John Just Tweeted ";} elseif($feedtitle == "digg / johnslater / history") {$source = "Digg"; $prefix = "John Just Dugg ";} elseif($feedtitle == "Johnslater's Recently Played Tracks") {$source = "Last.fm"; $prefix = "John is Listening to ";} elseif($feedtitle == "Uploads from slater.john") {$source = "Flickr"; $prefix = "John just took a new Photo called ";} elseif($feedtitle == "John Slater's Facebook Posts") {$source = "Facebook"; $prefix = "John just posted ";} elseif($feedtitle == "slater.john - Latest News") {$source = "Blog"; $prefix = "John just posted ";} elseif($feedtitle == "slater.john - Latest Reviews") {$source = "Reviews"; $prefix = "John just reviewed ";} elseif($feedtitle == "slater.john - Articles") {$source = "Articles"; $prefix = "New Article called ";} elseif($feedtitle == "YouTube :: Videos by johnslater") {$source = "YouTube"; $prefix = "John has added the video ";} $query1 = "INSERT INTO `slaterjohn`.`minifeed` (`miniID`, `feedtitle`, `itemtitle`, `itemdate`, `itemlink`, `itembody`, `favico`) VALUES (NULL , '1', '2', '3', '4', '5', '6');"; mysql_query($query1); echo $source.$title.$date.$link.$content.$favico.'<br />'; } As you can see i have even put in 1,2,3,4,5,6 for the values and not even these will insert. Something is being strange. Thanks in advanced.
  18. What function can i used to scan an external (on another server) file for the mine type and echo it out. All the details on PHP.net dont seem to work. Any idea?
  19. I'm unable to find anything on the PHP website or on Google that seems to do what i require. I'm trying to find a way to split a string into an array or something at every comma. So i want something like this... List: 1,2,3,4,5,6,7,8,9,10 to be outputted as... 1 2 3 4 5 6 7 8 9 10 Hope you can help or point me in the right direction.
  20. I want to count rows with PHP from mysql, then with each total i want to order them. So like you would normally output with MySQL and order it in the query i want to do a row round for several row-count-queries and then order them highest to lowest. Thanks.
  21. After slightly more testing and after putting this at the end of my function like you suggested it appear it only works with one value however i need to call several values from the same function. Only the top one (username) is being used and no matter which value i try to call it always calls username
  22. Is there anyway i can set up all of these varibles then just call them as normal like $cookie_username I currently have this... $cookie_fname = $cookie_fname=cookie(); $cookie_lname = $cookie_lname=cookie(); $cookie_username = $cookie_username=cookie(); $cookie_set = $cookie_set=cookie(); But for some reason the top one cancels out all of the others
  23. It looks like that has fixed my problem. thanks for your help :-)
×
×
  • 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.