Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-05-19
10
Medium Priority
?
309 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

610 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