Jump to content

Andy11548

Members
  • Posts

    163
  • Joined

  • Last visited

Posts posted by Andy11548

  1. Hello,

     

    I've got an overlay on my website which loads up when a button is clicked. Once the button it clicked, it parses a PHP file into a div which generates the content to be shown in the div. However, I can't seem to get the jQuery to work on buttons which are imported unless I call another Javascript file while populating the div. Does anyone know how I can get this so that it will work weather the buttons are there as the page is loaded or after extra content is brought in?

     

    I'm presuming it's due to the 

    $(document).ready(function(){
    
    });
    

    Current jQuery

    $(document).ready(function() {
    	$('.CloseOverlay').click(function() {
    		$('.OverlayContainer').hide();
    	});
    	$('.Approve').click(function() {
    		var UserID = $(this).val();
    		var Status = "GetData";
    		$.post('/Admin/Users/Verified/approveUser.php', { UserID: UserID, Status: Status }, function(data) {
    			$('.OverlayWrapper').html(data);
    		});
    		$('.OverlayContainer').show();
    	});
    });
    
    

    P.S - I'm pretty shocking at jQuery/Javascript!

     

     

     

    Thanks in advance,

    Andy

  2. I am working on this project with someone else they have done the database side of things with their team -  I am just working with what I am given.

     

    Thanks for this will give it a go.

     

    What would an elegant way be? In theory; if you don't want to write the code - its fine I would just like the best way to achieve this.

     

    The most elegant way would be to have multiple tables in the database. Unfortunately, you will find it hard to find an elegant way of writing the code with the database structure you've got. It's probably not the best way in the example I've put, but it isn't going to get any better really without the multiple tables...

     

    Also, in the first query, you may want to put ORDER BY `company` ASC in there, otherwise it won't work 100% unless all of the specs/company names are directly under each other in the database.

  3. The table has been created - I don't have control over this unfortunatley  - can I not achieve the same thing with one table?

     

    What do you mean you don't have control over this? Surely you have control over your MySQL Databases?

     

    This is a quick piece of code that works how you want it. It's far from elegant though...

    <?php
    $Connect = mysql_connect("HOST", "USER", "PASS") or die(mysql_error());
    mysql_select_db("test") or die(mysql_error());
    
    $LastCompany = '';
    
    $Query = mysql_query("SELECT * FROM `company`") or die(mysql_error());
    
    while($Fetch = mysql_fetch_assoc($Query)) {
    	if($LastCompany !== $Fetch['Company']) {
    	echo '<ul>';
    		echo '<li>' . $Fetch['Company'];
    			echo '<ul>';
    			$Query2 = mysql_query("SELECT * FROM `company` WHERE `Company`='" . $Fetch['Company'] . "'") or die(mysql_error());
    			while($Fetch2 = mysql_fetch_assoc($Query2)) {
    				echo '<li>' . $Fetch2['Specs'] . '</li>';
    			}
    			echo '</ul>';
    		echo '</li>';
    	echo '</ul>';
    	$LastCompany = $Fetch['Company'];
    	}
    }
    
    ?>
    
  4. From a personal perspective, it may be better in this case to have two different tables to store the data:

     

    Example:

     

    tbl.company:

     

    company_id

    company_name

     

    tbl.specs:

     

    spec_id

    company_id

    spec

     

    Once it's set up like this, it should be easier to display *ALL* the specs for Company1 by selecting all the entries in tbl.specs by filtering only by the company ID.

     

    The code below is an example and doesn't use best practices. You should be using "JOIN" for these sort of queries, but as I don't understand them well and it takes me a little while to write it, I'll show you the bad practice way which does work...

    <?php
    $CompanyQuery = mysql_query("SELECT * FROM `company`") or die(mysql_error());
    
    while($FetchCompany = mysql_fetch_assoc($CompanyQuery)) {
    $SpecsQuery = mysql_query("SELECT * FROM `specs` WHERE `company_id`='" . $FetchCompany['company_id'] . "'") or die(mysql_error());
    echo '<ul>';
         echo '<li>' . $FetchCompany['CompanyName'];
              echo '<ul>';
              while($FetchSpec = mysql_fetch_assoc($SpecsQuery)) {
                   echo '<li>' . $FetchSpec['spec'] . '</li>';
              }
              echo '</ul>';
         echo '</li>';
    echo '</ul>';
    }
    ?>
    

    Something like that would work (with a few tweaks), but as I said, this is NOT the best way to do it by any means.

  5. Hello All,

     

    If I had a table with results in from a Database, how would I go around moving a row up/down and refresh the data in the row?

     

    Would the best method be to have a seperate column in the database like 'RowOrder' and then once the arrow is pressed, swap it with the corresponding value and refresh the page?

     

     

    Thanks in advance,

    Andy

  6. Hello,

     

    I'm looking to build my own Shopping Cart (Just to have a mess around), and I'm wondering what the best way of Adding/Removing items to the cart would be?

     

    Any help/assistance would be grateful.

     

     

     

    Kind Regards,

    Andy

  7. Hello,

     

    I could do with some help joining this query in to another query. I'm completely and utterly blagged on what I'm doing now.

     

    I need this query:

    mysql_query("SELECT * FROM `users` WHERE `username`='".$_SESSION[username]."'");
    

     

    placed into this one:

    mysql_query("
    	   SELECT
    	   f1.cat_name as CatName,
    	   f1.cat_id as CatID,
    	   f2.cat_id as SubCatID,
    	   f2.sub_id as SubID,
    	   f2.sub_name as SubName,
    	   f2.sub_desc as SubDesc,
    	   f3.topic_id as TopicID,
    	   f3.user_id as UserTopicID,
    	   f3.topic_name as TopicName,
    	   f3.topic_message as TopicMessage,
    	   f4.user_id as UserReplyID,
    	   f5.username as Username,
    	   
    	   (SELECT COUNT(*) FROM forum_topics as f3 WHERE f3.sub_id = f2.sub_id) as TopicAMT,
    	   (SELECT COUNT(*) FROM forum_replies as f4 WHERE f4.topic_id = f3.topic_id) as ReplyAMT
    	   
    	   FROM `forum_cats` as f1
    	   		LEFT JOIN `forum_sub` as f2
    	   			ON f1.cat_id = f2.cat_id
    	   		LEFT JOIN `forum_topics` as f3
    	   			ON f2.sub_id = f3.sub_id
    	   		LEFT JOIN `forum_replies` as f4
    	   			ON f3.topic_id = f4.topic_id
    	   		LEFT JOIN `users` as f5
    	   			ON f4.user_id = f5.user_id
    	   			
    	 WHERE f1.cat_id='$cat' $getSub $getTopic
    
    	 ORDER BY f2.sub_id ASC, f4.reply_id DESC
    	 ");
    

     

    Help would be appreciated.

     

    Thanks,

    Andy.

  8. Right, I'm running into a random problem.

     

    When I press the Bold Button it works fine, it replaces the string highlighted with '' tags around it. However, when I press the Italic/Underline button etc it doesn't work :/.

     

    
    var text = "";
    
    function ShowSelection() {
      var textComponent = document.getElementById('topicMessage');
      var selectedText;
      // IE version
      if (document.selection != undefined)
      {
        textComponent.focus();
        var sel = document.selection.createRange();
        selectedText = sel.text;
      }
      // Mozilla version
      else if (textComponent.selectionStart != undefined)
      {
        var startPos = textComponent.selectionStart;
        var endPos = textComponent.selectionEnd;
        selectedText = textComponent.value.substring(startPos, endPos)
      }
      
      text = selectedText;
    }
    
    
    $(document).ready(function() {
    $('#bbcode_bold').click(function() { //BBCODE BOLD
    	var textarea = $('textarea').val();
    	textarea = textarea.replace(text, '[b]' + text + '[/b]');
    
    	$('textarea').val(textarea);
    });
    $('#bbcode_italic').click(function() { //BBCODE ITALIC
    	var textarea = $('textarea').val();
    	textarea = textarea.replace(text, '[i]' + text + '[/i]');
    
    	$('textarea').val(textarea);
    });
    $('#bbcode_underline').click(function() { //BBCODE UNDERLINE
    	var textarea = $('textarea').val();
    	textarea = textarea.replace(text, '[u]' + text + '[/u]');
    
    	$('textarea').val(textarea);
    });
    $('#bbcode_strikethrough').click(function() { //BBCODE STRIKETHROUGH
    	var textarea = $('textarea').val();
    	textarea = textarea.replace(text, '[strike]' + text + '[/strike]');
    
    	$('textarea').val(textarea);
    });
    });
    

  9. Hello, this doesn't appear to work with jQuery, I think it's Javascript. Could someone please convert this into jQuery.

     

    function ShowSelection()
    {
      var textComponent = document.getElementById('topicMessage');
      var selectedText;
      // IE version
      if (document.selection != undefined)
      {
        textComponent.focus();
        var sel = document.selection.createRange();
        selectedText = sel.text;
      }
      // Mozilla version
      else if (textComponent.selectionStart != undefined)
      {
        var startPos = textComponent.selectionStart;
        var endPos = textComponent.selectionEnd;
        selectedText = textComponent.value.substring(startPos, endPos)
      }
      alert("You selected: " + selectedText);
    }
    

     

    Thanks,

    Andy.

  10. Nope, I solved what I wanted, however, you've managed to read my mind on what I need help with next.

     

    How would I make it get the highlighted text from the textarea and output it into a variable?

     

    I've done quite a bit of research on this and have not found a solution to this yet.

     

    If you could help me with this it would be greatly appreciated.

     

     

    Thanks,

    Andy.

  11. Hello,

     

    I'm trying to create a button that will put text into a <textarea>. I've got this half working, so when I press the Button it puts in

     

    <textarea>
    [b][/b]
    </textarea>
    

     

    However, if I delete that or type something else, when I press the button again, it does nothing.

     

    Could anyone help?

     

    $('#bbcode_bold').click(function() {
    	$('#topicMessage').append('[b][/b]');
    });
    

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