Solved

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

Posted on 2009-05-19
10
299 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

724 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