Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
mysql_fetch_array problem
Old 03-06-2005, 10:39 AM mysql_fetch_array problem
Super Talker

Posts: 121
Trades: 0
Here is my code:

PHP Code:
                $bandListSql "SELECT * FROM bands ORDER BY name";
        
$bandListSql mysql_query($bandListSql);
                
        function 
output_band_list($pos){
            echo 
'<option value="-1" selected>---------</option>';
            while(
$r mysql_fetch_array($bandListSql)) {
                
$bandList .= '<option value="'.$r['id'].'">'.$r['name'].'</option>';
            }
//end while
            
mysql_data_seek($r0); //reset pointer 
        
}//end function 
It out puts to a dropdown list but all that i am getting is:
---------

its not doing the rest can anyone see why?
vegancoder is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-06-2005, 10:49 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
$bandListSql is not in the scope of your function, so essentially empty. You either need to pass it in as a parameter to your function, or put the line

global $bandListSql;

as the first line of function code - this way it will refer to the $bandListSql variable outside your function.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 03-07-2005, 06:33 AM
Super Talker

Posts: 121
Trades: 0
ok that was part of the problem, but i think i have fixed it, i wasnt outputting the list i was just assigning it to a variable
vegancoder is offline
Reply With Quote
View Public Profile
 
Old 03-07-2005, 07:04 AM
Super Talker

Posts: 121
Trades: 0
ok, i have another problem, here is my function:

PHP Code:
function output_band_list($pos){
          global 
$bandListSql;
            global 
$bandGigArray;
            echo 
'<option value="-1">---------</option>';
            
            while(
$r mysql_fetch_array($bandListSql)) {
                if(
$r['id'] == $bandGigArray[$pos]){
                    echo 
'<option value="'.$r['id'].'" selected>'.$r['name'].'</option>';
                }else{
                    echo 
'<option value="'.$r['id'].'">'.$r['name'].'</option>';
                }
//end if
            
}//end while
            
mysql_data_seek($r0); //reset pointer 
        
}//end function 
It works perfectly on the first call of it, but after that it doesnt work, it just outputs ---------
i assume its something to do with the while loop, but i thought mysql_data_Seek would fix that
vegancoder is offline
Reply With Quote
View Public Profile
 
Old 03-07-2005, 11:40 AM
Phaedrus's Avatar
Ultra Talker

Posts: 271
Location: CA
Trades: 0
I would try extracting $r outside the function, and declaring it global.
PHP Code:
global $bandListSql;
global 
$bandGigArray
global 
$r 
Reset the pointer at the beginning of the function just to be sure it's good to go, then go over $r with a foreach() loop.
__________________

Please login or register to view this content. Registration is FREE

Last edited by Phaedrus; 03-07-2005 at 11:45 AM..
Phaedrus is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to mysql_fetch_array problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.52099 seconds with 12 queries