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
Old 08-25-2007, 10:49 AM Easy array - surely?
scrobins's Avatar
Skilled Talker

Posts: 50
Name: Stuart Robinson
Location: Busselton
Trades: 0
I'm a bit dense when it comes to arrays so I need a little help trying to understand what's going on with this code and how to fix it. Here's the code;

PHP Code:
for ( $n 0$n 4$n++) {

    
$blogRSS=mysql_result($result,$n,"blogRSS");
    
        
$urls=array($blogRSS);

I'm trying to loop through some results and add the $blogRSS variable (which is a RSS feed link) to this array. There are only four (4) results but it only gets the last one.

What do I need to do to this code to make it add each feed link into the array?
scrobins is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-25-2007, 11:54 AM Re: Easy array - surely?
Novice Talker

Posts: 6
Name: !!cuisinart
Trades: 0
It should be like below

PHP Code:
for ( $n 0$n 4$n++) {

    
$blogRSS=mysql_result($result,$n,"blogRSS");
    
        
$urls[]=array($blogRSS);

Now $urls array will get 4 results in elements $url[0],$url[1].. etc
__________________

Please login or register to view this content. Registration is FREE
!!cuisinart is offline
Reply With Quote
View Public Profile Visit !!cuisinart's homepage!
 
Old 08-25-2007, 01:51 PM Re: Easy array - surely?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
The main problem you have is that the results keep overwriting the previous one at each interval.

Code:
$urls = Array();
 
for ($n = 0; $n < 4; $n++) {
 
$blogRSS = mysql_result($result, $n, "blogRSS");
 
$urls[] = $blogRSS;
 
}
The above sets up your $urls var as an array.


Code:
$urls = Array();
 
for ($n = 0; $n < 4; $n++) {
 
$blogRSS = mysql_result($result, $n, "blogRSS");
 
$urls[] = $blogRSS;
 
}
This will start a loop of four intervals (iterations)


Code:
$urls = Array();
 
for ($n = 0; $n < 4; $n++) {
 
$blogRSS = mysql_result($result, $n, "blogRSS");
 
$urls[] = $blogRSS;
 
}
This will caputure the results from row N from column blogRSS and assign the value to var $blogRSS. The array $urls will add a new element with that value.

So, the final code is...

PHP Code:
$urls = Array();
for (
$n 0$n 4$n++) {
 
  
$blogRSS mysql_result($result$n"blogRSS");
 
  
$urls[] = $blogRSS;
 

__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Easy array - surely?
 

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.13269 seconds with 12 queries