Solved

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

Posted on 2009-05-19
10
287 Views
Last Modified: 2012-05-07
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
Comment
Question by:phillystyle123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 5

Expert Comment

by:dhobale
ID: 24424326
$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
 
LVL 3

Expert Comment

by:webvogel
ID: 24424341
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
 

Author Comment

by:phillystyle123
ID: 24424467
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:phillystyle123
ID: 24424543
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
 
LVL 3

Expert Comment

by:webvogel
ID: 24425366
$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
 
LVL 3

Expert Comment

by:webvogel
ID: 24426528
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
 

Author Comment

by:phillystyle123
ID: 24428078
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
 

Author Comment

by:phillystyle123
ID: 24428085
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
 
LVL 3

Expert Comment

by:webvogel
ID: 24431186
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
 
LVL 2

Accepted Solution

by:
miyosia earned 500 total points
ID: 24431351
$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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
AJAX Wordpress Not Reading Variable 2 59
Php logic to add to date card 9 40
PHP Curl Problem 10 42
blocking the posted data from outside of my domains 8 25
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question