php_begins Posted December 5, 2011 Share Posted December 5, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/252515-display-results-of-query-by-clicking-a-hyperlink/ Share on other sites More sharing options...
ialsoagree Posted December 5, 2011 Share Posted December 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/252515-display-results-of-query-by-clicking-a-hyperlink/#findComment-1294665 Share on other sites More sharing options...
php_begins Posted December 5, 2011 Author Share Posted December 5, 2011 <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? Quote Link to comment https://forums.phpfreaks.com/topic/252515-display-results-of-query-by-clicking-a-hyperlink/#findComment-1294675 Share on other sites More sharing options...
ialsoagree Posted December 5, 2011 Share Posted December 5, 2011 It might have to do with the fact that you're telling PHP to echo the image within a new table row: echo "<tr>... Without ever having actually declared a table in HTML with <table>. Quote Link to comment https://forums.phpfreaks.com/topic/252515-display-results-of-query-by-clicking-a-hyperlink/#findComment-1294684 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.