i am trying this from 5hrs don't know i am going wrong.My table echos results but not echo total for the same.
<table width="102%" border="0">
<tr>
<th><b>Amount</b></th>
<th ><strong>County</strong></th>
</tr><?php
(this fetches data ...$row = mysqli_fetch_array($res) or die(mysqli_error($db)))
echo "<tr>";
echo "<td>" . $price . "</td>";
echo "<td>" . $rui['county'] . "</td>";
echo "</tr>";
(I get these entreis correct )
}
}
(Below table is not echoed)
echo "<tr>";
echo "<td> .<b>Total </b>. </td>";
echo "<td>" .$x. "</td>";
echo "<td></td>";
echo "</tr>";
?></table>
Remove the } } after the closing tag of the tr.
if you can't close the whole PHP block then you probably did something wrong in your syntax.
I don't know if you have more code or not, if you do - post it so we will get more accurate view of your code.
<table width="102%" border="0">
<tr>
<th><b>Amount</b></th>
<th ><strong>County</strong></th>
</tr>
<?php
(this fetches data ...$row = mysqli_fetch_array($res) or die(mysqli_error($db)))
echo "<tr>";
echo "<td>" . $price . "</td>";
echo "<td>" . $rui['county'] . "</td>";
echo "</tr>";
(I get these entreis correct )
(Below table is not echoed)
echo "<tr>";
echo "<td> .<b>Total </b>. </td>";
echo "<td>" .$x. "</td>";
echo "<td></td>";
echo "</tr>";
}
?>
</table>
You can remove the wrong bracket, OR check that the two bracket are opened when fetching data
<table width="102%" border="0">
<tr>
<th><b>Amount</b></th>
<th ><strong>County</strong></th>
</tr><?php
//(this fetches data ...$row = mysqli_fetch_array($res) or die(mysqli_error($db)))
echo "<tr>";
echo "<td>" . $price . "</td>";
echo "<td>" . $rui['county'] . "</td>";
echo "</tr>";
//(I get these entreis correct )
//(Below table is not echoed)
echo "<tr>";
echo "<td> .<b>Total </b>. </td>";
echo "<td>" .$x. "</td>";
echo "<td></td>";
echo "</tr>";
?>
</table>
Related
Two questions in one:
First question, mainly about presentation:
I'm echo-ing the following code which should create a table. The table should have a single column, but it's being rendered with the elements above the image as a single line. can anyone see why?
<?php
$sql = "SELECT * FROM catdata WHERE featured='yes' LIMIT 2";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['manufacturer'] . "</td>";
echo "</tr";
echo "<tr>";
echo "<td>" . $row['title'] . "</td>";
echo "</tr";
echo "<tr>";
echo "<td><img src=\"6.diesel.png\"></td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row['size'] . "l</td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row['mileage'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row['fitsmodel'] . "</td>";
echo "</tr>";
echo "<tr class=\"tablePriceBlock\">";
echo "<td>£" . $row['pricefitted'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>£" . $row['pricedel'] . "</td>";
echo "</tr>";
}
echo "</table>";
// Free result set
mysqli_free_result($result);
} else {
echo "No records matching your query were found.";
}
} else{
echo "ERROR: Unable to execute $sql. " . mysqli_error($link);
}
?>
Question 2:
Can I show the second result in a second column, or as a separate table? Also, is it possible to access the $result elements like say, $[manufacturer][1]?
Always look at the emitted source your code generates by either "View Source" or using a tool like curl. You'll find this mistake:
echo "</tr";
You're missing a >.
Many people who write HTML have browser plugins that can link through to an HTML validator to ensure they've got the correct syntax. You may want to find and install one of these.
To generate the second result is a separate table follow the following code.
echo "<table>";
$count = 1;
while($row = mysqli_fetch_array($result)){
if($count == 2){
echo "<table>";
echo "<tr>";
echo "<td>put your code here</td>";
echo "</tr>"
echo </table>
}else{
echo "<tr>";
echo "<td>" . $row['manufacturer'] . "</td>";
echo "</tr";
echo "<tr>";
echo "<td>" . $row['title'] . "</td>";
echo "</tr";
echo "<tr>";
echo "<td><img src=\"6.diesel.png\"></td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row['size'] . "l</td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row['mileage'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row['fitsmodel'] . "</td>";
echo "</tr>";
echo "<tr class=\"tablePriceBlock\">";
echo "<td>£" . $row['pricefitted'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>£" . $row['pricedel'] . "</td>";
echo "</tr>";
}
$count ++;
}
echo "</table>";
As you are limiting your query to only two record so this method is not bad for that and hope this will help.
I'm trying to update a mySQL table after a button click..The button click is not the problem but I wonder how I can get the klant_pk which is unique to update a certain record in mySQL. As you see I print out the mySql table at first. So is there anyone who know how I can get the according klant_pk after I click on a button in the table..
Thanks
$result = mysqli_query($con, "SELECT * FROM bestelling");
echo "Bestellingen";
echo "<table border='1' align='center'>
<tr>
<th>Bestelling_pk</th>
<th>Klant_pk</th>
<th>Product</th>
<th>Commentaar</th>
<th>Tijd</th>
<th> Voortgang </th>
<th> Status </th>
</tr>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['bestelling_pk'] . "</td>";
echo "<td>" . $row['klant_pk'] . "</td>";
echo "<td>" . $row['product'] . "</td>";
echo "<td>" . $row['opmerking'] . "</td>";
echo "<td>" . $row['tijd'] . "</td>";
echo "<td> <input type='button' value='In Wacht' onclick='return change(this);' />";
echo "<td>" . $row['status'] . "</td>";
echo "</tr>";
}
echo "</table>";
while ($row = mysqli_fetch_array($result)) {
...
echo "<td id='klank_pk_".$row['klant_pk']."'>" . $row['klant_pk'] . "</td>";
...
echo "<td> <input type='button' value='In Wacht' onclick='change(getElementById('klank_pk_".$row['klant_pk']."').value);' />";
...
}
i'm trying to do a table with php which takes the data from my database and build's the table im html but despite my while loop , only the 1st row is getting into the table. If i change the while loop before the
echo "<table border='1' cellpadding='2' cellspacing='2'";
I get all of them but in 3 tables.
What's wrong with the code ?
<?php
require 'connect.php';
$query = $link->query("SELECT * FROM fornecedor");
echo "Fornecedores";
echo "<table border='1' cellpadding='2' cellspacing='2'";
echo "<tr>
<td>Nome</td>
<td>NIF</td>
<td>Cidade</td>
<td>Rua</td>
<td>NrPorta</td>
<td>Website</td>
<td>email</td>
</tr>";
while ($row = mysqli_fetch_array($query)) {
echo "<tr>";
echo "<td>" . $row["Nome"] . "</td>";
echo "<td>" . $row["NIF"] . "</td>";
echo "<td>" . $row["Cidade"] . "</td>";
echo "<td>" . $row["Rua"] . "</td>";
echo "<td>" . $row["NrPorta"] . "</td>";
echo "<td>" . $row["Website"] . "</td>";
echo "<td>" . $row["Email"] . "</td>";
echo "</tr>";
echo "</table>";
};
?>
Move echo "</table>"; out of the while loop-
....
while(){
.....
// don't close the table tag here
}
echo "</table>";
For each row you are adding the closing </table> tag which should not be like that.
echo "</table>"; code must be out of the while loop. It must be written once only.
I am new to PHP and I have problem. I have a table with check boxes. I need to add if statement inside the check box.
echo "<div class='table1'>
<table>
<tr>
<td></td>
<td>Module code</td>
<td>Module Title</td>
<td>Option</td>
</tr>";
echo "<form action='confirmsubmission.php' method='post'>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . "<input type='checkbox' name='check[]'
value='".$row['module_id']."' />" . "</td>";
echo "<td>" . $row['module_id'] . "</td>";
echo "<td>" . $row['module_title'] . "<a href=# content='".$row['description']."'
class='tooltip'><span title='Module Description'><img src='images/i.png'/></span>
</a>". "</td>";
echo "<td>" . $row['module_choice'] . "</td>";
echo "</tr>";
}
echo "</table></div>";
Below is a If statement I need to add after value='".$row['module_id']."'
if($row['module_choice']=='Mandatory'){ echo "checked=\"true\""; }
A bit of a mouthful, but try:
...
echo "<td>" . "<input type='checkbox' name='check[]' value='".$row['module_id']."'".($row['module_choice']=='Mandatory' ? 'checked="true"' : "")." />" . "</td>";
...
Even though I'll advise you to use a templating system (Smarty, etc.), you can do the following code:
echo "<div class='table1'>
<form action='confirmsubmission.php' method='post'>
<table>
<tr>
<td></td>
<td>Module code</td>
<td>Module Title</td>
<td>Option</td>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . "<input type='checkbox' name='check[]'
value='".$row['module_id']."'";
if($row['module_choice']=='Mandatory'){
echo " checked='checked' ";
}
echo "/>" . "</td>";
echo "<td>" . $row['module_id'] . "</td>";
echo "<td>" . $row['module_title'] . "<a href=# content='".$row['description']."'
class='tooltip'><span title='Module Description'><img src='images/i.png'/></span>
</a>". "</td>";
echo "<td>" . $row['module_choice'] . "</td>";
echo "</tr>";
}
echo "</table></form></div>";
I want to display data in database in table form. I wrote the following code
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['EmpID'] . "</td>";
echo "<td>" . $row['EmpName'] . "</td>";
echo "<td>" . $row['Designation'] . "</td>";
echo "<td>" . $row['Salary'] . "</td>";
echo "<td><a href='upasg3.php?empid='". $row['EmpID'] .">Edit</a ></td>";
echo "<td><a href='upasg3.php?empid='". $row['EmpID'] .">Delete</a ></td>";
echo "</tr>";
}
But i dont get the value of $row['EmpID'] concatenated with the value of href. It redirects to the upasg3.php with empid= blank.
how to fix this? Please help
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['EmpID'] . "</td>";
echo "<td>" . $row['EmpName'] . "</td>";
echo "<td>" . $row['Designation'] . "</td>";
echo "<td>" . $row['Salary'] . "</td>";
echo "<td><a href='upasg3.php?empid=". $row['EmpID'] ."'>Edit</a ></td>";
echo "<td><a href='upasg3.php?empid=". $row['EmpID'] ."'>Delete</a ></td>";
echo "</tr>";
}
quotes.
Try removing the single quotes after empid=
And putting them here like this:
echo "<td><a href='upasg3.php?empid=". $row['EmpID'] ."'>Edit</a ></td>";
echo "<td><a href='upasg3.php?empid=". $row['EmpID'] ."'>Delete</a ></td>";
This will give you an output like:
<a href='upasg3.php?empid=100'>
Try
echo "<td><a href='upasg3.php?empid=". $row['EmpID']."'>Edit</a ></td>";
^ ^
<table width="100%" border="1">
<tr>
<td>ID</td>
<td>NAME</td>
<td>Designation</td>
<td>Salary</td>
<td>Edit</td>
<td>Delete</td>
</tr>
<tr>
<td><?=$row['EmpID']?></td>
<td><?=$row['EmpName']?></td>
<td><?=$row['Designation']?></td>
<td><?=$row['Salary']?></td>
<td>Edit</td>
<td>Delete</td>
</tr>
try this
echo "<td><a href='upasg3.php?empid=". $row['EmpID'] ."'>Edit</a ></td>";
echo "<td><a href='upasg3.php?empid=". $row['EmpID'] ."'>Delete</a ></td>";
Your quotes were in wrong place.