Jump to content

Destramic

Members
  • Posts

    960
  • Joined

  • Last visited

Posts posted by Destramic

  1. hey guys im need to be able to see if a string contains a certian character  :1 or :2 etc...it will be a colon then a number i know it needs to be done by using eregi but im not sure on how to do it if anyone can help please...thanks alot

  2. hey guys i have made a json script but i have data from mysql database that i need to convert to json...does anyone have a good tutorial/class/function on how this could be done correctley please

     

    thanks destramic

  3. hey guys im trying to make a select all checkboxes (grouped) script...my problem im having is that

     

    var group_checked_count = $('group:checked').length;
    var group_count         = $(group).length;
    

     

    isnt returning the correct value  as they both are returning 0

    var group_checked_count should return 1...and

    var group_count should return 4

     

    it seems im doing something wrong...if anyone could point out what that is please

     

    <!DOCTYPE html>
    <html>
    <head>
      <script type="text/javascript" src="/ajax/jquery/libary/jquery.js"></script>
      <script>	
    function toggleCheckboxes(group, element) {
    
    group   = $('input[name='+ group +']');
    element = $('#'+ element +'');
    
    var group_checked_count = $('group:checked').length;
    var group_count         = $(group).length;
    
    if ($(element).text() == '')
    {
    	if ($(group_count) / $(group_checked_count) < 1) {
    		$(element).text() = 'Select All';
    	}
    	else{
    		$(element).text() = 'Deselect All';
    	}
    }
    }
    
    toggleCheckboxes('sports', 'selectbutton');
    </script>
    </head>
    <body>
    <form>
    <span id="selectbutton"></span>
    
    Soccer: <input type="checkbox" name="sports" value="soccer"  /><br />
    Football: <input type="checkbox" name="sports" value="football" checked /><br />
    Baseball: <input type="checkbox" name="sports" value="baseball"  /><br />
    Basketball: <input type="checkbox" name="sports" value="basketball"  />
    </form>
    
    </body>
    </html>
    

  4. is it good practice to include   where nessesary or just simple " " just leave a space...the reason i ask this is because i know some browsers render this differently and as stupid as the question may be im wondering if to us   or just start using a " " space?

     

    thanks destramic

  5. hello...i have a while loop which works fine but i want to count and every 5th loop have a break (<br />)....im just wondering on the best way of doing is...i have on method...but i'm thinking there may be a better way of doing it than the way i am?

     

    <?php
    $i = 0;
    while ($games_row = mysql_fetch_array($games_result, MYSQL_BOTH))
    {
    	if ($i =5 )
                   {
                         echo "<br />";
                        $i = 0;
                   }
    
    	printf ("<option value=\"\">%s</option>\n", $game_name);
                   $i++;
    }
    ?>
    

     

    thanks

  6. dj kat....all code posted were from json.php...just updat ed versions...although ive now got my script working as i want it...and as for the ob_clean, ob_start and die....without these functions my script wouldnt work....by all means have a look

     

    <?php 
    ob_start();
    ?>
    <!DOCTYPE html>
    <html>
    <head>
      <script type="text/javascript" src="/ajax/jquery/libary/jquery.js"></script>
    </head>
    <body>
    <?php
    if ($_POST['game'] == 1)
    {
    
    $array = array(
       'game_type' => array(
            array('value' => 1, 'text' => 'CTF'), 
            array('value' => 1, 'text' => 'TDM'), 
        ),
        'division' => array(
            array('value' => 1, 'text' => 'Division 1'), 
            array('value' => 1, 'text' => 'Division 2')
        ));
        
    ob_clean();
    header('Content-Type: application/json');
    die(json_encode($array));
    }
    elseif ($_POST['game'] == 2)
    {
    
    $array = array(
       'game_type' => array(
            array('value' => 1, 'text' => 'TKOTH'), 
            array('value' => 1, 'text' => 'DM'), 
        ),
        'division' => array(
            array('value' => 1, 'text' => 'Division 3'), 
            array('value' => 1, 'text' => 'Division 4')
        ));
    
    ob_clean();
    header('Content-Type: application/json');
    die(json_encode($array));
    }
    ?>
    <form>
    <script>	
    $(document).ready(function(){
    
    var game_type_value = $('#game_type').text();
    var division_value  = $('#division').text();
    
    $("#game").change(function() {
    
    	if ($('#game option:selected').text() == "")
        	{
        		$('#game_type').empty();
        		$('#division').empty();
       		 	$('#game_type').text(game_type_value);
          		$('#division').text(division_value);
        	}
        	
    	var post_string = "game=" + $(this).val();
    
    	$.ajax({
    		  type: 'POST',
    		  data: post_string,
    		  cache: false,
    		  dataType: 'json',
    		  url: 'json.php',
    		  timeout: '2000',
    	       error: function(data) { 
    	       		console.log(data);
    	        },
    		    success: function(data) {
    			    
    	        	$.each(data, function(prop, obj){
    
    	            	switch(prop)
    		        	{
    		        		case 'game_type':
    		        			$('#game_type').empty();
    		        			$.each(obj, function(i, val){ 
    		        			var game_type_row =$('<label>' + val.text +'</label><input name=\"\" id=\"\" type=\"checkbox\" value=\"'+ val.value +'\" />');
    		      				$(game_type_row).appendTo('#game_type');
    			        	    });
    		        		break;
    		        		
    		        		case 'division':
    		        			$('#division').empty();
    		        			$.each(obj, function(i, val){
    		        			var division_row = $('<label>' + val.text +'</label><input name=\"\" id=\"\" type=\"checkbox\" value=\"'+ val.value +'\" />');
    			        		$(division_row).appendTo('#division');
    			        		});
    		        		break;
    		        	}			  
    	           });
    		   }
          });
    });
    });
    
    </script>
    <select name="game" id="game">
    <option value=""></option>
    <option value="1">Counter Strike</option>
    <option value="2">COD</option>
    </select>
    
    <div id="game_type">
    please select a game...</div>
    <div id="division">
    please select a game...</div>
    </form>
    
    </body>
    </html>
    

     

    but there is one question i need to have two clauses in the line $("#game").change(function() {

     

    something like $("#game").change || $("#game").text(function() {

     

    but im not sure how this is done...as im still leaning...if anyknow how this is possible please let me know....thank you

  7. here you go dj kat...i've been working on this for the last couple of days...just having a problem returning the objects in the array...maybe a second pair of eyes could notice the problem...thanks

     

    <?php 
    ob_start();
    ?>
    <!DOCTYPE html>
    <html>
    <head>
      <script type="text/javascript" src="/ajax/jquery/libary/jquery.js"></script>
    </head>
    <body>
    <?php
    if ($_POST['game'] == 1)
    {
    
    $array = array(
       'game_type' => array(
            array('value' => 1, 'text' => 'CTF'), 
            array('value' => 1, 'text' => 'TDM'), 
        ),
        'division' => array(
            array('value' => 1, 'text' => 'Division 1'), 
            array('value' => 1, 'text' => 'Division 2')
        ));
        
    ob_clean();
    header('Content-Type: application/json');
    die(json_encode($array));
    }
    elseif ($_POST['game'] == 2)
    {
    
    $array = array(
       'game_type' => array(
            array('value' => 1, 'text' => 'TKOTH'), 
            array('value' => 1, 'text' => 'DM'), 
        ),
        'division' => array(
            array('value' => 1, 'text' => 'Division 3'), 
            array('value' => 1, 'text' => 'Division 4')
        ));
    
    ob_clean();
    header('Content-Type: application/json');
    die(json_encode($array));
    }
    ?>
    <form>
    <script>	
    $(document).ready(function(){
    $("#game").change(function(){
    
    	var post_string = "game=" + $(this).val();
    
    	$.ajax({
    		  type: 'POST',
    		  data: post_string,
    		  cache: false,
    		  dataType: 'json',
    		  url: 'json.php',
    		  timeout: '2000',
    	       error: function(data) { 
    	       		console.log(data);
    	        },
    		    success: function(data) {
    	        
    	        	$.each(data, function(prop, obj){
    
    	            	switch(prop)
    		        	{
    		        		case 'game_type':
    		        			$.each(obj, function(i, val){ 
    		        				var game_type_row = val.text + '<input name=\"\" id=\"\" type=\"checkbox\" value=\"' + val.value + '\" />\n';
    		        				console.log(game_type_row);
    		        				$(game_type_row).appendTo('#game_type');
    			        			});
    		        		break;
    		        		
    		        		case 'division':
    		        			$.each(obj, function(i, val){
    			        			var division_row = val.text +'<input name=\"\" id=\"\" type=\"checkbox\" value=\"'+ val.value +'\" />\n';
    			        			console.log(division_row);
    			        			$(division_row).appendTo('#division');
    			        		});
    		        			
    		        		break;
    		        	}			  
    	           });
    		   }
          });
    });
    });
    </script>
    <select name="game" id="game">
    <option value=""></option>
    <option value="1">Counter Strike</option>
    <option value="2">COD</option>
    </select>
    
    <div id="game_type">
    please select a game...</div>
    <div id="division">
    please select a game...</div>
    </form>
    
    </body>
    </html>
    

  8. im not sure if this is the right place to post this...but im looking for tutorial on how to make my apache server pubic so peple can view my pages through my ip address...if somene could help that would be great.

     

    thanks

  9. hey guys im having a problem returning the data in the json array...plus when alerting data.value it comes back at 1000+ which is truely incorrect....can anyone explain where i am going wrong please?...thank you

     

    <!DOCTYPE html>
    <html>
    <head>
      <script type="text/javascript" src="/ajax/jquery/libary/jquery.js"></script>
    </head>
    <body>
    <?php 
    $game_type = array();
    $division  = array();
    
    if ($_POST['game'] == 1)
    {
    $game_type[] = array('value' => '1',
    	                 'text' => 'TDM'
    );
    
    $game_type[] = array('value' => '1',
    	                 'text' => 'CTF'
    );
    
        $division[] = array('value' => '1',
    	                 'text' => 'Divison 1'
    );
    }
    elseif ($_POST['game'] == 2)
    {
    $game_type[] = array('value' => '1',
    	                 'text' => 'CTF'
    );
    
        $division[] = array('value' => '1',
    	                 'text' => 'Divison 2'
    );
    }
    
    json_encode($game_type);
    json_encode($division);
    ?>
    <form>
    <script>	
    $(document).ready(function(){
    $("select#game").change(function(){
    
    	var post_string = "game=" + $(this).val();
    
    	$.ajax({
    		  type: 'POST',
    		  data: post_string,
    		  cache: false,
    		  dataType: 'game_type',
    		  url: 'json.php',
    		  timeout: '2000',
    	        error: function() {
    	        	alert("Error has occured");
    	        },
    		  success: function(data) {
    				  
    			       alert(data.length); 
    			       alert(data[1].text);      
    		  }
          });
    });
    });
    
    //$('#game_type').html('<input type=\"checkbox\" value=\"test\" /> TDM'); 
    //$('#division').html('<input type=\"checkbox\" value=\"test\" /> Division 1'); 
    </script>
    <select name="game" id="game">
    <option value=""></option>
    <option value="1">Counter Strike</option>
    <option value="2">COD</option>
    </select>
    
    <div id="game_type">
    </div>
    <div id="division">
    </div>
    <select name="sub_category" id="sub_category">
    <option value="">-- Select First Value --</option>
    </select>
    </form>
    
    </body>
    </html>

  10. im finnal on to something now...but the script im trying to function keeps returning an error on the json "failed to submit"...can anyone tell me why please

     

    <!DOCTYPE html>
    <html>
    <head>
      <script type="text/javascript" src="/ajax/jquery/libary/jquery.js"></script>
    </head>
    <body>
    <?php 
    $game_type = array();
    $division  = array();
    
    if ($_POST['game'] == 1)
    {
    $game_type[] = array('value' => '1',
    	                 'text' => 'TDM'
    );
    
        $division[] = array('value' => '1',
    	                 'text' => 'Divison 1'
    );
    }
    elseif ($_POST['game'] == 2)
    {
    $game_type[] = array('value' => '1',
    	                 'text' => 'CTF'
    );
    
        $division[] = array('value' => '1',
    	                 'text' => 'Divison 2'
    );
    }
    
    json_encode($game_type);
    json_encode($division);
    ?>
    <form>
    <script>	
    $(document).ready(function(){
    $("select#game").change(function(){
    
    	$.ajax({
    		type: 'POST',
            data: 'data',
            dataType: 'json',
            cache: false,
            url: 'json.php',
            timeout: '2000',
            error: function() {
            	alert("Failed to submit");
            },
            success: function(data) { 
            	alert("working!");
    			 }
    	});
    
            //	$('#game_type').html('<input type=\"checkbox\" value=\"test\" /> TDM'); 
            //   $('#division').html('<input type=\"checkbox\" value=\"test\" /> Division 1'); 
    
    });
    });
    
    </script>
    <select name="game" id="game">
    <option value=""></option>
    <option value="1">Counter Strike</option>
    <option value="2">COD</option>
    </select>
    
    <div id="game_type">
    </div>
    <div id="division">
    </div>
    </form>
    
    </body>
    </html>

  11. hey guys im trying to get multiple checkboxes on a line without the label dropping down on another line...if anyone can help please

     

    css

    label { width: 100px; float:left; display: inline;}
    input[type="checkbox"] { padding:6px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; }
    

     

    html

    <label for="Neatherlands">Neatherlands</label> 
    <input type="checkbox" name="neatherlands" id="Neatherlands" value="" />  
    <label for="United Kingdom">United Kingdom</label> 
    <input type="checkbox" name="united kingdom" id="United Kingdom" value="" />  
    

  12. im looking for a script which allows you to selected a certian option on a form select box then a row of list boxes will show underneath depending on what the select box value is....does anyone know of a good link to such a script/site/tutorial

     

    if you dont understand let me know please...thank you

  13. im working on a directory index script and i need to extract filename out of a sting which could look like this

     

    index.php

    news.htm

     

    and just return index or news....without the file format...does anyone know of a tutorial that could help please...thank you

  14. sorry im now having an error...i was firstly just setting $function as strip but when setting it in function argument as below im getting the error:

    Warning: Missing argument 2 for add_strip_slashes_deep()

    strange

    <?php
    function add_strip_slashes_deep($value, $function)
    {
    if (function_exists($function . "slashes"))
    {
    	if (get_magic_quotes_gpc() && 
    	    is_array($value))
    	{
    		$value = array_map("add_strip_slashes_deep", $value);
    	}
    	else if (is_string($value))
    	{
    		$value = call_user_func($function . 'slashes', $value);
    	}
    }
    else
    {
    	echo "An error has occurred.<br />\n";
    }
    
        return $value;	
    }
    
    
    // Example
    $array = array("f\\'oo", "b\\'ar", array("fo\\'o", "b\\'ar"));
    $array = add_strip_slashes_deep($array, "strip");
    
    // Output
    print_r($array);
    ?> 

  15. i'm trying to get strip/add slashes function working but its coming up with an error on this line...but im sure im doing the right thing...does anyone know where im going wrong please or even if this is possible

     

    $function = "add"; // or strip
    $value = {$function}slashes($value);
    

     

    thank you destramic

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