• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

how do i use the same url parameter twice in one qurey?

hi - i'm trying to use the same url parameter 2x in one query - in other words i need to use menu_item_link = '%s'twice - i'm getting a "too few arguments error - how can i do this without drastically overhauling my existing code??

thanks!
$filter = sprintf("AND LCASE(mp.menu_title) = '%s' AND m.page_parent_id = (SELECT id FROM menu_items WHERE menu_item_link = '%s')  AND m.top_level_id = (SELECT id FROM menu_items WHERE menu_item_link = '%s')", $menulocation, $page);

Open in new window

0
phillystyle123
Asked:
phillystyle123
1 Solution
 
dhobaleCommented:
$filter = sprintf("AND LCASE(mp.menu_title) = '%s' AND
m.page_parent_id = (SELECT id FROM menu_items WHERE menu_item_link = '%s')  AND m.top_level_id = (SELECT id as id2 FROM menu_items WHERE menu_item_link = '%s')", $menulocation, $page);
0
 
webvogelCommented:
For every %s you have to write a parameter, but you can use one parameter more than one time:
$filter = sprintf("AND LCASE(mp.menu_title) = '%s' AND m.page_parent_id = (SELECT id FROM menu_items WHERE menu_item_link = '%s')  AND m.top_level_id = (SELECT id FROM menu_items WHERE menu_item_link = '%s')", $menulocation, $menulocation, $page);

Open in new window

0
 
phillystyle123Author Commented:
dhobale - thanks for trying -your solution still renders the same error though:

Warning: sprintf() [function.sprintf]: Too few arguments in /home/taylorwi/public_html/includes/functions.php on line 187

webvogel - your solution made the list i'm trying to output disapear.

can't  i do something like this:

$filter = sprintf("AND LCASE(mp.menu_title) = '%s' AND m.page_parent_id = (SELECT id FROM menu_items WHERE menu_item_link = '%s')  AND m.top_level_id = (SELECT id FROM menu_items WHERE menu_item_link = "$_GET[$page"])", $menulocation,  $page);
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
phillystyle123Author Commented:
or can i somehow create another variable that is equal to $page - i'm afraid i didn't write this code so i'm at a bit of a loss here.

something like <?php $page==$page2?>


here's a more expanded version of my code:
 
//Get menu elements
	function getMenu( $menulocation, $toplevel=0 ) {
		global $d, $page, $parent_id, $subpage;
 
		//Determine type of menu to call
		$menu_array = array();
		if ($toplevel):
			$filter = sprintf("AND LCASE(mp.menu_title) = '%s' AND m.page_parent_id = 0", $menulocation);
		else:
			$filter = sprintf("AND LCASE(mp.menu_title) = '%s' AND
m.page_parent_id = (SELECT id FROM menu_items WHERE menu_item_link = '%s')", $menulocation, $page, $subpage);
		endif;
		$sql = "SELECT m.id, m.menu_item_title, m.menu_item_link, m.browser_target,
				m.is_restricted, p.module_id, m.top_level_id, menu_position_id, page_parent_id FROM menu_items m
				INNER JOIN menu_position mp ON m.menu_position_id = mp.id AND m.is_active = 1
				INNER JOIN pages p ON p.id = m.page_id $filter ORDER BY m.oindex";

Open in new window

0
 
webvogelCommented:
$filter = sprintf("AND LCASE(mp.menu_title) = '%s' AND m.page_parent_id = (SELECT id FROM menu_items WHERE menu_item_link = '%s')  AND m.top_level_id = (SELECT id FROM menu_items WHERE menu_item_link = '%s'", $menulocation, $page, $page);
0
 
webvogelCommented:
The solution for the error "Warning: sprintf() [function.sprintf]: Too few arguments in /home/taylorwi/public_html/includes/functions.php on line 187" I posted above.

Maybe you have more problems: $filter = sprintf("AND ... has to begin with "WHERE" and not with "AND":
$filter = sprintf("WHERE ...

Than $filter comes with two %s, but with 3 parameters.

If you want a second variable, do that:
$page2 = $page;
because this is a comparison:
$page==$page2

And this $_GET[$page"] is also not right. Use:
$_GET['page']
$page
or in a doublequoted string:
" ...   $_GET[page]   ... "
0
 
phillystyle123Author Commented:
hmm - still getting a too few arguments error with the $page2 idea and the GET variables just don't work - no error but no menu generated - i'm trying another approach - much simpler - i'll post the link on this question
0
 
phillystyle123Author Commented:
i believe i'm not writing this correctly:

$query_rsSubMenu = "SELECT menu_item_title FROM menu_items WHERE page_parent_id ='50'";

what am i doing wrong?

see code for how i'm trying to use it:


else :
				$query_rsSubMenu = "SELECT menu_item_title FROM menu_items WHERE page_parent_id ='50'";
				
				
				echo "\t<li style=\"background:url(images/photobutton_" . $value['id'] . ".jpg) no-repeat;\"><a ".($subpage=="management" && $value['id']=="50" ? 'class="active"' : ''). "   href=\"" . menus::checksef($url) . "\" $target $active tabindex=\"" . $ak->tabindex($key) . "\" onMouseover=\"dropdownmenu(this, event, menu" . $value['id'] . ", '192px')\" onMouseout=\"delayhidemenu()\">" . $value['title'] . "</a></li>\n"; 
				if ($value['id']=="50") //this is for that tricky 2nd level submenu
				echo "<ul class=\"secMenu\">
							<li>".$row_rsSubMenu['menu_item_title']."</li>
						</ul>";
			endif;

Open in new window

0
 
webvogelCommented:
This code is correct, if sprintf is to difficult for you, use

$filter = "AND LCASE(mp.menu_title) = '$menulocation' AND m.page_parent_id = (SELECT id FROM menu_items WHERE menu_item_link = '$page')  AND m.top_level_id = (SELECT id FROM menu_items WHERE menu_item_link = '$page'";
0
 
miyosiaCommented:
$filter = sprintf("AND LCASE(mp.menu_title) = '%s' AND m.page_parent_id = (SELECT id FROM menu_items WHERE menu_item_link = '%s')  AND m.top_level_id = (SELECT id FROM menu_items WHERE menu_item_link = '%s')", $menulocation, $page, $page);

that should work  think.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now