473,396 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

help: include file with variable inside div tag

28
I have a simple message board I created a while back.

Recently they've asked me to add threading support for messages.

so I created a seperate thread page, which gives me each threaded message after querying the database.

Then, on the main page, what I want it to do is display the original message,
then display the threads under it, after you click on the "show threads" link im trying to put somwhere around the original thread. Then display the next message, with threads under it (of course after the thread button is clicked). I don't want the page to refresh if possible and dont mind if i need to pull all the data first, then format it after, then display the page.

I'll paste pertinent code below, if im missing anything, i'm glad to throw any code requested:

main page
Expand|Select|Wrap|Line Numbers
  1. <head>
  2.  
  3. <style type="text/css">
  4. div {
  5. color: white;
  6. display: none;
  7. }
  8. </style>
  9.  
  10. <script language="JavaScript">
  11. function setVisibility(id, visibility) {
  12. document.getElementById(id).style.display = visibility;
  13. }
  14. </script>
  15.  
  16. </head>
  17.  /* more page data */
  18.  
  19. // database query to show messages withought the thread
  20. $result=mssql_query("SELECT * FROM Message_Board WHERE $searchby LIKE '%$search2%' 
  21. AND thread_number=0
  22. ORDER BY TStamp DESC");
  23.  
  24. // loop to display message without thread
  25. $i=0;
  26. while ($i < $num) {
  27.  
  28. $First_Name=mssql_result($result,$i,"First_Name");
  29. $Category=mssql_result($result,$i,"Category");
  30. $TStamp=mssql_result($result,$i,"TStamp");
  31. $msg=nl2br(mssql_result($result,$i,"msg"));
  32. $id=mssql_result($result,$i,"id");
  33. $thread_number=mssql_result($result,$i,"thread_number");
  34. $thread_id=mssql_result($result,$i,"thread_id");
  35.  
  36. ?>
  37.  
  38. <? echo $msg; ?>
  39. <br>
  40. <input type=button name=type value='Show Layer' onclick="setVisibility('sub3', 'inline');";><input type=button name=type value='Hide Layer' onclick="setVisibility('sub3', 'none');";> 
  41.  
  42. <div id="sub3"><? include('threadtest.php?thread_id=$thread_id'); ?></div>
  43. <?
  44.  
  45. $i++;
  46.  
  47. }
  48.  
  49. mssql_close();
  50. ?>
  51.  
here's pertinent code for 'threadtest.php:
Expand|Select|Wrap|Line Numbers
  1. <? $thread_id=$_GET['thread_id']; ?>
  2.  
  3. // database query
  4. $result=mssql_query("SELECT * FROM Message_Board 
  5. WHERE $searchby LIKE '%$search2%' 
  6. AND thread_id=$thread_id
  7. AND thread_number != 0
  8. ORDER BY TStamp ASC");
  9.  
  10. // loop to display threaded messages for the message with "thread_id"
  11. <?
  12. $i=0;
  13. while ($i < $num) {
  14.  
  15. $First_Name=mssql_result($result,$i,"First_Name");
  16. $Category=mssql_result($result,$i,"Category");
  17. $TStamp=mssql_result($result,$i,"TStamp");
  18. $msg=nl2br(mssql_result($result,$i,"msg"));
  19. $id=mssql_result($result,$i,"id");
  20. $thread_number=mssql_result($result,$i,"thread_number");
  21. $thread_id=mssql_result($result,$i,"thread_id");
  22.  
  23. ?>
  24.  
  25. <tr>
  26. <td>
  27. <hr width=50%>
  28. <? echo $msg; ?><br><font size=1><tt><? echo $First_Name; ?> at <? echo $TStamp; ?></tt></font> 
  29. </td>
  30. </tr>
  31.  
  32. <?
  33.  
  34. $i++;
  35.  
  36. }
  37.  
  38. mssql_close();
  39.  
I put the code for the loops in so you see what I'm trying to do.
If the message has a thread number of 0, its the original message, any message with higher values would be threads for that particular message. in which I don't want to be displayed unless clicked on. And just an fyi, the thread_id is the same on the original message and any threaded messages off that particular original message.

i also know from reading forums all day that i can't put variables in an include statement
Expand|Select|Wrap|Line Numbers
  1. include('threadtest.php?thread_id=$thread_id');
, but i wanted to show what i am looking to return, and the fact that the threadtest.php page needs the thread_id (which would be different for each original message) and then hits the database again with it (should I be hitting the database twice like that?).

I left out a lot of code i figured would be useless for this question. Plz assume the database connects correctly and im getting the results from the database that i want.

When i browse to www.website.com/threadtest.php?thread_id=2345 ,for example,
it displays exactly what i want to include on the main page. i only want it to display tho when the user clicks.

I believe i would be able to code it with the page refreshing, but i'm sure there must be a way to do what i'm trying to.

My other problem (non php related?) is in the list of original messages, it doesnt matter which "click to view thread" button i hit, it always displays in the first message only ....i.e., i click on the "view thread" button for message number 3, but the drop down appears in message number 1.

any help appreciated =) thx
Oct 2 '08 #1
5 3409
Dormilich
8,658 Expert Mod 8TB
If you don't want to use refresh you can use ajax for that, another advantage of this is, that you can call a script with parameters.

regards ← has to break-fast now
Oct 2 '08 #2
Markus
6,050 Expert 4TB
Put the thread id in a constant, before you include the file. Then you can access the constant in the included file. Simple.

Cheers,
Markus has an inkling he may be of no help because he has just woke up. :D
Oct 2 '08 #3
wizdom
28
Put the thread id in a constant, before you include the file. Then you can access the constant in the included file. Simple.

Cheers,
Markus has an inkling he may be of no help because he has just woke up. :D
Thanks for the response, I go back on sunday so I will give it a shot.

Here's what I'm thinking I'm going to try then...

from lines 34 - 43 on the main page code, looks like I already set the thread_id, so just removing the variable in the include statement may work =)
likt this:
Expand|Select|Wrap|Line Numbers
  1. $thread_id=mssql_result($result,$i,"thread_id"); 
  2.  
  3. ?> 
  4.  
  5. <? echo $msg; ?> 
  6. <br> 
  7. <input type=button name=type value='Show Layer' onclick="setVisibility('sub3', 'inline');";><input type=button name=type value='Hide Layer' onclick="setVisibility('sub3', 'none');";>  
  8.  
  9. <div id="sub3"><? include('threadtest.php'); ?></div> 
  10. <? 
  11.  
