0

hye, i'm having trouble in calling all the rows in one table. hope anyone could assist me solve the error:

<?php
require_once('database.php');
  
        
$result = mysql_query("SELECT * FROM events ");
while($row = mysql_fetch_array($result))
              
?>
wiwi
  • 1
  • 4
  • FYI, [you shouldn't use `mysql_*` functions in new code](http://stackoverflow.com/questions/12859942/). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [red box](http://php.net/manual/en/function.mysql-connect.php)? Learn about [*prepared statements*](https://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide which one is best for you. – John Conde Jun 13 '17 at 01:49
  • This code is incomplete and you also don't tell us what the error is – John Conde Jun 13 '17 at 01:50
  • sorry my mistakes. the error is my calendar doesnt appeared after i code query to call the database – wiwi Jun 13 '17 at 02:12

1 Answers1

0

I am not an expert on mysqli stuff (I use a Connection class I found somewhere which provides functions like selectMultipleRows($query) and so on) but I will try to give a good answer here.

assuming you already have created a connection $this->connID

$mysqli = $this->connID;
$result = $mysqli->query($query);
$data = $result->fetch_all(MYSQLI_ASSOC);

//stuff I do to make my life easier:
$return = array();         //for scoping reasons
if (isset($data[0]['id'])) {
  foreach ($data as $value) {
    $return[$value['id']] = $value;
  }
} else {
  $return = $data;
}

as far as I am concerned this should work.

edit

my class Connection basically works like this:

$this->connID = new mysqli($this->server, $this->user, $this->pass, $this->database);

if ($this->connID→connect_errno) { //debug stuff
  var_dump($this->connID->connect_error);
}

$this->connID->set_charset("utf8");

I guess this is all you will need.

Community
  • 1
  • 1