Assign value of a button for each row

Tags: php
Question!

I am trying to use php and I am really new to it.

I create one page that (with a php code) send the info to the database and one page that display the info from the databse.

My question is: Lets say I am going to input 10 info , but I am displaying just 5 of them, how can I display the rest of the info clicking to a button for each row?

Do I have to assign to the button a value? I cant understand how I can relate the button to the row.

Basically for each row I want to display the rest of the info of that specific row clicking on that specific button.

Any help will be appricciate. thanks

----- script that insert the info in the db-----

<?php

$name = mysqli_real_escape_string($link, $_POST['name']);
$mail = mysqli_real_escape_string($link, $_POST['mail']);
$number = mysqli_real_escape_string($link, $_POST['number']);
$device = mysqli_real_escape_string($link, $_POST['device']);
$model = mysqli_real_escape_string($link, $_POST['model']);
$problem = mysqli_real_escape_string($link, $_POST['problem']);

        $sql = "INSERT INTO cj (name, mail, number, device, model, problem) VALUES ('$name', '$mail', '$number', '$device', '$model', '$problem')";
        $result = mysqli_query($link, $sql);
        // if query fails stop script and echo error
    if( $result === false)
    {echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
        exit;
    }        
    header("location:add-customer.php?message=A job and customer has been added to the database");

    exit;
        echo "You'll never see this";
    ?>

----------- page that shows the info ------

     <?php
$sql = "SELECT * from "database name"";
    echo "
<table class='table'>
    <thead>
        <tr>";
/* Get field information for all columns */

    echo "<form action='' method=post>";
    echo "<tr class='info'>

                 <input type=hidden name=hidden value=" . $row['id'] . ">
                <td>" . $row['id'] . "</td> 
                <td>" . $row['device'] . "</td>
                <td>" . $row['model'] . "</td> 
                <td>" . $row['problem'] . "</td>
                <td>

            </td>        

                <td> 
                <a class='btn btn-primary btn-sm'  data-toggle='modal' data-target='#myModal' value= " . $row['id'] . " >  Info</a></form></td>

           </tr>"; 
    echo "</form>";


}
echo "
    </tbody>

</table>";

?>

<div class="container">
  <!-- Trigger the modal with a button -->
  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog modal-lg">
  <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Customer Information</h4>
        </div>

        <div class="modal-body">

       <?php
include("../includes/connection.php");
if ($link->connect_errno > 0) {
    die('Unable to connect to database [' . $link->connect_error . ']');
}
$sql = "SELECT name,mail,number from databasename WHERE **???**;


if (!$result = $link->query($sql)) {

    die('There was an error running the query [' . $link->error . ']');
}
echo "
<table class='table'>
    <thead>
        <tr>";
/* Get field information for all columns */
while ($finfo = $result->fetch_field()) {
    echo "
        <th>" . $finfo->name . "</th>";
}
echo "
        </tr>
    </thead>
    <tbody>";
while ($row = $result->fetch_assoc()) {
    echo "<tr class='info'>

                <td>" . $row['name'] . "</td>
                <td>" . $row['mail'] . "</td>
                <td>" . $row['number'] . "</td>

    </tr>";

...


Answers

Connect to datatabase and get all 10 info with PHP. But show only 5 info. Put a button there, and use Javascript or Jquery to show other rows. (Onclick event)

By : Mubariz


Here is what I will do,

1st, get the array of selected rows by using indexPathsForSelectedRows,

2nd, iterate the array to check if if indexPath.row is 1 or 2.

3rd, if your if statement's condition is true, then do ...



If I am reading this correctly, Message would contain a List<MessageUser>.

If that's the case then this should get you close:

var List<Message> messages = 
    ( from m 
      in db.Messages 
      where 
          m.UserID == userid || m.MessageUsers.Any(mu => mu.UserID == userID) 
      select m).ToList();
By : Sam Axe


This video can help you solving your question :)
By: admin