Reputation: 25
Edit: After receiving some help, I edited some parts and here formlarigor2.php file and I got new error says 1)mysqli_stmt_bind_result() expects at least 2 parameters, 1 given.... 2)mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in C.. I want to layout the page like given. That's why I used td> codes.. Any help? :`
<?php
$conn = mysqli_connect("localhost","root","","son_fbe");
if (mysqli_connect_error()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
$formid = isset($_GET['formid ']) ? $_GET['formid '] : '';
if ($stmt = mysqli_prepare($conn, "SELECT * FROM derssaydirma WHERE formid = ?")) {
mysqli_stmt_bind_param($stmt, "s", $formid );
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt);
}
?>
<!DOCTYPE html>
<html lang="en">
<head> <title></title> </head>
<body> <table align="center" bordercolor="#CCCCCC" border="1" >
<?php
$i=0;
while($row = mysqli_fetch_array($stmt)) {
if($i%2==0)
$classname="even";
else
$classname="odd";
?>
<tr class="<?php if(isset($classname)) echo $classname;?>">
<td width="235">Form ID</td>
<td width="299"><?php echo $row["formid"]; ?></td>
</tr>
<tr class="<?php if(isset($classname)) echo $classname;?>">
<td>O_AdiSoyadi</td>
<td><?php echo $row["O_AdiSoyadi"]; ?></td>
</tr>
<tr class="<?php if(isset($classname)) echo $classname;?>">
<td>OgrenciNo</td>
<td><?php echo $row["OgrenciNo"]; ?></td>
</tr>
<tr class="<?php if(isset($classname)) echo $classname;?>">
<td>Program_BaslanilanDonem</td>
<td><?php echo $row["Program_BaslanilanDonem"]; ?></td>
</tr>
//There are about 20 more like this code block( <tr></tr> <?php
$i++;
}
?>
</table>
`
I have a table that consists of more than 25 columns. There is a page that shows forms waiting for approval. In that form, I do not show all columns instead I show only a few. I do that using PHP code. Here my code.
There is a part that says see all submitted forms and go to that forms. I am able to see all submitted ones however I could not see the specific row. For example, the table displays formid, name and etc, I want to get information of formid's 2. How can I do that? `
Upvotes: 0
Views: 74
Reputation: 49375
Use the form id as parameter
<td width="174" class="centertext"><a href="formlarigor2.php?formid=<?php echo $row["formid"]; ?>"> Go to the form</a></td>
and in the formlarigor2.php you can get it as, where you put it at the start of php .
$formid = isset($_GET['formid ']) ? $_GET['formid '] : '';
if ($stmt = mysqli_prepare($conn, "SELECT * FROM derssaydirma WHERE formid = ?")) {
/* bind parameters for markers */
mysqli_stmt_bind_param($stmt, "s", $formid );
/* execute query */
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $col1, $col2,$col3,$col4,$col5,$col6);
while (mysqli_stmt_fetch($stmt)) {
printf("%s %s\n", $col1, $col2);
}
}
the fetch row part is usually in a while loop ti get multiple rows. but you have only one
Upvotes: 1
Reputation: 5589
I am guessing that "Go to the Form" will be showing more information about the form in a different page layout.
So the element in the html should link to another php page that shows that form in detail.
The link should take the id
of the selected form.
<td width="174" class="centertext"><a href="formlarigor2.php/?formId=<?php echo $row["formid"]; ?>"> Go to the form</a></td>
And that linked php page will have a query that says something like:
$formId = $_GET['formId'];
$stmt = $mysqli->prepare("SELECT * FROM derssaydirma where id = ?");
$stmt->bind_param("i", $formId);
$stmt->execute();
$result = $stmt->get_result();
The using $result you can do the detail layout.
Note the use of prepared statements to avoid SQL injection.
Upvotes: 1