sql >> Database >  >> RDS >> Mysql

Kan geen relevante mysql-informatie naar de aangeklikte link uitvoeren met SELECT *FROM table WHERE-variabele LIKE '$variable'

Ik kan begrijpen hoe het is als je voor het eerst begint. Zodra je je geest rond de basisdelen ervan hebt gewikkeld, zal de rest stromen.

Omdat je om een ​​betere manier vroeg, ga ik een les voorstellen die ik persoonlijk in al mijn projecten gebruik.

https://github.com/joshcam/PHP-MySQLi-Database-Class

Vergeet natuurlijk niet om de eenvoudige MYSQLI-klasse van de bovenstaande link te downloaden en deze op te nemen zoals ik hieronder in uw project doe. Anders zal niets van dit alles werken.

Hier ons de eerste pagina die de tabel bevat met alle gebruikers van uw personen Db-tabel. We zetten ze in een tabel met een eenvoudige knop voor bewerken/bekijken.

PAGINA 1

 <?php 
        require_once('Mysqlidb.php');

        //After that, create a new instance of the class.

    $db = new Mysqlidb('host', 'username', 'password', 'databaseName');

    //a simple select statement to get all users in the DB table persons
    $users = $db->get('persons'); //contains an Array of all users 


    ?>
    <html>
    <head>



    <link  type="text/css" href="style.css">
    </head>
    <body>

<table>

    <th>
        First Name
    </th>
    <th>
        Last Name
    </th>
    <th>&nbsp;</th>

<?php 

//loops through each user in the persons DB table
//the id in the third <td> assumes you use id as the primary field of this DB table persons
foreach ($users as $user){ ?>
    <tr>
        <td>
            <?php echo $user['fname'];?>
        </td>
        <td>
            <?php echo $user['lname'];?>
        </td>
        <td>
        <a href="insert.php?id=<?php echo $user['id']; ?>"/>Edit/View</a>   
        </td>
    </tr>

<?php } ?>

</table>
</body>
    </html>

Dus dat eindigt je eerste pagina. Nu moet je deze code opnemen op je tweede pagina waarvan we aannemen dat deze insert.php heet.

PAGINA 2

<!--add this to your insert page-->

 <?php 
        require_once('Mysqlidb.php');

        //After that, create a new instance of the class.

    $db = new Mysqlidb('host', 'username', 'password', 'databaseName');

    //a simple select statement to get all the user where the GET 
    //variable equals their ID in the persons table
    //(the GET is the ?id=xxxx in the url link clicked)

    $db->where ("id", $_GET['id']);
    $user = $db->getOne('persons'); //contains an Array of the user

    ?>

<html>
<head>



<link  type="text/css" href="style.css">
</head>
<body>
    <table>

<th>
    First Name
</th>
<th>
    Last Name
</th>
<th>user ID</th>


<tr>
    <td>
        <?php echo $user['fname'];?>
    </td>
    <td>
        <?php echo $user['lname'];?>
    </td>
    <td>
    <?php echo $user['id']; ?>  
    </td>
</tr>

</body>
</html>


  1. PHP en checkboxes check die gaan naar tabel

  2. Laravel welsprekend withCount() verondersteld langzamer te zijn dan alleen with()

  3. Hoe installeer ik postgres met NSIS met alle parameters?

  4. Een lijst met databases retourneren in SQLite