PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 4th, 2013, 01:08 PM
heybobo heybobo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 2 heybobo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 25 sec
Reputation Power: 0
Question PHP5 - Array

hi,

i have a php file with this code :

PHP Code:
 $items = array(
"Great Bittern"=>"Botaurus stellaris",
"Little Grebe"=>"Tachybaptus ruficollis",
"Black-necked Grebe"=>"Podiceps nigricollis",
"Little Bittern"=>"Ixobrychus minutus",
"Black-crowned Night Heron"=>"Nycticorax nycticorax",
"Purple Heron"=>"Ardea purpurea",
"White Stork"=>"Ciconia ciconia",
);



foreach (
$item as $key=>$value) {
    if (
strpos(strtolower($key), $q) !== false) {
        echo 
"$key|$value\n";
    }



it sends " echo "$key|$value\n"; " to my javascript.

so till here perfect

BUT now, i want to replace my $item array by a database query result

so i have for now :

PHP Code:
 $db = new mysqli('xx.x.xxx.xx',myusername,mypassowrd,mydb);
$query $db->query("SELECT * from mytable"); 


---> i want to sort out ID and TOWN and to put them in an array just like "$item" array above

PHP Code:
while ($result $query ->fetch_object()) {

$id =     $result->ID;                                         
$town=$result->TOWN;
                                            } 


only now, this code here :

PHP Code:
foreach ($result as $key=>$value) {
    if (
strpos(strtolower($key), $q) !== false) {
        echo 
"$key|$value\n";
    }



gives me every database result in one row without any <br> or \n .Just a mess, and it should come out as options of an select field. :-(


so the question is:

how can i get this :

PHP Code:
while ($result $query ->fetch_object()) {

$id =     $result->ID;                                         
$town=$result->TOWN;
                                            } 


like

PHP Code:
 $items = array(
"Great Bittern"=>"Botaurus stellaris",
"Little Grebe"=>"Tachybaptus ruficollis",
"Black-necked Grebe"=>"Podiceps nigricollis",
"Little Bittern"=>"Ixobrychus minutus",
"Black-crowned Night Heron"=>"Nycticorax nycticorax",
"Purple Heron"=>"Ardea purpurea",
"White Stork"=>"Ciconia ciconia",
); 



in order to use :

PHP Code:
foreach ($result as $key=>$value) {
    if (
strpos(strtolower($key), $q) !== false) {
        echo 
"$key|$value\n";
    }




????HELP !!!!!

Reply With Quote
  #2  
Old March 4th, 2013, 01:17 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
You don't want 'fetch_object'. You want 'fetch_all' or 'fetch_array'.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #3  
Old March 4th, 2013, 02:49 PM
heybobo heybobo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 2 heybobo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 25 sec
Reputation Power: 0
solution

and here the solution :

PHP Code:
while($rows mysql_fetch_array($result)){

echo 
$rows['VILLE']."\n";




:-)

THANKS FOR YOUR HELP ! ----it was too obvious ;-))
Comments on this post
Jacques1 disagrees: Please *do not* close your threads. There's still a lot to say about your current approach, but it's
not possible when the thread is already closed.
gw1500se disagrees: I will add my 2 cents as well and argee with Jacques1. I gave you the solution to your immediate
problem but you have a few additional issues that shojuld be dealt with even though your code seems
to work.

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP5 - Array

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap