这是我的PHP代码: h2>
$host = "localhost"; //Your database host server
$db = "root"; //Your database name
$user = "root"; //Your database user
$pass = "1234"; //Your password
$connection = mysql_connect($host, $user, $pass);
//Check to see if we can connect to the server
if(!$connection)
{
die("Database server connection failed.");
}
else
{
//Attempt to select the database
$dbconnect = mysql_select_db($db, $connection);
//Check to see if we could select the database
if(!$dbconnect)
{
die("Unable to connect to the specified database!");
}
else
{
$query = "SELECT * FROM playlist_builder";
$resultset = mysql_query($query, $connection);
$records = array();
$response = array(); //extra
//Loop through all our records and add them to our array
while($r = mysql_fetch_assoc($resultset))
{
$records[] = $r;
}
//Output the data as JSON
$json = json_encode($records, JSON_PRETTY_PRINT);
$json = str_replace('\\', '', $json);
$json = preg_replace('/"([a-zA-Z]+[a-zA-Z0-9_]*)":/','$1:',$json);
// $json = str_replace('"', "'", $json);
//NOTE: FOLDERS 'url' and 'file' SHOULD BE WRITABLE WITH PERMISSIONS - 777
//IN CASE 'url' FOLDER PLACED IN SERVER'S ROOT
//IF YOU'RE USING SOME FTP BROWSER CHANGE PERMISSIONS FOR 'url'
//FOLDER AND APPLY IT TO ALL ENCLOSED ITEMS
$data = 'var data = [{ tags: ';
$end = '}];';
$script = "// Call Slider function
$(window).load(function () {
$('#slideshow-slider').jSonSlider({
'loadallslides': false,
'auto': [true, '14000'],
'nextprev': false,
'circular': true,
'pagi': false,
'data': data
});
});";
file_put_contents('records.js', $data);
file_put_contents('records.js', $json, FILE_APPEND);
file_put_contents('records.js', $end, FILE_APPEND);
file_put_contents('records.js', $script, FILE_APPEND);
}
}
以下是我的js文件输出: h2>
var data = [{ tags: [
{
id: "1",
volume: "volume1",
name: "a",
content: "",
css_animate: "fadeIn"
},
{
id: "2",
volume: "volume1",
name: "a",
content: "",
css_animate: "fadeIn"
},
{
id: "3",
volume: "volume1",
name: "a",
content: "",
css_animate: "fadeIn"
}
]}];
// Call Slider function
$(window).load(function () {
$('#slideshow-slider').jSonSlider({
'loadallslides': false,
'auto': [true, '14000'],
'nextprev': false,
'circular': true,
'pagi': false,
'data': data
});
});任何帮助真的很感激! :)