and then from threadtest.php remove:
Expand|Select|Wrap|Line Numbers
  1. <? $thread_id=$_GET['thread_id']; ?> 
=======================================

If you don't want to use refresh you can use ajax for that, another advantage of this is, that you can call a script with parameters.

regards ← has to break-fast now
Thanks Dorm, I will check on ajax for the non refresh
Oct 2 '08 #4
Markus
6,050 Expert 4TB
Yep, I gave it a quick glance and looks fantabbydoosy!

See you 'round
Oct 2 '08 #5
wizdom
28
thanks guys for all the help,

i needed to make a couple changes to make it work, but all basically based on the above changes.

i had to change the variables in the second loop (in threadtest.php) because i think the loop variables in threadtest were switching the loop variables in the main page.....particularly "$i" , "$result", and "$num".

looks like i also had a "mssql_close();" at the end of threadtest.php which may have been stopping the loop from the main page, removed it along with a "session_start();", and an extra database connect string i had in threadtest.php.

I also fixed the problem where the thread was only displaying on the first message, i used the value of $id to add to the id name in the div tag, worked perfectly for each message, and it doesn't reload the page, and I didn't have to use ajax, altho i want to learn more about ajax for future reference, once the fixes were in, the page actually workd =)

Here's the changed code for anyone interested, once again really appreciate the help and i hope i can help someone else out at some point =)


