It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming PHP and MySQL Forum

While Loop 5x

Moderator: Malcolm

While Loop 5x

Postby cutibiz on Wed Sep 24, 2008 2:54 am

Hello

I need some PHP help here. I have got a list of name generated out from the database.

It actually a OSC site.

Code: Select all
$page_query = [i]the normal query code[/i]               
   
echo '<ul>';

    while ($page = tep_db_fetch_array($page_query)) {   
         echo '<li>' . $page['pages_title'] . '</li>';
   }

echo '</ul>';


This codes works however, I want to show only the 1st 5 data row in the database. How do I do that?

Please help!!! thanks
cutibiz
 
Posts: 13
Joined: Fri Aug 22, 2008 6:47 pm

Postby webmaster on Wed Sep 24, 2008 7:30 am

When writing the query, just add LIMIT 5 at the end, like this:
Code: Select all
SELECT * FROM tablename LIMIT 5
Make sure to check out our TNX Review and Link Vault Review
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden

Postby cutibiz on Sat Sep 27, 2008 7:03 pm

hi

thanks for responding however when I insert the "LIMIT 5" , no data is display.
cutibiz
 
Posts: 13
Joined: Fri Aug 22, 2008 6:47 pm

Postby webmaster on Sun Sep 28, 2008 6:07 am

Can you write the whole query
Make sure to check out our TNX Review and Link Vault Review
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden

Postby cutibiz on Wed Oct 01, 2008 7:38 pm

sry for the late reply.

here you go!


[php] $page_query = tep_db_query("select
p.pages_id,
p.sort_order,
p.status,
s.pages_title,
s.pages_html_text,
s.intorext,
s.externallink,
s.link_target
from
" . TABLE_PAGES . " p LEFT JOIN " .TABLE_PAGES_DESCRIPTION . " s on p.pages_id = s.pages_id
where
p.status = 1
and
p.page_type != 1
and
s.language_id = '" . (int)$languages_id . "'
order by
p.sort_order, s.pages_title");[/php]
Last edited by cutibiz on Sat Oct 04, 2008 3:17 pm, edited 1 time in total.
cutibiz
 
Posts: 13
Joined: Fri Aug 22, 2008 6:47 pm

Postby webmaster on Thu Oct 02, 2008 6:12 am

If that query works, this should also work:

[php]$page_query = tep_db_query("select
p.pages_id,
p.sort_order,
p.status,
s.pages_title,
s.pages_html_text,
s.intorext,
s.externallink,
s.link_target
from
" . TABLE_PAGES . " p LEFT JOIN " .TABLE_PAGES_DESCRIPTION . " s on p.pages_id = s.pages_id
where
p.status = 1
and
p.page_type != 1
and
s.language_id = '" . (int)$languages_id . "'
order by
p.sort_order, s.pages_title") LIMIT 5;[/php]
Make sure to check out our TNX Review and Link Vault Review
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden

Postby Johnathan on Thu Oct 02, 2008 7:23 am

WM, how if your font different from everyone elses?
Johnathan
1000+ Club
 
Posts: 1207
Joined: Thu May 31, 2007 3:28 pm
Location: Belfast, Northen Ireland

Postby cutibiz on Thu Oct 02, 2008 8:33 am

there an error

"Parse error: syntax error, unexpected T_STRING in C:\Program Files\xampplite\htdocs\osc\includes\boxes\artist_bio.php on line 34"
cutibiz
 
Posts: 13
Joined: Fri Aug 22, 2008 6:47 pm

Postby webmaster on Fri Oct 03, 2008 6:10 am

Do you get that error before adding "LIMIT 5" too?
Make sure to check out our TNX Review and Link Vault Review
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden

Postby cutibiz on Fri Oct 03, 2008 8:37 am

no. it working fine, without error before I add "LIMIT 5"
cutibiz
 
Posts: 13
Joined: Fri Aug 22, 2008 6:47 pm

Next

Who is online

Users browsing this forum: No registered users and 1 guest