File: readme_db.txt

Recommend this page to a friend!
  Classes of Andrea Bersi  >  Editable select input  >  readme_db.txt  >  Download  
File: readme_db.txt
Role: Documentation
Content type: text/plain
Description: tip for use with a db
Class: Editable select input
Generate form select input with editable text
Author: By
Last change:
Date: 15 years ago
Size: 986 bytes
 

Contents

Class file image Download
If you want to use the values stored into a table of a mysql db, it is very simple. Add, for example, a wrapper (in this example the ez_sql.class You find it in the site phpclasses.org)

include ("include/ez_sql.php");

After, you query your db as


if ( $mails = $db->get_results("SELECT mail FROM mail") )
{
	// Loop through the resulting array on the index $users[n]
	foreach ( $mails as $mail )
	{
		// Access data using column names as associative array keys
		$str.=$mail->mail.";";
        }
}
$select->print_select("mail",$str);
?>  

The select is at this point with the values of db

At the post of form you insert the value in the db if it is not present

if(isset($_POST['mail'])) {
//verifica se la mail inserita era giÓ nel db o no
if (!( $n = $db->get_var("SELECT count(*) FROM mail WHERE mail = '$_POST[mail]'") ))
{
	// Insert into the database
	$db->query("INSERT INTO mail (mail) VALUES ('$_POST[mail]')");
}  
.... other instructions
}

For more information send a message to info at phpclasses dot org.