SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    3MTA3
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    1,016
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    having issues with array_walk()

    I need to run a function that highlights a searched word on each row that is pulled from the db. I've been trying to use array_walk(), but can't get it to work right.
    PHP Code:
    $row_rsCC mysql_fetch_array($rsCC);
    array_walk($row_rsCC,'str_highlight'); 
    I've also tried this, but it only hightlights the first row:
    PHP Code:
    $row_rsCC str_highlight($row_rsCC$getQuery); 
    What's going on here? Can you not call array_walk() on a fetched array?

    Or is there a better way to do this?

  2. #2
    SitePoint Enthusiast Redprince's Avatar
    Join Date
    May 2004
    Location
    Salzgitter, Lower Saxony, Germany
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems that array_walk() cannot handle multidimensional arrays. Use foreach() to walk through your fetched result and try array_walk() there again

  3. #3
    3MTA3
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    1,016
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still having problems... Can someone give me an example on how I could perform the function to each row that's pulled from the db?

  4. #4
    3MTA3
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    1,016
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can anyone help me with this? I know it's something simple that I'm not understanding correctly. I've tried various ways with no luck.

  5. #5
    Chessplayer kleineme's Avatar
    Join Date
    Apr 2004
    Location
    Germany
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    if you say

    Code:
    $row_rsCC = mysql_fetch_array($rsCC);
    it will fetch the first row from the resultset. If you want to process all rows you would have to it in a loop:

    Code:
    while ($row_rsCC = mysql_fetch_array($rsCC)) {
      array_walk($row_rsCC,'str_highlight');
    }
    Never ascribe to malice,
    that which can be explained by incompetence.
    Your code should not look unmaintainable, just be that way.


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
  •