Author Topic: Not finding first record in MySQL  (Read 814 times)

0 Members and 1 Guest are viewing this topic.

NickM

  • Guest
Not finding first record in MySQL
on: Wed, 08. January 2003 - 07:20:52
The code below is simple enough but it refuses to list the first record in the table. All other records appear.
Any ideas why?


include_once ('../../vlibTemplate.php');
$tmpl=new vlibTemplate('templates/list3.html');

$tmpl->newLoop('pg_desc'); //define loop

$conn = db_connect();
$pages_sql = "select * from pages order by code";
$pages_result = mysql_query($pages_sql, $conn);

while ($pages = mysql_fetch_array($pages_result)) {

$tmpl->setDbLoop('pg_desc',$pages_result, 'MYSQL');
} //end the while

---------------------
and the Template:
<html>

<tmpl_loop name="pg_desc">

<p><tmpl_var name ='description'></p>
         
</tmpl_loop>

</html>

RNilsson

  • Guest
Not finding first record in MySQL
Reply #1 on: Wed, 08. January 2003 - 15:23:25
I'm not 100% sure how the dbLoop works, but try 'mysql_fetch_object' instead of 'mysql_fetch_array' as arrays start with element '0' while objects start with element '1' if i'm not completely left in the dark.

If it helps, great...if not...i'll just crawl back a bit =)

releasedj

  • Guest
Not finding first record in MySQL
Reply #2 on: Wed, 08. January 2003 - 18:59:40
Hi,

With setDbLoop(), you don't have to do a loop yourself, it's handled within vlibTemplate, so you would just do the PHP like this:

Code: [Select]

include_once '../../vlibTemplate.php';

$tmpl=new vlibTemplate'templates/list3.html';



$tmpl-newLoop'pg_desc'; //define loop



$conn = db_connect;

$pages_sql = select * from pages order by code;

$pages_result = mysql_query$pages_sql, $conn;



$tmpl-setDbLoop'pg_desc',$pages_result, 'MYSQL';





This should now work.

Kind regards,

Kelvin

NickM

  • Guest
Not finding first record in MySQL
Reply #3 on: Thu, 16. January 2003 - 14:16:18
Yes it does work. Thanks.