Hi,
First of all I am Sorry for such a long query.
I am using mysql db.I wanted to display data present in the db.I am using two functions showdiv() & hidediv().
For example,I have 26 tables in my db say from A-Z.In each table it has some info.for examp, in table 'A' it has A1,A2,A3... In table 'B' it has B1,B2..The page where the data from db must display is something like this.

<html>
<body>
<table>
<tr> 
<td class="imag" id="def">| <a href="home.html"> Home </a> | <a href="ab.php"> About Us </a>| <a href="st.php"> Staff </a> | <a href="med.php"> Medicines</a> |<a href="hc.html"> Health Care</a> |<a href="news.html"> News </a>|</td></tr>

This is the 1st row and in the 2nd row it contains alphabets A-Z.Here is the code

<tr><td>
<a href="javascript:switchid('div1');" style="text-decoration:none;" >A </a>&nbsp;
<a href="javascript:switchid('div2');" style="text-decoration:none;" >B</a>&nbsp;
<a href="javascript:switchid('div3');" style="text-decoration:none;" >C</a>&nbsp;
                                                    .
                                                    .
                                                    .
<a href="javascript:switchid('div25');" style="text-decoration:none;" >Y</a>&nbsp;
<a href="javascript:switchid('div26');" style="text-decoration:none;" >Z</a></td></tr>

Now in the next row I wanted the to display infor from db.For exam, when I click 'A' the data in table 'A' must display.If I click 'B',in the same row instead of data from 'A' data from table 'B' must display.Code I wrote is

<tr><td>
   
<?
$str="SELECT * FROM a";

$res=mysql_query($str);

if(mysql_num_rows($res)!=0)
{

while($data=mysql_fetch_array($res,MYSQL_ASSOC))
 {
   echo '<tr>';
    
      echo ' <td class="pos" id="div1" style="display:none;text-decoration:none; "> <a href="'.$data['MedName'].'" >' .$data['dispname'].' </a></td > ';
      echo '</tr>';
 }

}
$str="SELECT * FROM b ";

$res=mysql_query($str);

if(mysql_num_rows($res)!=0)
{

while($data=mysql_fetch_array($res,MYSQL_ASSOC))
 {
   echo '<tr>';
    
      echo ' <td  class="pos" id="div2" style="display:none;"> <a href="'.$data['MedName'].'" >' .$data['dispname'].' </a></td > ';
      echo '</tr>';
 }
 

}
else
 echo 'Failure';

So on upto 'Z'
And in the head I wrote

<script language="javascript" type="text/javascript">

var ids=new Array('div1','div2', 'div3', 'div4', 'div5', 'div6', 'div7', 'div8', 'div9', 'div10', 'div11', 'div12', 'div13', 'div14', 'div15', 'div16','div17', 'div18', 'div19', 'div20', 'div21', 'div22', 'div23', 'div24', 'div25', 'div26');

function switchid(id)
{
 hideallids();
 showdiv(id);
}

function hideallids()
{
  for(var i=0;i<ids.length;i++)
   { 
     hidediv(ids[i]);
    }
}

function hidediv(id)
{
  if(document.getElementById)
   {
     document.getElementById(id).style.display ='none';
   }
   else
    {
      if(document.layers)
       {
         document.id.display ='none';
       }
       else
        {
           document.all.id.style.display ='none';
        }
     }
}     

function showdiv(id)
{
  if(document.getElementById)
   {
     document.getElementById(id).style.display ='block';
   }
   else
    {
      if(document.layers)
       {
         document.id.display ='block';
       }
       else
        {
           document.all.id.style.display ='block';
        }
     }
}   



</script>

I am able to display data but my problem is that when I click 'A' onli A1 is displaying.when I click 'B' onli B1 is displaying not in the same row but some where down in the next row.For each alphabet data displayed is onli one and in the next row.

Once again Sorry for such a lengthy query.

Thank You

wow, you are making things so difficult. you can use php to grab all of the table names in the database and display them. you can also use ajax to retrieve the info in the database without all of the excessive coding. if you need me to write some code for you I will. just let me know.

ajax to retrive info from db...?I dont know ajax :(

Here is the solution :

<table border="1" align="center" >
<tr> <td>
<a href=medi.php?alpha=a >A</a>&nbsp;
<a href=medi.php?alpha=b>B</a>&nbsp;
<a href=medi.php?alpha=c>C</a>&nbsp;
<a href=medi.php?alpha=d>D</a>&nbsp;
                          .
                          .
 <a href=medi.php?alpha=z>Z</a>
</td></tr> 
<tr><td>
<?
$alphabet = $_GET['alpha'];
$str = "select * from tab_name where alphabet = '$alphabet' ";
$res=mysql_query($str);
if(mysql_num_rows($res)!=0)
{
while($data=mysql_fetch_array($res,MYSQL_ASSOC))
 {
   echo '<tr>';
    
      echo ' <td id="ghi"> <a href="'.$data['MedName'].'" >' .$data['dispname'].' </a></td > <br> ';
	 
      echo '</tr>';
	 }
  }
 else 
 echo 'Failure';
mysql_close($con);
?>
</td></tr>

make sure you check the variable you are receiving from the url for malicious data. if I wanted to, I could use sql injection and delete your database.

make sure you check the variable you are receiving from the url for malicious data. if I wanted to, I could use sql injection and delete your database.

How can you delete my database?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.