Jump to content

doddsey_65

Members
  • Posts

    902
  • Joined

  • Last visited

  • Days Won

    9

Posts posted by doddsey_65

  1. I am creating a sticky topic feature for my forum and dont know how to keep

    all topics marked sticky at the top of the list generated by the while loop. Any one have any ideas?

    They are ordered by the post date column.

     

    Here is the query:

     

    $posts_info_query = $db->query("SELECT 
    					p.post_id,
    					p.topic_id,
    					p.forum_id,
    					p.post_poster,
    					p.post_subject,
    					p.post_content,
    					p.post_time,
    					p.post_edit_by,
    					p.post_edit_date,
    					p.post_edit_num,
    					p.post_approved,
    					p.post_quoting,
    					m.user_id,
    					m.user_username,
    					m.user_group,
    					m.user_regdate,
    					m.user_birthday,
    					m.user_online,
    					m.user_sex,
    					m.user_location,
    					m.user_show_sex,
    					m.user_show_location,
    					m.user_show_status,
    					m.user_avatar,
    					m.user_sig,
    					m.user_posts
    
    					FROM ".DB_PREFIX."posts as p
    
    					LEFT JOIN ".DB_PREFIX."members as m
    					ON p.post_poster = m.user_username
    
    					WHERE p.topic_id = '$topic_id' 
    
    					ORDER BY p.post_time ASC
    
    					LIMIT $start, $limit")
    
    					or trigger_error("SQL", E_USER_ERROR);
    

     

    Thanks

  2. while ($topic_info = mysql_fetch_object($topic_info_query)) 
    	{
    $thread_topic_id = $topic_info->thread_topic_id;
    	?>
    <script type="text/javascript">
    var defaultMenuWidth="150px" //set default menu width.
    
    var linkset=new Array()
    //SPECIFY MENU SETS AND THEIR LINKS. FOLLOW SYNTAX LAID OUT
    
    linkset[0]='<a href="index.php?forum=<?php echo $forum_id; ?>&topic=<?php echo $thread_topic_id; ?>">View Topic</a>'
    linkset[0]+='<a href="">View Newest Post</a>'
    linkset[0]+='<a href="">Subscribe</a>'
    
    ////No need to edit beyond here
    
    var ie5=document.all && !window.opera
    var ns6=document.getElementById
    
    if (ie5||ns6)
    document.write('<div id="popitmenu" onMouseover="clearhidemenu();" onMouseout="dynamichide(event)"></div>')
    
    function iecompattest(){
    return (document.compatMode && document.compatMode.indexOf("CSS")!=-1)? document.documentElement : document.body
    }
    function showmenu(e, which, optWidth){
    if (!document.all&&!document.getElementById)
    return
    clearhidemenu()
    menuobj=ie5? document.all.popitmenu : document.getElementById("popitmenu")
    menuobj.innerHTML=which
    menuobj.style.width=(typeof optWidth!="undefined")? optWidth : defaultMenuWidth
    menuobj.contentwidth=menuobj.offsetWidth
    menuobj.contentheight=menuobj.offsetHeight
    eventX=ie5? event.clientX : e.clientX
    eventY=ie5? event.clientY : e.clientY
    //Find out how close the mouse is to the corner of the window
    var rightedge=ie5? iecompattest().clientWidth-eventX : window.innerWidth-eventX
    var bottomedge=ie5? iecompattest().clientHeight-eventY : window.innerHeight-eventY
    //if the horizontal distance isn't enough to accomodate the width of the context menu
    if (rightedge<menuobj.contentwidth)
    //move the horizontal position of the menu to the left by it's width
    menuobj.style.left=ie5? iecompattest().scrollLeft+eventX-menuobj.contentwidth+"px" : window.pageXOffset+eventX-menuobj.contentwidth+"px"
    else
    //position the horizontal position of the menu where the mouse was clicked
    menuobj.style.left=ie5? iecompattest().scrollLeft+eventX+"px" : window.pageXOffset+eventX+"px"
    //same concept with the vertical position
    if (bottomedge<menuobj.contentheight)
    menuobj.style.top=ie5? iecompattest().scrollTop+eventY-menuobj.contentheight+"px" : window.pageYOffset+eventY-menuobj.contentheight+"px"
    else
    menuobj.style.top=ie5? iecompattest().scrollTop+event.clientY+"px" : window.pageYOffset+eventY+"px"
    menuobj.style.visibility="visible"
    return false
    }
    
    function contains_ns6(a, b) {
    //Determines if 1 element in contained in another- by Brainjar.com
    while (b.parentNode)
    if ((b = b.parentNode) == a)
    return true;
    return false;
    }
    
    function hidemenu(){
    if (window.menuobj)
    menuobj.style.visibility="hidden"
    }
    
    function dynamichide(e){
    if (ie5&&!menuobj.contains(e.toElement))
    hidemenu()
    else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
    hidemenu()
    }
    
    function delayhidemenu(){
    delayhide=setTimeout("hidemenu()",100)
    }
    
    function clearhidemenu(){
    if (window.delayhide)
    clearTimeout(delayhide)
    }
    
    if (ie5||ns6)
    document.onclick=hidemenu
    
    </script>
    
    <?php
    	$topic_time_posted = date('F j, Y, g:i a', strtotime($topic_info->topic_time_posted));
    	$topic_url_name = $topic_info->topic_name;
    	$topic_url_name = str_replace(' ', '_', $topic_url_name);
    	echo "<div class=\"forum_row\">";
    	echo "<div class=\"icon\"><img src=\"images/default_icon.png\" alt=\"thread\" /></div>";
    	echo "<div class=\"icon2\"><img src=\"images/topic_icon.png\" alt=\"thread\" /></div>";
    	echo "<a href=\"index.php?forum={$forum_id}&topic={$topic_info->thread_topic_id}\" onMouseover=\"showmenu(event,linkset[0])\" onMouseout=\"delayhidemenu()\">";

     

    that is the code for starting the while loop and is shown up until the part where i use the javascript in the html.

  3. function logout ()
    {
    	//session must be started before anything
    	session_start ();
    
    	//if we have a valid session
    	if ( $_SESSION['logged_in'] == TRUE )
    	{	
    		//unset the sessions (all of them - array given)
    		unset ( $_SESSION ); 
    		//destroy what's left
    		session_destroy (); 
    	}
    
    	//It is safest to set the cookies with a date that has already expired.
    	if ( isset ( $_COOKIE['cookie_id'] ) && isset ( $_COOKIE['authenticate'] ) ) {
    		/**
    		 * uncomment the following line if you wish to remove all cookies 
    		 * (don't forget to comment ore delete the following 2 lines if you decide to use clear_cookies)
    		 */
    		//clear_cookies ();
    		setcookie ( "cookie_id", '', time() - KEEP_LOGGED_IN_FOR, COOKIE_PATH );
    		setcookie ( "authenticate", '', time() - KEEP_LOGGED_IN_FOR, COOKIE_PATH );
    	}
    
    //=========================================================
    //ADD YOUR QUERY HERE BEFORE THEY ARE REDIRECTED TO YOUR LOGOUT PAGE.
    //=========================================================
    
    	//redirect the user to the default "logout" page
    	header ( "Location: " . REDIRECT_ON_LOGOUT );
    }
    

  4. I have a problem where i am including javascript in a while loop but the id for the link always stays the same.

     

    start while loop.....
    $thread_topic_id = $topic_info->thread_topic_id;
    <script type="text/javascript">
    
    link[0] = '<a href="index.php?forum=<?php echo $forum_id; ?>&topic=<?php echo $thread_topic_id; ?>">View Topic</a>'
    
    </script>
    
    

     

    the $thread_topic_id variable is always the last record to be displayed. I have 5 records pulled. how would i get it to display the correct id?

  5. Trying to make it simpler:

     

    Basically i could create three extra database tables for child forums, child topics and child posts. But i dont want this. It is alot more work and it can get very confusing. What i want is something like an extra column of two in the forum table. Like child_id and forum type.  Where child id stays at 0 if its not a child and forum type is 'f'. But if it is a child then child id is the id and forum type is 'c'.

     

    Then in the code which displays the topics within the forum i need to display all of the topics but i also need to display the child boards within that forum. So something like:

     

     

    if ($forum_type == 'c') 
    {
    loop through the records for all 
    child boards with the forum id of the forum
    }

     

     

    it sounds simple enough but im struggling, especially when i have to work it into my existing code. attached is a copy of topics.php which displays all the topics once someone clicks on a forum.

     

    I also added an sql dump of the tables needed to make this page work incase you want to test it.

     

     

     

    [attachment deleted by admin]

  6. I wil ltry and explain this the best i can so please bare with me if it doesnt come out right first time lol.

     

    I am making a forum and as we all know forums have subforums or child boards that are within the forums themselves. Like php freaks has the forum php coding and then a sub forum within it for php regex.

     

    Im having trouble coding this though. Anyone have any tips on code and database structure that could help?

    I was thinking of making three new database tables for child forums, child topics and child posts but im sure there is an easier way. something like a column within the main forum table which defines wether the forum is a child or not. But then how would i link this child forum with the forum that its supposed to be in. Any advice is greatly appreciated. Thanks.

     

  7. Is this what you are after? If correct you just need to put the 'match' into the JavaScript

     

    $pattern='/<a href="([^\"]*)">/';
    $replace='<a href="\\1" onclick="return confirm(\'You are being redirected to \\1. Proceed?\')">';
    $message_content = preg_replace($pattern, $replace, $message_content);

     

    thats what i am after and i did try it but the popup just echos \\1 it doesnt print the actual url

  8. I am not sure if I understand you right, but one thing I thought might be of your interest.

    I am pretty sure your syntax is not right:

    <a href="whatever.com" onclick = "if (! confirm("Continue?")) return false;">

    maybe try:

     <a href="whatever.com" onclick="return confirm('continue?')">lalala</a>

     

    To add php and using the script that was given i think you can just add it like this:

     

    $pattern='/<a href="([^\"]*)">/';
            $replace='<a href="\\1" onclick = "if (! confirm(\''.$YOUR_VARIABLE_INSIDE_HERE.'\')) return false;">link</a>';
            $message_content = preg_replace($pattern, $replace, $message_content);
    

    But again i am pretty sure that on-click part is not correct. If not try:

     

    $pattern='/<a href="([^\"]*)">/';
            $replace='<a href="\\1" onclick="return confirm(\''.$YOUR_VARIABLE_INSIDE_HERE.'\'));">link</a>';
            $message_content = preg_replace($pattern, $replace, $message_content);
    

     

    -edit: I added:  link</a>  other wise you have nothing to click on

     

    What I mean is $YOUR_VARIABLE_INSIDE_HERE needs to be the url they are clicking. The href.

     

    Eg/

     

    $replace='<a href="\\1" onclick="return confirm(\'You are being redirected to '.$YOUR_VARIABLE_INSIDE_HERE.'\'));">link</a>';

  9. Im having trouble deleting the selected checkboxes in my form. I have tried several options out there but none seem to work. here is the code i have which generates the checkboxes. i am alos using jquery to select all.

     

    <form name="checkboxes" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

     

    This is within the while loop:

    echo "<input value=\"{$messages_info->message_id}\" style=\"float:left;\" type=\"checkbox\" name=\"checkbox\" />";

     

    <a href="<?php echo $site_root; ?>/user_center.php?user=<?php echo $_GET['user']; ?>&do=messages&action=del_marked">
     Delete Marked</a> </span>

     

    Anyone have any ideas? Thanks

  10. basically what i am trying to do is replace the

     

    <a href="whatever.com"> 

     

    with

     

    <a href="whatever.com" onclick = "if (! confirm("Continue?")) return false;">

     

    so that when the user clicks the url in a message the box pops up first then redirects them to the url if they click confirm. However i am getting the following error:

     

    Warning: preg_replace() [function.preg-replace]: Compilation failed: reference to non-existent subpattern at offset 11

     

    here is the code i used.

     

    $message_content = $content_info['message_content'];
    $pattern='<a href="\\1">';
    $replace='<a href="\\1" onclick = "if (! confirm("Continue?")) return false;">';
    $message_content = preg_replace($pattern, $replace, $message_content);
    echo $message_content;

     

    Anyone know where i went wrong?

  11. thanks twitch. I did in the end use jquery. I did find some scripts that did it for me but jquery was the better choice. I do have an offtopic question regarding your code though.

     

    at the beginning you add:

     

    $detail=$_POST["id"];
    $detail = mysql_real_escape_string($detail);
    

     

    but i would use:

     

    $detail = mysql_real_escape_string($_POST["id"]);
    

     

    is there any difference? I dont think there would be but you never know.

     

    Also where you use:

     

    $query = "SELECT * FROM your_table WHERE id = '$detail'";
    $qry_result = mysql_query($query) or die(mysql_error());
    while($row = mysql_fetch_array($qry_result)){

     

    i would use:

     

    $query = mysql_query("SELECT * FROM your_table WHERE id = '$detail'")
    or die(mysql_error());
    while($row = mysql_fetch_array($query )){

     

    Like i said just interested to know if there is any difference.

     

    Thanks

  12. i am making a private messaging system like hotmails where the message list appears on the left. Then when you click on one of them the box on the right loads the email. The problem is i dont really know how to go about it. Anyone have any pointers?

  13. Okay so I have 2 forums, which each have 1 topic and atleast 1 post within those topics

    lets call them forum 1 and forum 2 where the number is the id in the database under forum_id

     

    they are in a parent with a parent id of 1 so the database layout is

     

    forum_id - forum_parent_id
         1                     1
         2                     1
    

     

    but i want to add a child board/subforum to forum_id 1. So i added two more columns

    forum_type

    f for forum or c for child board

     

    forum_connection

    the forum id this child is in(if its a child)

     

    but how would i get forum child with a forum_connection of 1 to appear under the forum with an id of one?

     

    here is my query:

     

    $query = $db->query("SELECT
                  f.forum_id, f.forum_name, f.forum_description, 
    		  f.forum_topics, f.forum_posts, f.forum_type, forum_connection, 
                  f.forum_last_poster, f.forum_last_post_time, f.forum_last_post,
                  p.parent_id, p.parent_name, 
                  m.user_id, m.user_username, m.user_group,
                  t.thread_topic_id, t.topic_name
    		  
    		FROM forum_parents as p
    
    		JOIN forum_forums as f
    			ON f.parent_id = p.parent_id
    
    		LEFT JOIN forum_members as m
    			ON f.forum_last_poster = m.user_username
    
    		LEFT JOIN forum_topics as t
    			ON t.topic_name = f.forum_last_post
    		WHERE f.forum_type = 'f'
    		ORDER BY p.parent_id, f.forum_id ASC")
    		or trigger_error("SQL", E_USER_ERROR);

     

    hopefully someone will understand this lol

  14. thanks for the advice, i got it working before i read your post anti-moronic but a slight issue.

    when the post was made less than 30 minutes ago it shows how many minutes ago it was made.

    but it has a leading 0 eg 05 minutes ago. how would i replace that 0 or remove it?

     

    my code:

     

     $last_post = strtotime($topic_info->topic_last_post_time);
    $today = strtotime('NOW');
    $last_post_gap = $today - $last_post;
    $last_post_gap = date('i',($last_post_gap));
    $min = strtotime('- 1 MINUTE');
    $normal = strtotime('- 30 MINUTES');
    
    
    if ($last_post <= $normal)
    {
    echo '<p class="last_post_date">'.date('F j, Y g:i a', strtotime($topic_info->topic_last_post_time));
    } 
    
    elseif ($last_post >= $min)
    {
    echo '<p class="last_post_date">Less Than 1 Minute Ago';
    }
    
    else {
    
    	echo "<p class=\"last_post_date\">{$last_post_gap} minutes ago";
    }

  15. function redirect( $url ){
    if (! headers_sent( ) ){
    
    header( "Location: ".$url );
    exit( 0 );
    }
    echo "<script language=Javascript>document.location.href='".$url."';</script>";
    exit( 0 );
    } 
    
    $test = $_POST['test'];
    $page_vars = $_GET['page_vars']; //etc
    
    if($test){
    redirect('http://site.com/index.php?forum=1&topic=1&page=2&post=236#p236'); //redirect to any url
    }

     

    im no expert but from the looks of your code you are assuming that i will know the page number. But thats my problem because when its inserted into the database i wont know which page number it is on to redirect to. I could use several if statements but surely theres a better way.

  16. I am using a header redirect after a user makes a post which goes to their post.

     

    example they made a post which has an id of 236, then the url redirect would be

     

    index.php?forum=1&topic=1&post=236#p236

     

    i have the <a name> set up on each post and it works fine until the post is on a different page.

    the url should be:

     

    index.php?forum=1&topic=1&page=2&post=236#p236

     

    but how would i be able to tell the header redirect which page to go to. I was thinking if statements like:

     

    if ($number_of_results >=10) { $page = 2; }

     

    but that would involve alot of if statements with no way of knowing how many pages the topic could have.

     

    Is there an easier way?

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