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
Interesting Loop Problem
Old 10-22-2010, 08:33 AM Interesting Loop Problem
Average Talker

Posts: 26
Trades: 0
I have this function, but it doesnt work. Basically the list outputs a list of news features, and puts a line under neath each article to seperate them. However once the last article has been reached, I don't want the break to be shown.

this is my code, any help would be appreciated as i am really struggling on this. Just need to determine the last item in the array, and stop the <hr split> from being output.
This code isnt working, but i have put it here to show what my thinking process is at the moments.

PHP Code:
function newsFeature(){ 
    
$event "SELECT imgname, title, content, pkID from news ORDER BY date, time DESC LIMIT 5"
    
$event_page query($event); 
    
$count numRows($event_page); 
     
    while (
$row mysql_fetch_assoc($event_page)) 
    { 
        
$rowcount $count
        
$para substr($row['content'] , 0,100); 
        
$result .= '<article>'
        
$result .= '<a href="news-article.php?pkID=' $row['pkID'] . '"><img src="uploads/thumbs/' $row['imgname'] . '" alt="" width=116 height=83/ ></a>'
        
$result .= '<h2><a href="news-article.php?pkID=' $row['pkID'] . '">' $row['title'] . '</a></h2>'
        
$result .= '<p>' $para '...</p>'
        
$result .= '<p><a class="read-more" href="news-article.php?pkID=' $row['pkID'] . '">Read more<span></span></a></p>'
        
$result .= '</article>'
        if(
$row != end($row[])){ 
            
$result .= '<hr class="split">'
        } 
    } 
        return 
$result

applebiz89 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-22-2010, 09:08 AM Re: Interesting Loop Problem
Skilled Talker

Posts: 52
Trades: 0
So this is your code

Quote:
PHP Code:
function newsFeature(){ 
    
$event "SELECT imgname, title, content, pkID from news ORDER BY date, time DESC LIMIT 5"
    
$event_page query($event); 
    
$count numRows($event_page); 
     
    while (
$row mysql_fetch_assoc($event_page)) 
    { 
        
$rowcount $count
        
$para substr($row['content'] , 0,100); 
        
$result .= '<article>'
        
$result .= '<a href="news-article.php?pkID=' $row['pkID'] . '"><img src="uploads/thumbs/' $row['imgname'] . '" alt="" width=116 height=83/ ></a>'
        
$result .= '<h2><a href="news-article.php?pkID=' $row['pkID'] . '">' $row['title'] . '</a></h2>'
        
$result .= '<p>' $para '...</p>'
        
$result .= '<p><a class="read-more" href="news-article.php?pkID=' $row['pkID'] . '">Read more<span></span></a></p>'
        
$result .= '</article>'
        if(
$row != end($row[])){ 
            
$result .= '<hr class="split">'
        } 
    } 
        return 
$result

This one should work:

PHP Code:
function newsFeature(){ 
    
$event "SELECT imgname, title, content, pkID from news ORDER BY  date, time DESC LIMIT 5"
    
$event_page query($event); 
    
$count numRows($event_page); 
     
$numberc 0;
    while (
$row mysql_fetch_assoc($event_page)) 
    { 
        
$rowcount $count
$numberc++;
        
$para substr($row['content'] , 0,100); 
        
$result .= '<article>'
        
$result .= '<a href="news-article.php?pkID=' $row['pkID'] .  '"><img src="uploads/thumbs/' $row['imgname'] . '" alt=""  width=116 height=83/ ></a>'
        
$result .= '<h2><a href="news-article.php?pkID=' .  $row['pkID'] . '">' $row['title'] . '</a></h2>'
        
$result .= '<p>' $para '...</p>'
        
$result .= '<p><a class="read-more"  href="news-article.php?pkID=' $row['pkID'] . '">Read  more<span></span></a></p>'
        
$result .= '</article>'
        if(
$numberc != 5){ 
            
$result .= '<hr class="split">'
        } 
    } 
        return 
$result

It counts the articles and when he arrives to the last in this case news number 5 because you limited it in the query.. it will not show hr...

Hope It's usefull.

Regards.
webmastertalker is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Interesting Loop 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.24082 seconds with 12 queries