This is probably a simple question but I cannot figure it out alone.
I want the column of the table to hold the part key as href to another page that does something. Without the href it works fine.
echo "<table border='1' style='width:300px'>";
echo "<tr>
<th>KEY</th>
<th>NAME</th>
<th>MFGR</th>
<th>BRAND</th>
<th>TYPE</th>
<th>SIZE</th>
<th>CONTAINER</th>
<th>RETAIL PRICE</th>
<th>COMMENT</th>
</tr>";
while($array=mysqli_fetch_array($result))
{
echo "<tr>";
//The following line gives me "Notice: Array to string conversion":
echo "<td> ".$array[0]. "</td>";
echo "<td> ".$array[1]. "</td>";
echo "<td> ".$array[2]. "</td>";
echo "<td> ".$array[3]. "</td>";
echo "<td> ".$array[4]. "</td>";
echo "<td> ".$array[5]. "</td>";
echo "<td> ".$array[6]. "</td>";
echo "<td> ".$array[7]. "</td>";
echo "<td> ".$array[8]. "</td>";
echo "</tr>";
}
echo "</table>";
The line that gives me trouble is the one with the href as I mentioned.
Apart from $nKey not being defined anywhere, you have problems on this line:
echo "<td> ".$array[0]. "</td>";
// ^
That's not where the href ends. You need to move this to where it actually ends:
echo "<td><a href='part.php?item_n= ".$array[0]."&key= ".$nkey."'> ".$array[0]. "</a></td>";
// ^
Edit:
Your real problem is that $nkey is an array, and not a string as you're expecting. Since this variable has been left out of the posted script it's hard to give any further suggestions until it's seen.
".$array[0]. "
^
This single quote is misplaced, place it after the whole address,
<a href='part.php?item_n= ".$array[0]."&key= ".$nkey."'> ".$array[0]. "</a>
^ here
Try this,
echo "<td><a href='part.php?item_n=".$array[0]."&key=".$nkey."'>".$array[0]. "</a></td>";
OR
echo "<td><a href='part.php?item_n=$array[0]&key=$nkey'>".$array[0]. "</a></td>";
Related
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>
I need to get the data of the database to an HTML table.
There were similar questions asked before but none of them were similar to my requirement.
I need to get the first row of the database to the first row of the table.
So I did this.
echo "<table id='main-table' border='1px solid'> <thead> ";
echo "<tr>";
echo "<th>Board No</th>";
echo "<th>Number</th>";
echo "</tr></thead><tbody>";
while($query->fetch()){
echo "<form action='' class='' method='post'><tr>";
line 55 --> echo "<td>" . Board Code:".$row["board_code"] . Number:".$row["status"] . "</td>";
echo "</tr> </form>";
}//End of While
echo "</tbody></table>";
There is a syntax error in line 55 as mentioned above in the code.
Check this code:
echo "<table id='main-table' border='1px solid'> <thead> ";
echo "<tr>";
echo "<th>Board No</th>";
echo "<th>Number</th>";
echo "</tr></thead><tbody>";
while($query->fetch()){
echo "<form action='' class='' method='post'><tr>";
echo "<td> Board Code:".$row["board_code"]. "</td>";
echo "<td>Number:".$row["status"]. "</td>";
echo "</tr> </form>";
}
echo "</tbody></table>";
"<td>" . Board Code:".$row["board_code"] ." Number:".$row["status"] . "</td>";
edit your code like if it does not work please share your whole code will help you for sure
Check with this code
echo "<form action='' class='' method='post'><tr>";
line 55 --> echo "<td>" . Board Code:".$row["board_code"] ." Number:".$row["status"] . "</td>";
echo "</tr> </form>";
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 working on uploading a file along with a description and table and then displaying it in a table format. My problem is that I'm not sure how to link my the path for the uploaded file into the table so the user can click on the link in the table and it will download.
Code:
This is what I'm attempting to use>
<?php
include 'connect.php';
$result = mysqli_query($con,"SELECT DocDate, Description, DocFile FROM Documents");
echo "<table border='0' width='100%'>
<col width='50'>
<col width='100'>
<tr>
<th>Date</th>
<th>Description</th>
<th>File</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['DocDate'] . "</td>";
echo "<td>" . $row['Description'] . "</td>";
echo "<td>" $row['DocFile'] "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
If you feel it to be usefull I'm happy to add the code where I upload the file to my server.
EdiT Sorry I put in the wrong variable thing into my table, I don't think it changes it too much
Is this what you're looking for?
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['DocDate'] . "</td>";
echo "<td>" . $row['Description'] . "</td>";
echo "<td> " . $row['DocFile'] . " </td>";
echo "</tr>";
}
This is how you can do
echo '<td>'.$name.'</td>';
I prefer to use ' ' and within it have the HTML since HTML will contain a lot of "" so no need to use escape them and then separate PHP and HTML with concatenation.
you have syntax error in this line in while loop:
echo "<td>" $name "</td>";
should be :
echo "<td> $name </td>";
In this line you have an error:
echo "<td>" $row['DocFile'] "</td>";
You need to scape the " character:
echo "<td> " . $row['DocFile'] . " </td>";
With your syntax you are creating an error because you are ending the string after the td tag.
If you are using a web url which uses a php variable in the url and want to open a new tab when you click on the hyper link, use this
echo "<td><a target='_blank' href=\"http://view.php?Id=".$row['Id']."\">". $row['Id'] ."</a></td>";
This is helpful when you have to use a php variable in the hyperlink and is being used in a table. Clicking on the Id will open the page related to that Id in a new tab in this case.
im trying to display the picture saved in the database using Php, but what i get is Url link which was saved in the database and not the picture, i think the syntax is wrong.
<?php
echo "<table border=\"1\" align=\"center\">";
echo "<tr>
<th>Name</th>
<th>Description</th>
<th>Price</th>
<th>Manufacturer</th>
<th>Image</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" .$row['Name']."</td>";
echo "<td>" .$row['Description'] ."</td>";
echo "<td>" .$row['Price'] ."</td>";
echo "<td>" .$row['Manufacturer'] ."</td>";
echo "<td>" .$row['ImageURL'] ."</td>";
echo "</tr>";
}
echo "</table>";
?>
</p>
<?php
You need to construct an <img> element, not just output the image URL.
Try replacing this: $row['ImageURL']
With this: "<img src='".$row['ImageURL']."' />
On this line:
echo "<td>" .$row['ImageURL'] ."</td>";
it looks like you'll want that to be:
echo "<td><img src='" .$row['ImageURL'] ."' /></td>";
Change
echo "<td>" .$row['ImageURL'] ."</td>";
to
echo "<td><img src='" .$row['ImageURL'] ."' style='width: 200px; height: 350px;' /></td>";
Modify the values 200px and 350px to whatever you want, just keep the 'px' suffix.