1

enter image description herei am beginner in php.

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>
6
  • Could you please put screen shot of your table out? Commented Aug 24, 2016 at 11:38
  • surround <td></td> with <tr></tr> Commented Aug 24, 2016 at 11:38
  • you miss <tr> fix it Commented Aug 24, 2016 at 11:39
  • You seem uncertain of your table and column names (pro_name/pname, etc..). And STOP using this deprecated API Commented Aug 24, 2016 at 11:40
  • if i use <tr> then all entry will goes in new row that i don't want i want matrx like represenatation Commented Aug 24, 2016 at 11:43

3 Answers 3

1

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     |
Sign up to request clarification or add additional context in comments.

3 Comments

if i use <tr> then all entry will goes in new row that i don't want i want matrx like represenatation
that is why i used <td> also for seperate coloumns
please see the picture
0

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>

1 Comment

sir if i use <tr> then all entry will goes in new row that i don't want i want matrx like represenatation
0

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>

1 Comment

Correct that's what i want

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.