SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to get each line from an array and based on that select articles

    I have some bulk optional operation waiting for user to check in boxes which articles will be consider in this bulk actions.
    After checkbox is selected (articleID) I passing this values in array to another page, where I can extract this array as follows
    PHP Code:
    <?php
    $opt
    =$_GET['checkedRecords'];
    $action=$_GET['bulk_actions']; 
    $count_checked=count($opt);

    echo 
    "Selected $count_checked";
    foreach (
    $opt as $id){
        echo 
    "<br> $id";     
    }
    echo 
    "<br>$action"
    ?>
    the result is if I selected two articles
    PHP Code:
    Selected 2
    0   
    //id of article
    42 //id of article
    active //bulk operation to this selected articles 
    Now the question is, how can I limit this ID's 0, 42 to be variable names based on its value to select some article
    $id = 0,
    $id = 42, etc.
    I tried with
    PHP Code:
    $content Content::find_by_id($id); 
    but ofcourse it cannot found article cause ID is not set.

  2. #2
    SitePoint Addict telos's Avatar
    Join Date
    Mar 2005
    Location
    192.168.2.34
    Posts
    279
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $id cannot be both 0 AND 42 at the same time. One would either have to overwrite the previous value or be a single value in an array.

    I would do it like this:
    PHP Code:
    echo "Selected $count_checked";
    foreach (
    $opt as $id){
        
    $content Content::find_by_id($id);
        echo 
    $content;

    Alternatively, you could store the content in an associate array where the key is the ID of the content. For example:
    PHP Code:
    $content = array();
    foreach (
    $opt as $id){
        
    $content[$id] = Content::find_by_id($id);
    }
    print_r($content); 

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, after this second option you recommend me I got printed array
    PHP Code:
    Selected 2
    Array ( [95] => Content Object ( [ID] => 95 [Content] => asdddddddddd [Title] => sdaaaaaaaaa [Updated] => 1260715407 [Created] => 1260715407 [TemplateID] => [KeyWords] => [Visible] => [UserID] => ) [96] => Content Object ( [ID] => 96 [Content] => sadrzajh [Title] => decembar [Updated] => 1260715568 [Created] => [TemplateID] => [KeyWords] => [Visible] => [UserID] => ) ) 
    how can I make use of this in real world example, such as to catch id's of selected articles and use it for further processing.
    I'm just started scratching assoc. arrays.

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    found half working solution, please share your knowledge with me to finish this task and to figure assoc. arrays

    PHP Code:
    $opt=$_GET['checkedRecords'];
    $action=$_GET['bulk_actions']; 
    $count_checked=count($opt);

    echo 
    "Selected $count_checked";

    $id "("implode(","$opt).")";

    $record Content::find_by_id($id);
    $my_id $record->ID;
    $title $record->Title;
    echo 
    "<br>""$my_id " "$title."<br>"
    Only first record is displayed.

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't belive it was so simple at the end
    regards to telos.
    Final solution at the end is following

    PHP Code:
    foreach ($opt as $id){
       
    $content Content::find_by_id($id);
       
    $my_id $content->ID;
       
    $my_title $content->Title;
       echo 
    $my_id;
       echo 
    $my_title



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •