Lena Siegland
Lena Siegland

Reputation: 13

Simple PHP: Select & Show Column not working

I need to show Data from today from a certain column. Can anyone help? Nothing appears. Thanks! Connection seems to work.

    <?php
$db = mysqli_connect("server", "username", "pw", "database");
if(!$db)
{
  exit("Verbindungsfehler: ".mysqli_connect_error());
}
?>

<?php
$abfrage = "SELECT type FROM customers WHERE DATE(time) = CURDATE()";
$ergebnis = mysql_query($abfrage);
while($row = mysql_fetch_object($ergebnis))
   {
   echo "$row->Spaltenname";
   }
?>

Upvotes: 0

Views: 343

Answers (2)

Shaer
Shaer

Reputation: 36

In addition to the query problem, you have another problem with your code, you used mysqli_connect, then you started to use the old deprecated mysql_* methods.

ini_set('display_errors', '1');
error_reporting (-1);
$abfrage = "SELECT * FROM `customers` WHERE DATE(`time`) = CURDATE()";
$ergebnis = mysqli_query($db, $abfrage);
echo mysqli_error($db);
while($row = mysqli_fetch_object($ergebnis))
{
   echo $row->Spaltenname;
}

Upvotes: 1

Dan Belden
Dan Belden

Reputation: 1217

Your query is only retrieving the "type" column.

$abfrage = "SELECT * FROM customers WHERE DATE(time) = CURDATE()";

Potentially expanding the columns in your SELECT may fix this?

  • Always worth trying the query on the DB directly, before implementing it in any code.

Goodluck.

Upvotes: 0

Related Questions