Reputation:
i am maintaining all student's project database.
project details (pro_image,pro_name,pro_guide,pro_cost....etc)
and displaying this is in table format in html
what i want is after some 4-5 project entries .
pointer should goes new row then add 4-5 entries again.
But all project showing in same single column
what should i do ?
here my code :
<html>
<head> <title> cool </title> </head>
<body>
<?php
$conn=mysql_connect("localhost","root","");
if(!$conn)
{
die("Connection Failed :".mysqli_connect_error());
}
$sql="SELECT * FROM `pro_det` ";
mysql_select_db("dub");
$retval=mysql_query($sql,$conn);
if(!$retval)
{
die("could not get data".mysql_error());
}
?>
<table>
<?php
while($row=mysql_fetch_array($retval,MYSQL_ASSOC))
{
?>
<tr>
<img src= <?php"echo $row['pimages'] height="200" width="100"" ?>
<?php
echo" </br>";
echo" pname : {$row['pname']}</br>";
echo" project member : {$row['pmember']}</br>";
echo" project guide : {$row['pguide']}</br>";
echo" project abs : {$row['pabs']}</br>";
echo".................</br>";
?>
</tr>
<?php
}
echo"Fetched data sucessfully \n";
mysql_close($conn);
?>
</table>
</body>
</html>
Upvotes: 1
Views: 78
Reputation: 4738
You are missing tr
tag
in Html table structure is like
<table>
<tr>
<td></td>
</tr>
</table>
So your modified code will look like
<?php
while($row=mysql_fetch_array($retval,MYSQL_ASSOC))
{
?>
<tr>
<img src= <?php"echo $row['pimages'] height="200" width="100"" ?>
<?php
echo" <td>pname : {$row['pname']}</td>";
echo" <td>project member : {$row['pmember']}</td>";
echo" <td>project guide : {$row['pguide']}</td>";
echo" <td>project abs : {$row['pabs']}</td>";
?>
</tr>
<?php
}
echo"Fetched data sucessfully \n";
mysql_close($conn);
?>
</table>
EDIT 1: so your table structure will be like
pname | project member | project guide | project abs |
P1 | Pmem1 | PG01 | PA01 |
P2 | Pmem2 | PG02 | PA02 |
P3 | Pmem3 | PG03 | PA03 |
P4 | Pmem4 | PG04 | PA04 |
Upvotes: 1
Reputation: 3864
You have to use the modulo operator on a counter in order to add a <tr />
element every fourth line :
<table>
<tr>
<?php
$i = 0;
while($row=mysql_fetch_array($retval,MYSQL_ASSOC)) {
$i++;
/* Do your thing with tds here */
if ($i % 4 == 0)
echo '</tr><tr>';
}
?>
</tr>
</table>
Upvotes: 0
Reputation: 2036
I think you forgot tr
in your table
<?php
while($row=mysql_fetch_array($retval,MYSQL_ASSOC))
{
?>
<tr>
<td>
<img src= <?php"echo $row['pimages'] height="200" width="100"" ?>
<?php
echo" </br>";
echo" pname : {$row['pname']}</br>";
echo" project member : {$row['pmember']}</br>";
echo" project guide : {$row['pguide']}</br>";
echo" project abs : {$row['pabs']}</br>";
echo".................</br>";
?>
</td>
</tr>
<?php
}
echo"Fetched data sucessfully \n";
mysql_close($conn);
?>
</table>
Upvotes: 0