Main Page:
Expand|Select|Wrap|Line Numbers
  1. <head> 
  2.  
  3. <style type="text/css"> 
  4. div { 
  5. color: white; 
  6. display: none; 
  7. </style> 
  8.  
  9. <script language="JavaScript"> 
  10. function setVisibility(id, visibility) { 
  11. document.getElementById(id).style.display = visibility; 
  12. </script> 
  13.  
  14. </head> 
  15.  /* more page data */ 
  16.  
  17. // database query to show messages withought the thread 
  18. $result=mssql_query("SELECT * FROM Message_Board WHERE $searchby LIKE '%$search2%'  
  19. AND thread_number=0 
  20. ORDER BY TStamp DESC"); 
  21.  
  22. // loop to display message without thread 
  23. $i=0; 
  24. while ($i < $num) { 
  25.  
  26. $First_Name=mssql_result($result,$i,"First_Name"); 
  27. $Category=mssql_result($result,$i,"Category"); 
  28. $TStamp=mssql_result($result,$i,"TStamp"); 
  29. $msg=nl2br(mssql_result($result,$i,"msg")); 
  30. $id=mssql_result($result,$i,"id"); 
  31. $thread_number=mssql_result($result,$i,"thread_number"); 
  32. $thread_id=mssql_result($result,$i,"thread_id"); 
  33.  
  34. ?> 
  35.  
  36. <? echo $msg; ?> 
  37. <br> 
  38. <input type=button name=type value='Show Layer' onclick="setVisibility('sub<? echo $id; ?>', 'inline');";><input type=button name=type value='Hide Layer' onclick="setVisibility('sub<? echo $id; ?>', 'none');";>  
  39.  
  40. <div id="sub<? echo $id; ?>"><? include('threadtest.php'); ?></div> 
  41. <? 
  42.  
  43. $i++; 
  44.  
  45.  
  46. mssql_close(); 
  47. ?> 
  48.  
  49.  

threadtest.php:
Expand|Select|Wrap|Line Numbers
  1. // database query 
  2.  
  3. // renamed loop variables so as not to get confused with index.php
  4.  
  5. $result2=mssql_query("SELECT * FROM Message_Board 
  6. WHERE thread_id=$thread_id
  7. AND thread_number != 0
  8. ORDER BY TStamp ASC");
  9.  
  10. // loop to display threaded messages for the message with "thread_id" 
  11. $num2=mssql_num_rows($result2);
  12.  
  13. $i2=0;
  14. while ($i2 < $num2) {
  15.  
  16. // removed unnecessary variables
  17.  
  18. $First_Name=mssql_result($result2,$i2,"First_Name");
  19. // $Category=mssql_result($result,$i,"Category");
  20. $TStamp=mssql_result($result2,$i2,"TStamp");
  21. $msg=nl2br(mssql_result($result2,$i2,"msg"));
  22. // $id=mssql_result($result,$i,"id");
  23. // $thread_number=mssql_result($result,$i,"thread_number");
  24. // $thread_id=mssql_result($result,$i,"thread_id");
  25.  
  26. ?>
  27.  
  28.     <hr width=50%>
  29.         <? echo $msg; ?><br><font size=1><tt><? echo $First_Name; ?> at <? echo $TStamp; ?></tt></font> 
  30.  
  31. <?
  32.  
  33. $i2++;
  34.  
  35. }
  36.  
  37. ?>
  38.  
  39. // removed line - shouldn't close database yet
  40. // mssql_close(); 
  41.  
Oct 5 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: michaaal | last post by:
I have two folders in my website... Folder1 (this is where my #include file is, this is where the style.css is) --Folder2 (Folder2 is inside of Folder1) Folder2 contains a file that has...
6
by: atv | last post by:
Alright, i have some questions concerning include files en global variables.I hope someone is willing to answer these. 1).Why is it that if i define a global variable in a file, say main.c, and...
3
by: Dan Trowbridge | last post by:
Hi everyone, In my attempt to port code from VS 6.0 to VS.NET I had some code break along the way, mostly due to not adhereing closely to the C++ standard. This may be another instance but I...
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only...
7
by: pauldepstein | last post by:
#include <iostream> using namespace std; int main() { extern "C" int f(int, int);
14
by: tbird2340 | last post by:
I want to write an if / then statement and have tried using this: var MyVarMailto; if (Request.Form("LoanRequest") == "Under $250,000") { if (Request.Form("Organization") == "1") { MyVarMailto...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
9
by: weidongtom | last post by:
Hi, I've written the code that follows, and I use the function add_word(), it seems to work fine *before* increase_arrays() is called that uses realloc() to allocate more memory to words. But...
3
by: Stephen Torri | last post by:
Below is a class that is suppose to represent a segment of memory or a contents of a binary image (e.g. ELF executable). I have started to read Modern C++ Design and thought the best way to ensure...
4
by: Paul David Buchan | last post by:
Hello, I'm attempting to write a program to read in database files (.dbf). When I do it all as a single procedure in main, everything works. However, what I really want, is to pass the database...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.