Solved

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

Posted on 2009-05-19
10
256 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
10 Comments
 
LVL 5

Expert Comment

by:dhobale
Comment Utility
$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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:phillystyle123
Comment Utility
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
Comment Utility
$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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 3

Expert Comment

by:webvogel
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
$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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now