mercredi 12 août 2015

Rebel of while in php

Hey mates i wrote little code of php. This code shows the contents of a mysql database table and has a button osyłający further but unfortunately, while I and my revolts $ a variable is always the final value. example post about id = 1 click on the button when the address of the page + variable See table is 11 or variable which is at the exit of the loop. How to do to link to pages with the whole post with id 1 looked so looks.php example? Id = '1' ???????

  <?php
session_start();
    require_once 'connect.php';
    $a = 0;
    $conn = @new mysqli($host, $dbuser,$dbpass,$dbname);
    if ($conn->connect_errno!=0)
        {
             echo "Error ".$conn->connect_errno;
        }
     else {
           $id=$_SESSION["id"];
           #echo 'to jest nasze id '.$id;
           $sql = "select * from zgloszenia where user_id ='$id'; ";
           $wynik = $conn->query($sql);
           echo '<table class="table table-striped"><tr><th>id</th><th>stan</th><th>opis</th><th>data</th></tr>';
            while($row = $wynik->fetch_assoc())
                {

                $t[]=$row['id'];
                echo "<tr href='http://myspace.com'><td>".$row['id']."</td><td>".$row['stan']."</td><td>".$row['opis'].
                        "</td><td>".$row['data_zgl']."</td><td><form method ='post'><button  type='submit' name='submit' class='btn btn-default'>zobacz</button></form></td></tr>";

                            if (isset($_POST['submit']))
                         {

                             header('Location: zobacz.php?id='.$t[0].'');
                         }
               $a++;
                }
                echo '</table>';

            }
            print_r($t);
        $conn->close();

Aucun commentaire:

Enregistrer un commentaire