RE: [PHP] Sense last record

2007-04-09 Thread Peter Lauri
Assuming you know it will be three records:

$i = 1;
while(...) {
if($i==3) {
//Do the stuff for the last one
} else {
//Do the rest of the stuff here
}
$i++;
}

Assuming you don't know:

$count = mysql_num_rows($Result); //or equivalent in AdoDB
$i=1;
while(...) {
if($i==$count) {
//Do the stuff for the last one
} else {
//Do the rest of the stuff here
}
$i++;
}

Best regards,
Peter Lauri

www.dwsasia.com - company web site
www.lauri.se - personal web site
www.carbonfree.org.uk - become Carbon Free


 -Original Message-
 From: Mário Gamito [mailto:[EMAIL PROTECTED]
 Sent: Monday, April 09, 2007 3:32 PM
 To: php-general@lists.php.net
 Subject: [PHP] Sense last record
 
 Hi,
 
 I'm doing this site that has three news in the homepage.
 You can see the static version here:
 http://www.telbit.pt
 As you can see, the two first news have blocoTexto class and the
 third, blocoTextoLast
 
 Now, i'm developing a dinamyc structure where the news are stored in a
 MySQL database and retrieved from there.
 
 My problem is with the third news and it's different class.
 I'm using AdoDB recordSet to get the news from the database.
 You can see it here:
 http://www.telbit.pt/2/
 
 How can i sense that i've reached the last row and apply the
 blocoTextoLast class to it ?
 
 My code follows my signature.
 
 Any help would be appreciated.
 
 Warm Regards
 --
 :wq! Mário Gamito
 --
 div id=blocoNews
   ?php
include('config.php');
include('adodb/adodb.inc.php');
 
// connect to MySQL
$conn-debug=1;
$conn = ADONewConnection('mysql');
 
 $conn-PConnect($host,$user,$password,$database);
 
// get news data
$recordSet = $conn-Execute(SELECT date, now, title, lead, body
 FROMnews ORDER BY date DESC LIMIT 3);
 
   if (!$recordSet)
print $conn-ErrorMsg();
   else
while (!$recordSet-EOF) {
 print 'div class=blocoTexto' . ' h3' . $recordSet-fields[2] .
 '/h3' . 'p class=data' . $recordSet-fields[0] . '/p' .
 'p' . $recordSet-fields[3] . '/p' . '/div';
 
   $recordSet-MoveNext();
 }
   echo br class=\clear\;
 
   $recordSet-Close();
   $conn-Close();
 ?  !-- end #secContent --
 /div
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Sense last record

2007-04-09 Thread Satyam
I would use some JavaScript on the client side to go through the table and 
change the classes once the whole page is loaded.


Otherwise, for a pure PHP solution, I might either load the whole table on 
an array, which is wasteful in memory, or defer the actual output of each 
record until the next record is read so, if no further records exist, I 
would change the class name of the row still in a variable and output the 
row right after the loop ends before the end of the table.


Satyam

- Original Message - 
From: Mário Gamito [EMAIL PROTECTED]

To: php-general@lists.php.net
Sent: Monday, April 09, 2007 3:31 PM
Subject: [PHP] Sense last record



Hi,

I'm doing this site that has three news in the homepage.
You can see the static version here:
http://www.telbit.pt
As you can see, the two first news have blocoTexto class and the third, 
blocoTextoLast


Now, i'm developing a dinamyc structure where the news are stored in a 
MySQL database and retrieved from there.


My problem is with the third news and it's different class.
I'm using AdoDB recordSet to get the news from the database.
You can see it here:
http://www.telbit.pt/2/

How can i sense that i've reached the last row and apply the 
blocoTextoLast class to it ?


My code follows my signature.

Any help would be appreciated.

Warm Regards
--
:wq! Mário Gamito
--
div id=blocoNews
 ?php
  include('config.php');
  include('adodb/adodb.inc.php');

  // connect to MySQL
  $conn-debug=1;
  $conn = ADONewConnection('mysql');

$conn-PConnect($host,$user,$password,$database);

  // get news data
  $recordSet = $conn-Execute(SELECT date, now, title, lead, body FROM 
news ORDER BY date DESC LIMIT 3);


 if (!$recordSet)
  print $conn-ErrorMsg();
 else
  while (!$recordSet-EOF) {
   print 'div class=blocoTexto' . ' h3' . $recordSet-fields[2] . 
'/h3' . 'p class=data' . $recordSet-fields[0] . '/p' .

'p' . $recordSet-fields[3] . '/p' . '/div';

 $recordSet-MoveNext();
}
 echo br class=\clear\;
 $recordSet-Close();
 $conn-Close();
?  !-- end #secContent -- /div

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 269.0.0/752 - Release Date: 08/04/2007 
20:34





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Sense last record

2007-04-09 Thread tg-php
Sorry, I only saw the one response to this question so not sure if what I'm 
going to propose was already mentioned and wouldn't work.

Two things come to mind..  first, it looks like blocoTextoLast just has 
different margin settings, I assume because it's located on the right side of 
the page content.  Would you care if, for example, you only had two news items 
and the second one (being the last) had margins set to what the first or second 
news items would have and not the last item?  That is, does news item #1 or 
#2 need the special formatting that #3 does?

Second, why not just get a count of the number of news items returned by the 
SQL query.  If it's only one, then apply blockoTextoLast to item #1.  If it's 
two, apply it to #2.  If it's three or more, apply it to the third new item?

I guess one more thing could be done.   Create three div containers, like 
you're doing now.  Use blockoTexto for the first two, and blockoTextoLast 
to the third.  It doesn't really matter if they have any content, the class 
stays the same.  Then you don't have to worry if you have 1, 2 or 3 news items.

-TG



= = = Original message = = =
- Original Message - 
From: M~rio Gamito [EMAIL PROTECTED]
To: php-general@lists.php.net
Sent: Monday, April 09, 2007 3:31 PM
Subject: [PHP] Sense last record


 Hi,

 I'm doing this site that has three news in the homepage.
 You can see the static version here:
 http://www.telbit.pt
 As you can see, the two first news have blocoTexto class and the third, 
 blocoTextoLast

 Now, i'm developing a dinamyc structure where the news are stored in a 
 MySQL database and retrieved from there.

 My problem is with the third news and it's different class.
 I'm using AdoDB recordSet to get the news from the database.
 You can see it here:
 http://www.telbit.pt/2/

 How can i sense that i've reached the last row and apply the 
 blocoTextoLast class to it ?

 My code follows my signature.

 Any help would be appreciated.

 Warm Regards
 -- 
 :wq! M~rio Gamito
 --
 div id=blocoNews
  ?php
   include('config.php');
   include('adodb/adodb.inc.php');

   // connect to MySQL
   $conn-debug=1;
   $conn = ADONewConnection('mysql');

 $conn-PConnect($host,$user,$password,$database);

   // get news data
   $recordSet = $conn-Execute(SELECT date, now, title, lead, body FROM 
 news ORDER BY date DESC LIMIT 3);

  if (!$recordSet)
   print $conn-ErrorMsg();
  else
   while (!$recordSet-EOF) 
print 'div class=blocoTexto' . ' h3' . $recordSet-fields[2] . 
 '/h3' . 'p class=data' . $recordSet-fields[0] . '/p' .
 'p' . $recordSet-fields[3] . '/p' . '/div';

  $recordSet-MoveNext();
 
  echo br class=\clear\;
  $recordSet-Close();
  $conn-Close();
 ?  !-- end #secContent -- /div

 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



 -- 
 No virus found in this incoming message.
 Checked by AVG Free Edition.
 Version: 7.5.446 / Virus Database: 269.0.0/752 - Release Date: 08/04/2007 
 20:34

 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


___
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Sense last record

2007-04-09 Thread Mário Gamito

Hi,

Thank you all for your answers.

I solved the problem with:

div id=blocoNews
 ?php
  include('config.php');
  include('adodb/adodb.inc.php');

  $debug = 1;

  // connect to MySQL
  $conn-debug=1;
  $conn = ADONewConnection('mysql');
  $conn-PConnect($host,$user,$password,$database);

  // insert subscription values
  $recordSet = $conn-Execute(SELECT id_news, date, now, title, lead, 
body FROM news ORDER BY now DESC LIMIT 3);


  $counter = 0;

  if (!$recordSet)
   print $conn-ErrorMsg();
  else
   while (!$recordSet-EOF) {
$counter++;
 if ($counter == 3)
  $div = 'div class=blocoTextoLast';
 else
  $div = 'div class=blocoTexto';
print($div);
print 'h3' . $recordSet-fields[3] . '/h3' . 'p class=data' 
 . $recordSet-fields[1] . '/p' . 'p' . $recordSet-fields[4] . 'a 
href=news.php?news='. $recordSet-fields[0] . '[+]/a' . '/p' . 
'/div';

   $recordSet-MoveNext();
   }

 echo br class=\clear\; 
 $recordSet-Close();
$conn-Close();
?
!-- end #secContent --  
/div

Warm Regards
--
:wq! Mário Gamito

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php