Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-20-2009, 08:58 PM   PM User | #16
codingForumsFTW
New Coder

 
Join Date: Nov 2009
Posts: 17
Thanks: 8
Thanked 0 Times in 0 Posts
codingForumsFTW is an unknown quantity at this point
im so lost don't understand this...

PHP Code:

foreach ($aResults as $key=>$value) {    
    echo 
"{$row['s_last']} |{$value['id']}\n"
gives me this

|20

PHP Code:

foreach ($aResults as $key=>$value) {    
    echo 
"$key{$row['s_last']} |{$value['id']}\n";        

gives me this
0 |20


totally stupid question i know
codingForumsFTW is offline   Reply With Quote
Old 11-20-2009, 09:44 PM   PM User | #17
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,687
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
Hey no worries, we all get lost occasionally. It's how you learn!

And it's partially my fault, because my previous message suggested you look at $row, but that's wrong in this situation.

Check out how a foreach() loop works. You loop through an array using substitute variables for the key and value of each element in the array. You are referring to the $row array, inside that foreach(), but you should be looking at the substitute variable $value, which is actually an array itself. That's why using $value['id'] is working. Bottom line, try $value['s_last'].

And for more enlightenment, because we're all here to learn:

http://us3.php.net/manual/en/language.types.array.php
http://us3.php.net/manual/en/control...es.foreach.php
__________________
Fumigator is offline   Reply With Quote
Users who have thanked Fumigator for this post:
codingForumsFTW (11-20-2009)
Old 11-20-2009, 09:51 PM   PM User | #18
codingForumsFTW
New Coder

 
Join Date: Nov 2009
Posts: 17
Thanks: 8
Thanked 0 Times in 0 Posts
codingForumsFTW is an unknown quantity at this point
Thank you! This works perfectly!

PHP Code:
foreach ($aResults as $key=>$value) {    
    echo 
"{$value['info']}, {$value['value']}|{$value['id']}\n"
codingForumsFTW is offline   Reply With Quote
Old 11-20-2009, 10:41 PM   PM User | #19
codingForumsFTW
New Coder

 
Join Date: Nov 2009
Posts: 17
Thanks: 8
Thanked 0 Times in 0 Posts
codingForumsFTW is an unknown quantity at this point
ok i have auto complete that i want to be able to select a column of the database before searching on it
i just want to pass the oneone variable over to the php page.

so i have this javascript

Code:
<script type="text/javascript">
$().ready(function() {

	function log(event, data, formatted) {
		$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
	}
	
	$("#search").autocomplete("test.php", {
		width: 260,
		selectFirst: false
	});
	$("#search").result(function(event, data, formatted) {
		if (data)
			$(this).parent().next().find("input").val(data[1]);
	});
	
	
$(":text, textarea").result(log).next().click(function() {
		$(this).prev().search(); // shows resluts
	});

});


</script>
the html

Code:
	<p class="field" > <select id="oneone" name="oneone" style="width:100px;margin:5px 0 5px 0;" value="">
		<option value="s_last">Last Name</option>
<option value="s_first">First Name</option>

<label>Search</label>
			<input type="text" id="search" />
		</p>
		<p>
			<label>Hidden input</label>
			<input  type="text" id="inputit" />
codingForumsFTW is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:08 PM.


Advertisement
Log in to turn off these ads.