Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    New Coder
    Join Date
    Nov 2009
    Posts
    17
    Thanks
    8
    Thanked 0 Times in 0 Posts
    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

  2. #17
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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

  3. Users who have thanked Fumigator for this post:

    codingForumsFTW (11-20-2009)

  4. #18
    New Coder
    Join Date
    Nov 2009
    Posts
    17
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Thank you! This works perfectly!

    PHP Code:
    foreach ($aResults as $key=>$value) {    
        echo 
    "{$value['info']}, {$value['value']}|{$value['id']}\n"

  5. #19
    New Coder
    Join Date
    Nov 2009
    Posts
    17
    Thanks
    8
    Thanked 0 Times in 0 Posts
    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" />


 
Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •