Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot display events from mysql #759

Open
aznith opened this issue Oct 16, 2018 · 2 comments
Open

Cannot display events from mysql #759

aznith opened this issue Oct 16, 2018 · 2 comments

Comments

@aznith
Copy link

aznith commented Oct 16, 2018

Hi. I just followed the exact files from this tutorial
https://phpzag.com/demo//create-event-calendar-with-jquery-php-and-mysql/

The only thing I changed is Im using my own sql table. So I changed the query in the codes too. But I could not display or even fetch my events from the database. Can someone help me?

`<?php
session_start();
//require_once 'TEST_conn.php';
include_once("TEST_conn.php");

//$mysqli = new mysqli("localhost","intern", "intern*3922539#", "Office HqRM");
//$user = "SELECT Email, Username FROM User WHERE Username like '".$_SESSION['Username']."'";
//$strUser = mysql_query($user, $link_ID);
//$ObjUser = mysql_fetch_object($strUser);

//$SelLoc = $_POST['loc'];

$sqlEvents = "SELECT LocationNo, IP, StartDate, EndDate FROM Schedule";
$resultset = mysql_query($conn, $sqlEvents) ;
$calendar = array();
while( $rows = mysqli_fetch_assoc($resultset) ) {
// convert date to milliseconds
$start = strtotime($rows['StartDate']) * 1000;
$end = strtotime($rows['EndDate']) * 1000;
$calendar[] = array(
'LocationNo' =>$rows['LocationNo'],
'IP' => $rows['IP'],
'url' => "#",
"class" => 'event-important',
'start' => "$start",
'end' => "$end"
);
}
$calendarData = array(
"success" => 1,
"result"=>$calendar);
echo json_encode($calendarData);
exit;

`

@ayushgarg98
Copy link

ayushgarg98 commented Nov 10, 2019

Hello,

I used the same tutorial and I am able to fetch the events from the database.
You may check the names that are associated with your database connection, which includes the name of the database, names of the tables and names of the attributes, etc.
You can check the above PHP script you have written in your question for the fact that if it is producing the JSON file or not and hence you can get to the issue and solve it.

You can take help from the following code:

`<?php
$db = ''; //!!!!----name of the database----!!!!
$username = '';
$password = '';
$host = 'localhost';
$mysqli = new mysqli($host, $username, $password, $db);
$mysqli->query("SET NAMES 'utf8'");

if ($mysqli->connect_errno) 
{
	echo "Error de conexion: (" . $mysqli->connect_errno .") " . $mysqli->connect_error;
}

$sqlEvents = "SELECT * FROM <tableName> LIMIT 20";

$sql = $mysqli->query($sqlEvents);
while($row = $sql->fetch_array(MYSQLI_ASSOC)){
    $start = strtotime($row['start_date']) * 1000;
    $end = strtotime($row['end_date']) * 1000; 
    $description = $row['description'];
    $name = $row['title'];
    $title = $name.' Starts: '.$row['start_date'].', Ends: '.$row['end_date'].'Brief Discription: '.$description;
    $calendar[] = Array(
        'id' =>$row['id'],
        'title' => "$title",
        'url' => "#",
        "class" => 'event-important',     //!!!!----this can also be taken from the databse----!!!!
        'start' => "$start",
        'end' => "$end"
    );
}
$calendarData = Array(
	"success" => 1,	
    "result"=>$calendar);
echo json_encode($calendarData);
exit;

?>`

@cablegunmaster
Copy link

cablegunmaster commented Nov 11, 2019

Your issue needs more code which you have written yourself and also the issue you are experiencing meaning , what error code do you got ? Do you got any error in the developer console? (F12) when you have the page open?

Either 1 the table is empty which you are calling or the connection is not properly made or you got a error when you changed the tutorial code. Either or all I cannot see without seeing the code. or adding more screenshots.

  1. Table is empty (check with phpmyadmin ) or which ever SQL editor you are using to view the table.
  2. connection is poorly made, every time I try to make a connection to my DB server it will fail because my Password is incorrect or my host is set incorrectly (this is sometimes trial and error)

Try below script and fill in your own variables to see if the connection can be made properly to the DB; if you keep getting connection failed its due to some variables set which are incorrect. If you do not know the servername ask the webhost, if its on your own pc localhost should do the trick.

<?php
$servername   = "localhost";
$database = "database";
$username = "user";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
   die("Connection failed: " . $conn->connect_error);
}
  echo "Connected successfully";
?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants