Skip to content

Instantly share code, notes, and snippets.

@LOCOSP
Created November 20, 2018 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LOCOSP/644da71257266df484521736344e161d to your computer and use it in GitHub Desktop.
Save LOCOSP/644da71257266df484521736344e161d to your computer and use it in GitHub Desktop.
//loop test
$result = mysqli_query($link, 'SELECT * FROM `supply` WHERE id=' . intval($_SESSION["id"]));
$rows = array();
while($row = mysqli_fetch_array($result))
$rows[] = $row;
foreach($rows as $row){
$ename = stripslashes($row['supplier_name']);
$produkt = stripslashes($row['product_name']);
$color = stripslashes($row['color_color']);
$quantity = stripslashes($row['quantity']);
$received = stripslashes($row['received']);
echo $received . '<br />';
echo $ename . '<br />';
echo $produkt . ' ' . $color . '<br />';
echo $quantity . '<br />';
@websafe
Copy link

websafe commented Nov 20, 2018

pisz ładnie

@websafe
Copy link

websafe commented Nov 20, 2018

oberwało Ci loopa

@websafe
Copy link

websafe commented Nov 20, 2018

$result = mysqli_query($link, 'SELECT * FROM `supply` WHERE id=' . intval($_SESSION["id"]));
$rows = array();
//
while($row = mysqli_fetch_array($result)) {
    $rows[] = $row;
}
//
print_r($rows);
//
foreach($rows as $row) {
    $ename = stripslashes($row['supplier_name']);
    $produkt = stripslashes($row['product_name']);
    $color = stripslashes($row['color_color']);
    $quantity = stripslashes($row['quantity']);
    $received = stripslashes($row['received']);
    echo $received . '<br />';
    echo $ename . '<br />';
    echo $produkt . ' ' . $color . '<br />';
    echo $quantity . '<br />';
}

@websafe
Copy link

websafe commented Nov 20, 2018

header('Content-Type: text/plain; charset=utf-8');
$query = 'SELECT * FROM `supply` WHERE id=' . intval($_SESSION["id"]);
echo $query;
$result = mysqli_query($link, $query);
$rows = array();
//
while($row = mysqli_fetch_array($result)) {
    $rows[] = $row;
}
//
print_r($rows);
//
foreach($rows as $row) {
    $ename = stripslashes($row['supplier_name']);
    $produkt = stripslashes($row['product_name']);
    $color = stripslashes($row['color_color']);
    $quantity = stripslashes($row['quantity']);
    $received = stripslashes($row['received']);
    echo $received . '<br />';
    echo $ename . '<br />';
    echo $produkt . ' ' . $color . '<br />';
    echo $quantity . '<br />';
}

@websafe
Copy link

websafe commented Nov 20, 2018

// Nagłówek tekstowy - wyswietlamy tekst a nie html (nie potrzebujemy wtedy <br> i print_r wygląda czytelniej)
header('Content-Type: text/plain; charset=utf-8');
//
$query = 'SELECT * FROM `supply` WHERE id=' . intval($_SESSION["id"]);
// Podgląd zapytania, które zaraz wykonamy:
echo $query . PHP_EOL;
// wykonujemy zapytanie
$result = mysqli_query($link, $query);
// Tworzymy pustą tablicę, która będzie przechowywać wiersze wyniku
$rows = array();
// Iterujemy przez wszystkie wiersze wyniku i wpisujemy do tablicy wierszy
while($row = mysqli_fetch_array($result)) {
    $rows[] = $row;
}
// Profilaktycznie wyświetlamy, co zebraliśmy w tablicy $rows:
print_r($rows);
//
foreach($rows as $row) {
    $ename = stripslashes($row['supplier_name']);
    $produkt = stripslashes($row['product_name']);
    $color = stripslashes($row['color_color']);
    $quantity = stripslashes($row['quantity']);
    $received = stripslashes($row['received']);
    echo $received .  PHP_EOL;
    echo $ename .  PHP_EOL;
    echo $produkt . ' ' . $color . PHP_EOL;
    echo $quantity . PHP_EOL;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment