Location: PHPKode > scripts > PHP Voice > php-voice/samples/news.php
<?php

/**
 * PHP script that read summary news from your website database 
 *
 * @author Ben Yacoub Hatem <hide@address.com>
 * $ version 1.0.0 Fri Nov 05 05:57:17 CET 2004 05:57:17 by hatem

* sample Mysql Table

create table news (
  id int(4) NOT NULL auto_increment,
  summary tinytext NOT NULL,
  PRIMARY KEY  (id)
) TYPE=MyISAM;

* @date		04-12-2002
*/

// Config
$CompanyName = "PHP Voice News";
$host = "localhost"; // MySQL host
$user = "root"; // User login
$pass = ""; // User passwd
$db   = "phpvoice"; // News database

$number_of_news = 5;

$query = "SELECT summary FROM news order by id DESC LIMIT 0,$number_of_news"; // MySQL Query
// End config


    /* Connecting, selecting database */
    $link = @mysql_connect($host, $user, $pass)
        or die("Could not connect");

    @mysql_select_db($db) or die("Could not select database");

    /* Performing SQL query */
    $result = @mysql_query($query) or die("Query failed");
    $num = @mysql_num_rows($result);
    
    if ($num<$number_of_news) {
    	$number_of_news = $num;
    }

	// VoiceXML began here

 
	require_once ("../vxml.class.php");
	
	$app=new gonx_vxml;
	
	$app->start_vxml("", "", "en", "", "", "2.0");
	$app->start_catch("connection.disconnect"); $app->start_exit_c(); $app->end_catch();

	
	$app->load("message",array("","Welcome to $CompanyName","#choix"));
		
		// Creation du menu
		$app->start_menu("choix");
		
			$app->start_prompt();
			
				$app->start_audio("welcome.wav");
				
				$app->write("Please press numbers from 1 to $number_of_news to read latest news. Use * to disconnect.");
				
				$app->end_audio();
				
			$app->end_prompt();
				
			for ($i=1;$i<=$number_of_news;$i++){
				$app->start_choice_c($i,$i,"","#$i" );
			}
			$app->start_choice_c("*","*","","#*" );
			$app->load("nomatch",array("Sorry, your entry isn't valid.","en-US"));
			$app->load("noinput",array("Sorry, I didn't receive any entry.","en-US"));
		
		$app->end_menu();
		
// Read news from MySQL Database
	$i = 1;
    while ($line = @mysql_fetch_array($result, MYSQL_ASSOC)) {
        foreach ($line as $summary) {
		
        	$app->load("message", array($i,utf8_encode(strip_tags($summary)),"#choix","news$i.wav"));

			$i++;
        }
	}
    /* Free resultset */
    mysql_free_result($result);

    /* Closing connection */
    mysql_close($link);

// End MySQL 		

	$app->load("message", array("*","$CompanyName Thank you for your visit, bye bye."));

	$app->end_vxml();
	
	$app->generate();
 
?>
Return current item: PHP Voice