Create an Array Code Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • andyy15
    New Member
    • Jun 2007
    • 2

    #1

    Create an Array Code Help

    I have the following code:

    [CODE=php]$cPath_new_a = $categories['categories_id']. ",";
    $cPath_new_b = $cPath_new_a;

    $cPath_new_c = rtrim($cPath_ne w_b , ',');

    echo $cPath_new_c;
    [/CODE]

    $categories['categories_id'] pulls a sub category ID out of the database based on what main category the user is in. Let's say I am in a main category with 2 subcategories, 23 and 53. $categories['categories_id'] alone echos 2353. I want to make this into an array that contains 23 and 53.

    I thought the best way to accomplish this would be to add a , to make the string 23,53, then remove the last , then use explode(); to convert the comma delimited string into an array. However rtrim/substr both are not working for me.Using rtrim (see code above) outputs 2353, I also get the same result using substr. Is there some way to convert $cPath_new_a into an actual string within the code (not a dynamic variable) then apply rtrim or substr? Or am I approaching this whole thing incorrectly?

    I really appreciate any feedback.
  • DeMan
    Top Contributor
    • Nov 2006
    • 1799

    #2
    Hi andyy15,

    Welcome to thescripts. This looks to me suspiciously like database code, and I hoped you could help me out with which technology you were using. If you can, we can (possibly) move this thread to a specific forum where the experts will be better able to address your enquiry.

    Comment

    • andyy15
      New Member
      • Jun 2007
      • 2

      #3
      My Apology, I am using PHP. Please move my thread to the appropriate forum.

      Thanks

      Comment

      • DeMan
        Top Contributor
        • Nov 2006
        • 1799

        #4
        Consider it Done!! (Thank-You : Boy was I wrong on the DB)

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, andyy15.

          How are you fetching your results from the database? Every DAL that I've ever worked with (even the non-existent ones) automatically returns its results in the form of an array because of the way mysql_fetch_ass oc() returns results.

          Comment

          Working...