0% found this document useful (0 votes)
36 views2 pages

Acceder Nombre de Campos PHP SQL

This document discusses how to select records from a database table and display them in an HTML table using PHP ADODB. It provides the SQL syntax to select specific columns from a table where email is not null. It then shows how to execute the SQL, retrieve the results, and output each field into cells of a table while iterating through the recordset.

Uploaded by

mhernandez807712
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views2 pages

Acceder Nombre de Campos PHP SQL

This document discusses how to select records from a database table and display them in an HTML table using PHP ADODB. It provides the SQL syntax to select specific columns from a table where email is not null. It then shows how to execute the SQL, retrieve the results, and output each field into cells of a table while iterating through the recordset.

Uploaded by

mhernandez807712
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

http://www.w3cyberlearnings.

com/PHP_A
DODB_Select_Record
PHP ADODB Select Record
Contents
[show]
PHP ADODB Select Record
Select records and generate table.
Syntax ADODB Select Record
$sql = "SELECT id,first_name,last_name,email FROM {$table} WHERE email IS
NOT NULL";

$result = $conn1->Execute($sql);
while (!$result->EOF) {

echo $result->fields[0];
echo "<br/>";
echo $result->fields[1];
echo "<br/>";
echo $result->fields[2];
echo "<br/>";
echo $result->fields[3];
echo "<br/>";

$result->MoveNext();
}
Example 1
<?php

include 'adodb5/adodb.inc.php';

$host = 'localhost';
$user = 'user2000';
$pass = 'password2000';
$dbname = 'w3cyberlearning';

$conn1 = &ADONewConnection('mysql');
$conn1->PConnect($host, $user, $pass, $dbname);
$table = 'user_infor';
$sql = "SELECT id,first_name,last_name,email FROM {$table} WHERE email IS
NOT NULL";

$result = $conn1->Execute($sql);

if ($result == false) {
print 'error' . $conn1->ErrorMsg() . '<br>';
}

$table_meta = $conn1->MetaColumns($table);
$table_header = array_keys($table_meta);

echo '<table border="1">';
// generate and display header from table field
echo '<tr>';
foreach ($table_header as $colname) {
echo '<th>' . $colname . '</th>';
}
echo '</tr>';


while (!$result->EOF) {
echo '<tr>';
echo '<td>'. $result->fields[0].'</td>';
echo '<td>'. $result->fields[1].'</td>';
echo '<td>'. $result->fields[2].'</td>';
echo '<td>'. $result->fields[3].'</td>';
echo '</tr>';
$result->MoveNext();
}
?>
Output

You might also like