Jump to content

Show/Hide table row from mysql db with php


linuh2009

Recommended Posts

Hi there.I really need help on this and don`t know anybody that could do it ???.What is all about: i have a mysql database and php to display the content from one table in HTML format.What i need is that when i click on a row (doesn`t matter what cell) to give me an extra row(show/hide) witch will display the content from a column inside mysql, same table and it is not displayed normally.Using HTML and js i could do it, but since i`m new to php & MySQL i just don`t know how to do this.

In html i did that :

# <html>

# <head>

# <style type="text/css">

# .hide

# {

#    display: none ;

# }

# .show

# {

#    display: block;

#    background-color: #d0d0d0;

# }

# </style>

# <script type="text/javascript">

# function showHide(id)

# {

#    if (document.getElementById)

#    var obj = document.getElementById(id);

#    if (typeof(obj)=='undefined' || obj==null) return;

#    if (obj.className == 'hide') obj.className='show';

#      else obj.className='hide';

# }

# </script>

# </head>

# <body>

# <table border="1">

# <tr>

# <td>HEAD1</td>

# <td>HEAD2</td>

# <td>HEAD3</td>

# <td>HEAD4</td>

# </tr>

#    <tr onclick="showHide('rnd1');">

# <td>ROW1</td>

# <td>ROW1</td>

# <td>ROW1</td>

# <td>ROW1</td>

#    </tr>

#    <tr id="rnd1" class="hide">

# <td colspan="4">Describe row 1</td>

#    </tr>

#    <tr onclick="showHide('rnd2');">

# <td>ROW2</td>

# <td>ROW2</td>

# <td>ROW2</td>

# <td>ROW2</td>

#    </tr>

#    <tr id="rnd2" class="hide">

# <td colspan="4">Describe row 2</td>

#    </tr>

# </table>

# </body>

# </html>

In PHP i use that to display it after the table header.

<?

while($row = mysql_fetch_array($result))

{

echo "<tbody align='center'>";

echo "<tr>";

echo "<td align='left'>". $row['id'] ."</td>";

echo "<td align='left'>". $row['denumire'] . "</td>";

echo "<td>" . $row['nrinv'] . "</td>";

echo "<td>" . $row['um'] . "</td>";

echo "<td>" . $row['cantitatea'] . "</td>";

echo "<td>" . $row['achizitie'] . "</td>";

echo "<td>" . $row['initial'] . "</td>";

echo "<td>" . $row['actual'] . "</td>";

echo "<td>" . $row['locatia'] . "</td>";

echo "</tr>";

echo "</tbody>";

echo "<tr>";

}

echo "</table>";

mysql_close($con);

?>

I just don`t know how to do this in php as in HTML/JS.

Thank you for your time and i hope i managed to explain what i need, but most of all i hope someone could help me. I`m trying to do that for 3 days now and i`m out of time....ThankYou.

Link to comment
Share on other sites

Ok.For php to display i could use this after table header

 

<?

echo "</tr>\n";

while($row = mysql_fetch_row($result))

{

    echo "<tr class='entry show'>";

          foreach($row as $cell)

        echo "<td><a  onClick=\"toggle_it('pr1')\">$cell</a></td>";

 

    echo "</tr>\n";

}

mysql_free_result($result);

?>

What i need is this example : http://daagest.feaa.uaic.ro/teste/example1/index.html

But to get all the content from MySQL, with a lot more rows ofc.... When click on a row`s cell to give an extra row right under the one i clicked, wich will contain some data stored in another mysql column in same table, column displayed only when clicked on row.....Thank you.

Link to comment
Share on other sites

Sorry for my mistake.In php i could use this code after table`s header.

 

<?

echo "</tr>\n";

while($row = mysql_fetch_row($result))

{

    echo "<tr class='entry show'>";

          foreach($row as $cell)

        echo "<td>$cell</td>";

 

    echo "</tr>\n";

}

mysql_free_result($result);

?>

Instead of all thoose "echoes"...:S

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.