marksie1988 Posted April 3, 2008 Share Posted April 3, 2008 Hi, im trying to find some script that i can click on a link and it will open up some information below it which is pulled from a mysql table but each link needs to have a different query for the table to get the correct data. also i want the information to go directly below the link. would it be posible to do this with one mysql query as the only way ive been able to do it is with a query copied and pasted lots of times. is it possible to do like a variable link e.g. in php you would have the link, index.php?category="WEBSITES" and then you would call category in the mysql query. i need the same in javascript :S if you understand me Thanks Quote Link to comment Share on other sites More sharing options...
devstudio Posted April 4, 2008 Share Posted April 4, 2008 I am not entirely sure I understand. But I am going to assume your "WHERE" clause is all that needs to change. switch($category) { case 'WEBSITES': $whereTxt = " WHERE category = 'websites'"; break; case 'SOMETHINGELSE': $whereTxt = " WHERE category = 'SOMETHINGELSE'"; break; } if($whereTxt) { $queryTxt = "SELECT * FROM table ".$whereTxt; } else { // Select everything, or error? } No idea by what you mean that you need to do the same thing in JS. Best, Nathan Quote Link to comment Share on other sites More sharing options...
marksie1988 Posted April 8, 2008 Author Share Posted April 8, 2008 i dont think you know what i meant, basically i want to have a javascript where you click a link and it displays the info under that link here is an example http://corsarius.net/curriculum-vitae but i want the data shown to display the information from a mysql query. i have created the following script which doesnt display the information properly when i add the php into it but when i do it as html it works <?php include('../login/include/session.php'); include('../inc/header.php'); $cat="SELECT *,COUNT(*) FROM services_category,services WHERE services_category.category=services.category GROUP BY services_category.category order by services_category.pos";//select the info from the category table $cat2=mysql_query($cat) or die("Could not get services"); while($cat3=mysql_fetch_array($cat2)) { $cat1=$cat3['category']; //display the category as a header print"<p><a name=\"$cat1\"></a></p> <h3 onClick=\"expandcontent(this, '$cat1')\" style=\"cursor:hand; cursor:pointer\"> <span class=\"showstate\"></span>$cat1<br /> </h3>"; $getthreads="SELECT * from services WHERE category = '$cat1'";//select the boards from the table $getthreads2=mysql_query($getthreads) or die("Could not get threads123"); while($getthreads3=mysql_fetch_array($getthreads2)){ $getthreads3[title]=strip_tags($getthreads3[title]); $cats=strip_tags($getthreads3[category]); $totalservices = mysql_num_rows(mysql_query("SELECT * FROM services WHERE category='$cats'")); print "<div id=\"$cats\" style=\"visibility:hidden;\">"; print"<div id=\"$cats\" class=\"switchcontent\"> <p><b>University of the Philippines - Diliman (06/02 - 04/06)<br /> BS Computer Science</b></p> </div>"; print"testing"; print"</div>"; } } include('../inc/footer.php'); ?> here is the origonal html <script src="scripts/switch.js" type="text/javascript"></script> <p><a name="TEST1"></a></p> <h3 onClick="expandcontent(this, 'sc1')" style="cursor:hand; cursor:pointer"> <span class="showstate"></span>TEST1<br /> </h3> <div id="sc1" class="switchcontent"> <p><b>OOO THIS TEXT APPEARS</b></p> </div> <p><a name="TEST2"></a></p> <h3 onClick="expandcontent(this, 'sc2')" style="cursor:hand; cursor:pointer"> <span class="showstate"></span>TEST2</h3> <div id="sc2" class="switchcontent"> <p><b>WOW THIS TEXT APPEARS</b></p> </div> Quote Link to comment 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.