This is getting really frustrating, but I guess that's what I get for trying something seemingly advanced without getting a complete grasp on the basics.

The thing is that a friend of mine asked me to build a site for her in trade for some massages for my Fiance's leg. He's already had two, and I still don't have a site for her.

Here goes:

I'm writing code for a new vBulletin page, and I'm having some trouble. I'd ask there, but this is a straight PHP question rather than a vBulletin question.

For the sake of clarity, all vB functions appear to be working properly, and I don't need help with them (I already got help with those on the vB.org forums).

What I need is to fine the primary numerical key in a multidimentional array that contains associative arrays.

Where I'm having problems is here:

if($vbulletin->userinfo['userid']){


$planners = $vbulletin->db->query_read("
	SELECT *
	FROM " . TABLE_PREFIX . "planners
	WHERE memberid = " . $vbulletin->userinfo['userid'] . "
	ORDER BY id DESC
");

$planners_array = array();
$planners_array[] = $vbulletin->db->fetch_array($planners);

if($vbulletin->GPC['planner']){

	$plannerid = $vbulletin->GPC['planner'];

	for($key = 0 ; isset($planners_array[$key]['id']) ; $key++){

		if($plannerid = $planners_array[$key]['id']){

			$planner = $key;
		}

	}

} else {

	$planner = 0;

}

$menuids = $planners_array[$planner][menuids];

$menus = $vbulletin->db->query_read("
	SELECT id, shortdescription, mealtype
	FROM " . TABLE_PREFIX . "menus
	WHERE id IN ($menuids)
");

}

When I type the planner ID that I need in the browser, it defaults to $planner=0

What might I be doing wrong here (I know, I'm oprobably WAY off. Noob, as I mentioned.).

Thanks! 🙂

    I'm not 100% sure what you want to accomplish, but I suspect it would be clearer if you could run your code with this modification to get some debug data:

    $planners_array = array();
    $planners_array[] = $vbulletin->db->fetch_array($planners);
    // add these lines just for debugging:
    echo "<pre>" . print_r($planners_array, 1) . "</pre>\n";
    exit;
    // end of debug code
    

    Then copy-and-paste the result here (within [noparse]

    [/noparse] tags) so we can see what the array looks like that you are trying to parse.
    
    (One likely problem is the use of "=" instead of "==" in your [b]if[/b] comparsion, but I'm by no means sure that's the only problem.)

      Thank you.

      Actually, that helped a lot because I now see that my first query is only returning one result.

      Maybe I need to go back to the vB forums to figure this out. Something isn't right.

      On another note, either I'm a genius or I have ZERO idea what I'm doing because people keep asking me what I'm trying to accomplish (I'll go for the latter). 😉

      I thought about the "==" instead of "=", but that broke my script.

      Yeah, I'm prolly WAY off here. 🙁

        Most likely the $vbulletin->db->fetch_array() is designed to return one result row, with the idea that if it is a multi-row result then you will have it within a loop. If you want to populate an array with the results, you could do something like:

        $resultArray = array();
        while($row = $vbulletin->db->fetch_array())
        {
           $resultArray[] = $row;
        }
        

          Hmmm...so it WAS an issue with my vB function (or rather, my misunderstanding of it).

          Thank you so much! That produced EXACTLY the results I was hoping for! 🙂

          Final WORKING code:

          if($vbulletin->userinfo['userid']){
          
          
          $planners = $vbulletin->db->query_read("
          	SELECT *
          	FROM " . TABLE_PREFIX . "planners
          	WHERE memberid = " . $vbulletin->userinfo['userid'] . "
          	ORDER BY id DESC
          ");
          
          $planners_array = array();
          while($row = $vbulletin->db->fetch_array($planners)){
          	$planners_array[] = $row;
          }
          
          if($vbulletin->GPC['planner']){
          
          	$plannerid = $vbulletin->GPC['planner'];
          
          	for($key = 0 ; isset($planners_array[$key]['id']) ; $key++){
          
          		if($plannerid == $planners_array[$key]['id']){
          
          			$planner = $key;
          
          			break;
          
          		} else {
          
          			$planner = 0;
          
          		}
          
          	}
          
          } else {
          
          	$planner = 0;
          
          }
          
          $menuids = $planners_array[$planner][menuids];
          
          $menus = $vbulletin->db->query_read("
          	SELECT id, shortdescription, mealtype
          	FROM " . TABLE_PREFIX . "menus
          	WHERE id IN ($menuids)
          ");
          
          }
          
            Write a Reply...