Forum Moderators: coopster

Message Too Old, No Replies

Php/mysql novice needs help.

Adjust coding for list creation.

         

digisales

4:23 pm on Apr 21, 2009 (gmt 0)

10+ Year Member



I am a novice with php and mysql, and need some help. The following script creates a list of email addresses on a mailing list housed in mysql.

$db_name = "dbname";
$table_name = "mlist";
$connection = @mysql_connect("localhost", "user", "pswd")
or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$sql = "SELECT id, email_addr FROM $table_name ORDER BY id";
$result = @mysql_query($sql, $connection) or die (mysql_error());
$contact_list = "<ul>";
while ($row = mysql_fetch_array ($result)) {
$id = $row['id'];
$email_addr = $row['email_addr'];
$contact_list .= "<li>$email_addr";
}
$contact_list .= "</ul>";
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<? echo "$contact_list"; ?><br>

It currently only lists the address, but the table also contains fields with first and last name (f_name and l_name). I need to adjust the above coding so that is will display and list all the info as follows:

f_name l_name email_addr

Frank_Rizzo

4:28 pm on Apr 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$db_name = "dbname";
$table_name = "mlist";
$connection = @mysql_connect("localhost", "user", "pswd")
or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());

------------

$sql = "SELECT id, f_name, l_name, email_addr FROM $table_name ORDER BY id";
$result = @mysql_query($sql, $connection) or die (mysql_error());
$contact_list = "<ul>";
while ($row = mysql_fetch_array ($result)) {
$id = $row['id'];
$f_name = $row['f_name'];
$l_name = $row['l_name'];
$email_addr = $row['email_addr'];
$contact_list .= "<li>$f_name $l_name $email_addr";

------------
}
$contact_list .= "</ul>";
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<? echo "$contact_list"; ?><br>

digisales

4:43 pm on Apr 21, 2009 (gmt 0)

10+ Year Member



Like a charm! Many thanks for the quick response.