Jump to content

display results of query by clicking a hyperlink


php_begins
 Share

Recommended Posts

I have no clue about to go abt this one:

I have  form which has some:

<table>
   <tr>
     <td>
        <form>
         Title
        display info
         </form>
     </td>
   </tr>
</table>

 

I need to add an additional link next to title such that when someone clicks on the link the table expands and displays rsult of a query.

 

<table>
   <tr>
     <td>
        <form>
         Title          LINK
         if( link is clicked )
        {
           $query=select
           display query results
        }
        else
       {
         dont display query results
         display info
       }
         </form>
     </td>
   </tr>
</table>

 

 

 

Link to comment
Share on other sites

There's two possible ways to handle this. One involves javascript (and possibly AJAX, depending on how exactly you want to tackle the problem), the other is simpler if you don't know javascript but requires two pages.

 

For the latter, write a web page that looks how you want it to look if the hyperlink isn't clicked, then write a web page that looks how you want it to look if the hyperlink is clicked. Then have the hyperlink from the 1st page link to the 2nd page.

 

For javascript solutions, you should really inquire in the javascript section of the forums. Suffice it to say, one way to solve the problem with javascript and without AJAX is to replace the text of the table (or whatever the text your trying to replace is contianed in) with the results of the query, preformatted via PHP and included in the javascript sent to the browser after the PHP script runs.

 

Using AJAX, you do essentially the same thing, but instead of running the query when the page first loads and loading the results into javascript, you have the javascript call a PHP page that does the query upon request, formats the data, and then have javascript update the current page with the data from the AJAX request.

Link to comment
Share on other sites

<script type="text/javascript">

function toggleMe(a){
  var e=document.getElementById(a);
  if(!e)return true;
  if(e.style.display=="none"){
    e.style.display="block"
  } else {
    e.style.display="none"
  }
  return true;
}
</script>

<input type="button" class="button" onclick="return toggleMe('para1')" value="Show all Banners">
<div id="para1" style="display:none">
     <?
        $allbanners=mysql_query("SELECT * from ads where active='Y' )           or die(mysql_error());
while($allbanners_results = mysql_fetch_assoc($allbanners))
{

   $banner_image_path = $allbanners_results['image_path'];  
		                
   $banner_url = $allbanners_results['URL']; 

   $banner_title = $allbanners_results['title'];
   echo "<tr><td width='468' align='left'><a href='".$banner_url."'><B><font size='3' face='arial'>".$banner_title."</font></B><img border=0 src='./images/" . $banner_image_path . "'></a></td></tr>";
  echo "testing"

}
     ?>
  </div>

the above code works for only text expansion but does not expand or hide images..why is that so?

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

×
×
  • 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.