Jump to content

Results ending up in a strange place


hdshngout

Recommended Posts

For a site I am working on, I allow users to enter a simple code to pull their pictures from flickr.  On the profile part however, I am running into a bit of trouble.  The flickr results appear correctly, just in the wrong spot.  In order to accomplish this, I have used preg_replace alongside preg_match.

 

In short, I am trying to read the bit of code and replace it with the correct photos.  I can not figure out how to control where the results appear.  Any help would be greatly appreciated.

 

(And a bit more information, I am using

PHP 5

Flickr API

phpFlickr

)

 

The bit of code I believe the trouble is with are

$sql_flickr = mysql_query("SELECT * FROM exterior_services WHERE owner='$userid' AND service='flickr'") or die(mysql_error());
$flickr = mysql_fetch_array($sql_flickr);
$flickr_username = $flickr[username];
$flickr_num = $flickr_match[1];
$flickr_new_row = $flickr_match[2];

if(strstr($custom_coding, '<widget>$flickr_display') == TRUE) {
//$custom_coding = preg_replace('/<widget>\$flickr_display\((\d+),(\d+)\)<\/widget>/',include('profile_stuff/flickr.php'),$custom_coding);

$custom_coding = preg_replace('/<widget>\$flickr_display\((\d+),(\d+)\)<\/widget>/','',$custom_coding); 
include('profile_stuff/flickr.php');
}

 

and then the phpFlickr part

<?php
define('secure','true');
require_once("services/flickr/phpFlickr.php");
// Create new phpFlickr object
$f = new phpFlickr($api_key);
$f->enableCache(
    "db",
    "mysql://$db_user:$db_pass@$db_pass/$db_name"
);

$i = 0;
    // Find the NSID of the username inputted via the form
    $person = $f->people_findByUsername($flickr_username);
    
    // Get the friendly URL of the user's photos
    $photos_url = $f->urls_getUserPhotos($person['id']);
    
    // Get the user's first 36 public photos
    $photos = $f->people_getPublicPhotos($person['id'], NULL, $flickr_num);
    
    // Loop through the photos and output the html
    foreach ($photos['photo'] as $photo) {
        echo "<a href=$photos_url$photo[id]>";
        echo "<img border='0' alt='$photo[title]' ".
            "src=" . $f->buildPhotoURL($photo, "Square") . ">";
        echo "</a>";
        $i++;
        // If it reaches the sixth photo, insert a line break
        if ($i % $flickr_new_row == 0) {
            echo "<br>\n";
        }
    }
?>

 

Once again, I greatly appreciate all help given.

 

-Nick

Link to comment
https://forums.phpfreaks.com/topic/39729-results-ending-up-in-a-strange-place/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.