Nah -- Should never more than 100 links. Here is my code so far (it uses arrays):
Code: Select all
<?php
class portfolio {
// Initialize object varibles
var $curUserID = 0;
var $curLinkID = 0;
var $userCount = 0;
var $linkCount = 0;
var $users = array();
var $links = array();
// call to initilize the object
function init() {
$this->buildLinkArray();
$this->buildUserArray();
$this->userCount = count( $this->users );
$this->linkCount = count( $this->links );
}
// call to reset the object
function reset() {
$this->curUserID = 0;
$this->curLinkID = 0;
unset($this->users);
unset($this->links);
}
// gets all links from database and assigns values to array "$links"
// Used by init() function
function buildLinkArray() {
$result_links = mysql_query("select gallery_links.* from gallery_links");
while( $res = mysql_fetch_assoc( $result_links ) ) {
$dataї] = $res;
}
$this->links = $data;
}
// gets all users from database and assigns values to array "$users"
// Used by init() function
function buildUserArray() {
$result_links = mysql_query("select gallery_people.* from gallery_people");
while( $res = mysql_fetch_assoc( $result_links ) ) {
$dataї] = $res;
}
$this->users = $data;
}
// Show user details
function UserDetails($arg="") {
switch($arg) {
case "id":
return($this->usersї$this->curUserID]ї"ID"]);
break;
case "name":
return($this->usersї$this->curUserID]ї"name"]);
break;
case "email":
return($this->usersї$this->curUserID]ї"email"]);
break;
default:
return($this->usersї$this->curUserID]ї"ID"]);
break;
}
}
}
?>I tried using a while loop to iterate through the links array and check for the appropriate ID, but I am not satisfied with that solution. What I would really like to do is return a smaller array containing just the links for that user so that I can loop through the array and format as I wish without hardcoding any html into my class.
So, essentially, I am trying to build a smaller multidimensional array out of a larger multidimensional array by extracting the values (and keys) that match the supplied user id.
Whew...
Phil