Hi there!

I think it's a pretty easy one, but I'm quite new to PHP...

I managed to create a database with a table that I use to store personal
data: My address book

The fields are name, address, email, and so forth.

Now I have a loop in a page that cycle through all my entries and displays
them like this (imagine a beautiful HTML formatting to top it!):

John Smith
Phone (home): xxxxxxx
Phone (mobile): xxxxxxx
Phone (office): xxxxxxx
address: xxxxxxx
email: xxxxxxx

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

Martin Duval
Phone (home): xxxxxxx
Phone (mobile): xxxxxxx
Phone (office): xxxxxxx
address: xxxxxxx
email: xxxxxxx

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

Alan Smithee
Phone (home): xxxxxxx
Phone (mobile): xxxxxxx
Phone (office): xxxxxxx
address: xxxxxxx
email: xxxxxxx

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

etc.

Here is the code I use (I'm french so there are some french comments and
caracters)

=========================== START (Sample 1) ==============================

mysql_connect($host,$user,$password) or die("Impossible de se connecter à la
base de données ".$database);

$result = mysql_db_query($database,"select * from addressbook");

while ($row = mysql_fetch_object($result))
{
 if($row->prenom != "")
 {
  echo "<span class=\"NomPrenom\">".$row->prenom."</span>";
 }

 if($row->nom != "")
 {
  echo "<span class=\"NomPrenom\">&nbsp;".$row->nom."</span>";
 }

 if($row->teldomicile != "")
 {
  echo "<br>\n";
  echo "<img src=\"/interface/icons/domicile_phone.gif\" align=\"absbottom\"
alt=\"Téléphone domicile\">&nbsp;\n";
  echo $row->teldomicile;
 }

 if($row->telmobile != "")
 {
  echo "<br>\n";
  echo "<img src=\"/interface/icons/mobile.gif\" align=\"absbottom\"
alt=\"Téléphone mobile\">&nbsp;\n";
  echo $row->telmobile;
 }

 if($row->telbureau != "")
 {
  echo "<br>\n";
  echo "<img src=\"/interface/icons/bureau.gif\" align=\"absbottom\"
alt=\"Téléphone bureau\">&nbsp;\n";
  echo $row->telbureau;
 }

 if($row->email != "")
 {
  echo "<br>\n";
  echo "<img src=\"/interface/icons/email.gif\" align=\"absbottom\"
alt=\"Adresse e-mail\">&nbsp;\n";
  echo "<a href=\"mailto:".$row->email."\">".$row->email."</a>";
 }

 if(($row->rue != "") || ($row->codepostal != "") || ($row->ville != "") ||
($row->pays != ""))
 {
  echo "<br>\n";
  echo "<img src=\"/interface/icons/adresse.gif\" align=\"absbottom\"
alt=\"Adresse\">&nbsp;\n";
 }

 if($row->rue != "")
 {
  echo $row->rue;
  echo "&nbsp;-&nbsp;";
 }

 if($row->codepostal != "")
 {
  echo $row->codepostal;
  echo "&nbsp;";
 }

 if($row->codepostal != "")
 {
  echo $row->ville;
  echo ",&nbsp;\n";
 }

 if($row->pays != "")
 {
  echo $row->pays;
 }

 echo "<br><br><br><hr><br><br><br>\n";
}
mysql_free_result($result);
mysql_close();
// FIN Affichage et formatage de la table Address Book

?>

============================ END (Sample 1) ===============================

What I want to do is have the options to modify and delete an entry, that
would look like this:

John Smith
Phone (home): xxxxxxx
Phone (mobile): xxxxxxx
Phone (office): xxxxxxx
address: xxxxxxx
email: xxxxxxx

>> Modify | Delete
-------------

Martin Duval
Phone (home): xxxxxxx
Phone (mobile): xxxxxxx
Phone (office): xxxxxxx
address: xxxxxxx
email: xxxxxxx

>> Modify | Delete
-------------

Alan Smithee
Phone (home): xxxxxxx
Phone (mobile): xxxxxxx
Phone (office): xxxxxxx
address: xxxxxxx
email: xxxxxxx

>> Modify | Delete
-------------

I managed to have the option to add a new entry to the list with the follow
code triggered via a form:

=========================== START (Sample 2) ==============================

<?
$host = "localhost";
$user = "";
$password = "";
$database = "mabase";

mysql_connect($host,$user,$password);

echo $nom."<br>";
echo $prenom."<br>";
echo $teldomicile."<br>";
echo $telmobile."<br>";
echo $telbureau."<br>";
echo $email."<br>";
echo $rue."<br>";
echo $codepostal."<br>";
echo $ville."<br>";
echo $pays."<br>";

//$nom = "Dupont";
//$prenom = "Jean";

$ok = mysql_db_query($database, "insert into addressbook
(nom,prenom,teldomicile,telmobile,telbureau,email,rue,codepostal,ville,pays)
values
('$nom','$prenom','$teldomicile','$telmobile','$telbureau','$email','$rue','
$codepostal','$ville','$pays')");

?>

============================ END (Sample 2) ===============================

But I would like to be able to have an alphbetical view (A>Z or Z>A) whereas
here a new entry is simply appended at the end of the table and displayed in
that order...


Summary:

- How do I add the Modify/Delete buttons for each entry?
- How can I display the results in an alphabetical order?


If you read to this point, thank you already!

any help, resource, tutorial, example is greatly appreciated!


Sébastien






-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to