Jump to content

yanisdon

Members
  • Posts

    23
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

yanisdon's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. check this out: http://www.php.net/oop
  2. 1) Get rid of that initialisation: $_SESSION['user']=0; $_SESSION['userid']=0; 2) You're assigning the value of $_POST['user'] to a variable called '$username' $username=$_POST['user']; $password=$_POST['password']; and later a variable called "$user" to 'user' (Member of the Session array): $_SESSION['user']=$user; // SETTING THE SESSIONS I reckon it should be : $_SESSION['user']=$username; // SETTING THE SESSIONS .. to start with.. And, why using blody javascript for a simple task such as redirecting?? Just do it with PHP, e.g like this: <?php header( 'Location: http://www.yoursite.com/blah.html' ) ; exit; ?> check this out: http://au2.php.net/header ..or use http refresh etc.. Cheers!
  3. Because I am using the stdClass later in the code as well and it's more flexible for me. Of course I could convert the whole thing into an array, then sort the stuff etc., but using an object is just the best option for my code here..
  4. Hi there, I've got an array of objects. The print_r() looks like this: stdClass Object ( [type] => book [name] => Book page [module] => book [description] => A book is a collaborative writing effort: users can collaborate writing the pages of the book. [help] => [has_title] => 1 [title_label] => Title [has_body] => 1 [body_label] => Body [min_word_count] => 0 [custom] => 0 [modified] => 1 [locked] => 1 [orig_type] => book ) stdClass Object ( [type] => event [name] => Event [module] => basicevent [description] => An event is a planned event with a start and end date, and displays in the events calendar. [help] => [has_title] => 1 [title_label] => Title [has_body] => 1 [body_label] => Body [min_word_count] => 0 [custom] => 0 [modified] => 1 [locked] => 1 [orig_type] => event ) stdClass Object ( [type] => blog [name] => Blog entry [module] => blog [description] => A blog is a regularly updated journal or diary made up of individual posts. [help] => [has_title] => 1 [title_label] => Title [has_body] => 1 [body_label] => Body [min_word_count] => 0 [custom] => 0 [modified] => 1 [locked] => 1 [orig_type] => blog ) What I like to be doing here is basically to sort 'alphabetically' by [type]. I can't use sort() since it expects an array. Any ideas?
  5. That works: <?php // FUNCTION: function paginate($array,&$offset,$perpage=10){ $offset = $offset?$offset:0; if($offset >= count($array)) return FALSE; $page = array_slice($array,$offset,$perpage,TRUE); $offset+=$perpage; return $page; } // USAGE: // build a test array for($i=0;$i<=5000;$i++){ $array[$i] = 'item '.$i; } // set your offset variable $offset = 1; // paginate it some to test it while( $a=paginate($array,$offset) ){ print_r($a); } ?> /** Array ( [1] => item 1 [2] => item 2 [3] => item 3 [4] => item 4 [5] => item 5 [6] => item 6 [7] => item 7 [8] => item 8 [9] => item 9 [10] => item 10 ) Array ( [11] => item 11 [12] => item 12 [13] => item 13 [14] => item 14 [15] => item 15 [16] => item 16 [17] => item 17 [18] => item 18 [19] => item 19 [20] => item 20 ) Array ( [21] => item 21 [22] => item 22 [23] => item 23 [24] => item 24 [25] => item 25 [26] => item 26 [27] => item 27 [28] => item 28 [29] => item 29 [30] => item 30 ) Array ( [31] => item 31 etc, etc,......... */
  6. Thanks for the response. Well, maybe I need to add that I don't want to generate a real paging mechanism. A little bit of background. My little app parses a remote RSS file with Magpie. Basically Magpie parses the content of a given RSS file into a PHP object. So far so good. The RSS file in question is being generated by a remote Server which is prone to timeout. The RSS file contains dynamic parameter for the total number of items and the pagesize which can be used to manipulate the $_GET parameter in order to bypass the timeout issue. So again: 1) the array contains 5000 items. 2) start to loop through the array and get the first 10 items (1 -10) 3) do something with those 10 items.. 4) now go back and get the next 10 items (11-20) 5) do something with those 10 items.. 4) now go back and get the next 10 items (21-30) and so on.. Cheers.
  7. Hi, I want to create a loop which iterates through an array in steps of 10 Let's assume we have an array. Array ( [0] => Array ( [title] => Title one [link] => http://www.mylink.com [description] => This is a test description [dot] => Array ( [source] => test source [relevance] => 1.0 [metadata_score] => 0.3505949 [metadata_collection] => Test collection [metadata_mimetype] => text/html [metadata_size] => 0 [metadata_url] => http://www.test.com ) [summary] => This is just a test summary ) [1] => Array ( [title] => Title one [link] => http://www.mylink.com [description] => This is a test description [dot] => Array ( [source] => test source [relevance] => 1.0 [metadata_score] => 0.3505949 [metadata_collection] => Test collection [metadata_mimetype] => text/html [metadata_size] => 0 [metadata_url] => http://www.test.com ) [summary] => This is just a test summary ) etc, etc.. So far so good. Now let's assume the array contains aprox. 5000 items and this value would be represented by a variable called $totaValue What I really like to be doing here is to loop through the array in steps of 10 and by doing that to create some sort of paging mechanism in order to avoid any impacts triggered by server timeout's etc. Say I've got these values in $arr_param[]: [totalresults] => 200 [startindex] => 1 [itemsperpage] => 10 //$arr_param['itemsperpage'] So I'd need to create a loop or a function which loops through the entire array and iterates 10 times ($arr_param['itemsperpage']). After that go back and procede with the next 10 iterations and so on. In order to be able to achieve this I'd need to set the $arr_param[startindex] to 11, next time to 21 and next to 31 and so on.. : How can this be done? Any ideas? Cheers
  8. Thanks for the leverage. Here's the working function: /** * Customize a definition list. * * @param dt_data * An array of values to be placed within the <dt> part * * @param ddt_data * An array of values to be placed within the <dd> part * * @param title * Optional parameter. If set a title will be displayed * * @param cls * optional parameter. If set a css class will be added * to the definition list */ function theme_definition_list($dt_data, $dd_data, $title = NULL, $cls = NULL) { if (!empty($title)) { $output .= '<h3>'. $title .'</h3>'; } $output .='<dl'.(!empty($cls)?' class="'.$cls.'"':'').'>'."\n"; $dl_array = array_combine($dt_data, $dd_data); foreach ($dl_array as $dt=>$dd) { $output .= '<dt>'.$dt.'</dt>'."\n"; $output .= '<dd>'.$dd.'</dd>'."\n"; } $output .='</dl>'."\n"; return $output; } Here's how to call the function: $invite_header = array('Accepted', 'Pending', 'Expired'); $invite_row = array(invites_status('accepted'), invites_status('pending'), invites_status('expired')); $invite_title = 'test'; $invite_class = 't-display'; $content = theme_definition_list($invite_header, $invite_row, $invite_title, $invite_class);
  9. Hi there, I want to create a function which can take two arrays and build a definition list from it. <?php But instead of : /* * title * * one * 1 * two * 2 * three * 3 */ I get this: /* * title * * one * * two * * three * * 1 * * 2 * * 3 * */ ?> Here's what I got so far: <?php function theme_definition_list($dt_data, $dd_data, $title = NULL) { if (isset($title)) { $output .= '<h3>'. $title .'</h3>'; } $output .='<dl>'."\n"; foreach($dt_data as $dt_val){ $output .= '<dt>'.$dt_val.'</dt>'."\n"; } foreach($dd_data as $dd_val){ $output . '<dd>'.$dd_val.'</dd>'."\n"; } $output .='</dl>'."\n"; return $output; } $a = array('one','two','three'); $b = array('1','2','3'); $c = 'title'; $show_output = theme_definition_list($a, $b, $c); print_r($show_output); /* * This is what I like to get: * title * * one * 1 * two * 2 * three * 3 */ ?> Any suggetsions? Cheers
  10. Here's the solution: I could also do something similar to serialize but use hash instead. As I add the objects to an array, I have the hash being the array key, then before I add an object to the array I see if the hash already exists with array_key_exists(), if it does then I don't add it. Actually I don't even need to check if the hash is already set, I can just add them all and duplicate keys will overwrite, so in the end my array will have only distinct objects.
  11. Hi there, I've got the following issue: I've menaged to parse RSS data from a given XML file into a PHP object with SimpleXML. As this is quiet a trivial task, so far so good. At a particluar spot within the code I have the following object instances. Here's a print_r($obj); Two first two object instances are equal because they have the same attributes and values, wheras the third one is different. What I like to be doing here before going any further is to get rid of duplicates and only take unequal instances to proced with my methods and code. My idea now is to compare a particular attribute (E.g. $obj->title) and if that attribute appears to exist more than once, get rid of the/all duplicate/s. Something like DISTINCT in SQL if that make sense How can I get that going? Cheers! stdClass Object ( [type] => cbd [uid] => 1 [status] => 1 [promote] => 1 [sticky] => 1 [title] => Test 1 [body] => This CATS (Creating Accessible Teaching & Support) [teaser] => This CATS (Creating Accessible Teaching & Support) [ftype] => RSS [fversion] => 2.0 [fencoding] => UTF-8 [flanguage] => en [fmanagingeditor] => 2 [cmetadata_size] => 0 [taxonomy] => Array ( [tags] => Array ( [19] => [46] => [45] => Curriculum, Inclusive design, Curriculum, Learning design approaches [5] => ) ) ) stdClass Object ( [type] => cbd [uid] => 1 [status] => 1 [promote] => 1 [sticky] => 1 [title] => Test 1 [body] => This CATS (Creating Accessible Teaching & Support) [teaser] => This CATS (Creating Accessible Teaching & Support) [ftype] => RSS [fversion] => 2.0 [fencoding] => UTF-8 [flanguage] => en [fmanagingeditor] => 2 [cmetadata_size] => 0 [taxonomy] => Array ( [tags] => Array ( [19] => [46] => [45] => Curriculum, Inclusive design, Curriculum, Learning design approaches [5] => ) ) ) stdClass Object ( [type] => cbd [uid] => 1 [status] => 1 [promote] => 1 [sticky] => 1 [title] => Test 2 [body] => The use and efficacy of a simulation model [teaser] => The use and efficacy of a simulation model [ftype] => RSS [fversion] => 2.0 [fencoding] => UTF-8 [flanguage] => en [fmanagingeditor] => 2 [cmetadata_size] => 0 [taxonomy] => Array ( [tags] => Array ( [19] => Engineering and Related Technologies, Civil Engineering [46] => [45] => Flexible learning, Learning designs, Simulation-based learning [5] => ) ) )
  12. Thanks for that. With that code snippet, I'll get this: q=dc.date.lastmodified:%5b2007-05-01T00:00:00Z%20TO%202007-05-19T00:00:00Z%5d user=username sr=resource type=rss I get that already with parse_url: //So I get all desired values using something like this: $q_str = parse_url(REQUEST_URL, PHP_URL_QUERY); // get the query string // print $q_str; parse_str(html_entity_decode($q_str), $output); // split the query string into chunks // result: // Array // ( // [q] => dc.date.lastmodified:[2007-05-01T00:00:00Z TO 2007-05-19T00:00:00Z] // [user] => username // [sr] => resource // [type] => rss // ) I was actually trying to split the query part which is this: q=dc.date.lastmodified:%5b2007-05-01T00:00:00Z%20TO%202007-05-19T00:00:00Z%5d Cheers Jan
×
×
  • 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.