-1

Yesterday I asked a question about array, with commas, output as column. Check it here Today I have come this far:

<?php require_once("dbconnection.php"); ?>

<?php

$sql = "SELECT amount, ingredients FROM opskriftreg LIMIT 1;";

$ingredients =  explode(',', $row['ingredients']);
$amount      =  explode(',', $row['amount']);

echo '<table>';
        for ($i = 0; $i < count($ingredients); $i++) {
          echo '<tr>';
          echo '<td>', $ingredients[i], '</td>';
          echo '<td>', $amount[i], '</td>';
          echo '</tr>';
        }
        echo '</table>';

?>

The site shows an empty table now, but no errors, no nothing.

Anybody got any ideas??

Community
  • 1
  • 1
Münter
  • 179
  • 1
  • 2
  • 8
  • You've got perfect answer there already, **You should look into normalizing your data. Putting comma separated lists into a record usually means that you have yet to learn how relational databases really work.** – Your Common Sense Apr 04 '14 at 06:34
  • The database connection works. Tried with a different setup, but only showed at array in a line – Münter Apr 04 '14 at 06:35

1 Answers1

1

You didn't executed the query..

$sql = "SELECT amount, ingredients FROM opskriftreg LIMIT 1;";

// $result = mysqli_query($mysqli_link, $sql);
// $row = mysqli_fetch_array($result);    

$ingredients =  explode(',', $row['ingredients']);
$amount      =  explode(',', $row['amount']);

Go to mysqli_query for more help.

Ashwini Agarwal
  • 4,828
  • 2
  • 42
  • 59
  • Tried this just get two errors. `Warning: mysqli_query() expects at least 2 parameters` `Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result` – Münter Apr 04 '14 at 06:38
  • Fixed it now, but now I am back to square one. Doesn't show anything – Münter Apr 04 '14 at 06:54