我在结果中收到空值:title,但在DB中,location_end中有一个值
package javaapplication2;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Collections;
import java.util.Scanner;
public class Stock {
private LinkedList<Book> books;
public Stock(){
books=new LinkedList<>();
}
public void Load(File file) throws FileNotFoundException{
Scanner scan =new Scanner(file);
String s=scan.nextLine().trim();
scan.useDelimiter(":");
String author, title,edition, publisher;
int price, quantity;
while(scan.hasNext()){
author=scan.next();
title=scan.next();
edition=scan.next();
publisher=scan.next();
price=scan.nextInt();
quantity=scan.nextInt();
books.add(new Book(author,title,edition,publisher,price,quantity),books.getSize()+1);
}
}
public void purchase(Book book){
Node<Book> current=books.getfirst();
for(int i=0; i<books.getSize(); i++){
if(current.element.getTitle().equalsIgnoreCase(book.getTitle()))
current.element.setQuantity(current.element.getQuantity()+book.getQuantity());
else
books.add(new Book(book), books.getSize()+1);
current=current.next;
}
}
public void sale(Book book){
Node<Book> current= books.getfirst();
for(int i=0; i<books.getSize(); i++){
if(current.element.getTitle().equalsIgnoreCase(book.getTitle())){
if(current.element.getQuantity()>1)
current.element.setQuantity(current.element.getQuantity()-1);
else
System.out.print("\n There is NO Copies of this book"+book.getTitle()+"in the stock");
}
else System.out.print("\n the book is NOT in the stock");
current=current.next;
}
}
public boolean search(String s){
Node<Book> current = books.getfirst();
for(int i=0; i<books.getSize(); i++){
if(current.element.getTitle().equalsIgnoreCase(s))
return true;
else if(current.element.getAuthor().equalsIgnoreCase(s))
return true;
else {
for(int y=0; y<current.element.getTitle().length()-s.length()+1; y++){
if(s.equalsIgnoreCase(current.element.getTitle().substring(y, y+s.length())))
return true;
}
}
}
return false;
}
public void Display(){
Node<Book> current =books.getfirst();
for(int i=0; i<books.getSize();i++){
System.out.print("\n "+ current.element.toString());
current=current.next;
}
}
public void sortedReport(){
//Collections.sort(books);
Node<Book> current= books.getfirst();
for(int i=0; i<books.getSize(); i++){
System.out.print("\n "+current.element.toString());
current= current.next;
}
}
}
结果:标题应该有值,但我收到空
<?php
$bdd = new PDO('mysql:host;dbname', 'user', 'pass');
$result = $bdd->prepare("SELECT * FROM schedule");
$result->execute();
$event_array = array();
$result->setFetchMode(PDO::FETCH_ASSOC);
while ($record = $result->fetch()) {
$event_array[] = array(
'id' => $record['id'],
'title' => $record['location_end'],
'start' => $record['start_time'],
'end' => $record['end_time'],
);
}
echo json_encode($event_array);
events: {
url: 'http://localhost/FleetManagement/getEvents.php',
type: 'POST',
dataType: 'json',
success: function(){
alert('Get Events Successfull!!');
$('#calendar').fullCalendar('updateEvent',event);
},
error: function(error) {
alert(error);
}
}
答案 0 :(得分:0)
在结果标题中,我收到空值
您正在尝试使用location_end
字段,但该列不在您的SQL选择中;
SELECT id, start_time, end_time, status, approval_status FROM schedule
您需要将该列添加到SQL中;
SELECT id, location_end, start_time, end_time, status, approval_status FROM schedule
答案 1 :(得分:0)
尝试在json_encode之前打印$event_array
。
在我看来,'location_end'包含一些非utf8编码字符。