Jump to content

MDanz

Members
  • Posts

    728
  • Joined

  • Last visited

Posts posted by MDanz

  1. the following code doesn't work.  If i change 'textarea[]' to just 'textarea' it works.  But i need textarea in an array.

     

    <SCRIPT LANGUAGE="JavaScript">
    
    function counter(field,cntfield,maxlimit) {
    if (field.value.length > maxlimit) 
    field.value = field.value.substring(0, maxlimit);
    else
    cntfield.value = maxlimit - field.value.length;
    }
    </script>
    
    <form name="submitform">
    
    <textarea name="textarea[]"  cols="30" rows="1"
    onKeyDown="counter(document.submitform.textarea[],document.submitform.charleft,1000)"
    onKeyUp="counter(document.submitform.textarea[],document.submitform.charleft,1000)"></textarea>
    <br>
    <input readonly type="text" name="charleft" size="3" maxlength="4" value="1000">
    characters left
    
    </form>

  2. i have imploded the array '$scope'.  i want to put the results into a multiple where clause.  The problem is how do i implement OR into the WHERE clause?

     

    		$scopetwo = implode("keywords=",$scope);  
    
    
    		$getresults=mysql_query("SELECT * FROM message WHERE '$scopetwo' ORDER BY posted ASC",$this->connect);

  3. i have an array in the loop but it isn't building up with results.  i want it to check if the array exists, if not then create the array. Then in next loop it pushes a new value into the array.  Below isn't working?...

     

    
    while($row=mysql_fetch_assoc($get));
    {
    $key = $row['keyword'];
    
    $scope= $_SESSION['scope'];
    
    
    		if (!is_array($scope)) {
    
    		$scopenew = array($key);
    		$_SESSION['scope'] = $scopenew;
    
                    } else {
    
    		$scopenew = array_push($scope, $key);
    			$_SESSION['scope'] = $scopenew;	
    
    }
    
    
    }
    

  4. ok i realised what is wrong... if i didn't click on the checkbox it isn't added to the array.

     

    <?php 
    
    if(isset($_POST['submit'])) {
    
    print_r($_POST['tags']); 
    
    } else {
    ?>
    
    
    <form action="test16.php" method="post">
    <input type="checkbox" name="tags[]" value="1" />
    <input type="checkbox" name="tags[]" value="2" />
    <input type="checkbox" name="tags[]" value="3" />
    <input type="checkbox" name="tags[]" value="4" />
    <input type="submit" name="submit" value="submit" />
    </form>
    
    <?php   }  ?>

     

    How do i change the code above so it's four values in the array, indicating what i have clicked on and what i haven't.

  5. The only reason I can't think of it not showing anything is that nothing was checked.  It would probably help more to print_r the entire $_POST array and see what's coming through.

     

    Also, put it inside <pre> tags when you print_r, it's much easier to read.

    echo "<pre>" . print_r($_POST) . "</pre>";

    ok i did that and this the result

     

    Array ( [0] => ) 

     

    is it because value is blank?

    <input type='checkbox' name='test[]' value='' />

     

     

     

  6. i have a form with multiple checkboxes, with the same name. so i put them in an array like this.

     

    <input type='checkbox' name='test[]' value='' />
    <input type='checkbox' name='test[]' value='' />
    <input type='checkbox' name='test[]' value='' />
    <input type='checkbox' name='test[]' value='' />

     

    Now when i do print_r($_POST['test']; , it should display an array and if each checkbox has been ticked or not.  it just comes up blank.

     

    Any idea?

  7. onclick isn't working... information should be displayed in the div with id='info'

    echo "<div id='$id' style='display:none;'>$name - $information</div>";
    
    echo "<div class='productcol' onclick='Info($id)'><img src='$image' alt='$name' style='width:95px;height95px;' /></div>";
    
    echo "<div id='info'></div>";
    

     

    function Info(number) {
    
    var information = document.getElementById(number).innerHTML;
    
    document.getElementByID('info').innerHTML = information;
    
    }

  8. This code adds a new textarea when i press the "add" button.  How do i alter the code so it can remove a textarea.

     

    e.g. i added 4 textarea's but i only intended to add 3, how do i delete the 4th textarea?

     

    <div id='newdiv'>
    </div>

     

    <input type='button' onclick='new()' name='add' value='Add' style='font-size:12px;' />

     

     
    function new() {
    var htmlText =  "<div class='container'><textarea name='reason[]' style='font-size: 10px;width:500px; height:50px;' onFocus='if(this.value==\"type more information"\") { this.value=\"\"}'>type more information</textarea></div>"; 
          		
            var newElement = document.createElement('div');
    
            newElement.id = 'new1'; // Give the DIV an ID, if you need to reference it later...
    
     newElement.innerHTML = htmlText;
    
         var fieldsArea = document.getElementById('newdiv');
    fieldsArea.appendChild(newElement);
    
    }
    

  9. it should work... when i press the button a textarea should be displayed in the div "newreason".  It isn't working though.

     

    	
    <input type='button' onclick='newreason()' name='reasonbutton' value='Next reason' style='font-size:12px;' />
    
    <div id='newreason'>
    </div>
    
    
    function newoutcome()
    {
    var htmlReason =  "<span class='font'>More Information</span><img src='arrowdown.jpg' /><br />
    <textarea name='reason[]' style='font-size: 10px;width:500px; height:50px;' onFocus='if(this.value==\"type more information\") { this.value=\"\"}'>type more information</textarea>"; 
          		
    var newElementone = document.createElement('div');
    
           
    	newElementone.id = 'newreason1';
    
    	newElementone.innerHTML = htmlReason;
    
      var fieldsAreaone = document.getElementById('newreason');
    fieldsAreaone.appendChild(newElementone);
    
    }

  10. i did this but then realised it won't total the `rating` for a DISTINCT username.  How can i change it so that it totals the rating for a username?

     

    	$getuser = mysql_query("SELECT DISTINCT username, rating FROM block WHERE category='$category' ORDER BY `rating` DESC",$this->connect);
    
    				while ($row = mysql_fetch_assoc($getuser)){
    				$theuser = ucfirst($row['username']);
    				$rating = $row['rating'];
    
    				echo "<div class='leaderboard'><ul><li><a href='profile.php?user=$theuser'>$theuser</a></li><li>$rating</li></ul></div>";
    
    				}

  11. i tried this but it doesn't work. rating is a column with integer type.  it is returning the wrong row with the lowest rating.

     

    how do i get the the highest rating(integer) in the WHERE clause?

     

    $getrest =  mysql_query("SELECT * FROM block WHERE sid='505' ORDER BY 'rating' DESC LIMIT 1") or die(mysql_error());
    while($row=mysql_fetch_assoc($getrest))
    {
    $name= $row['name'];
    
    }
    
    echo $name;

  12. $c = "non-specific";
    $categoryex = explode(", ",$c);	
    
    $category = "non-specific";
    if(array_key_exists('$category', $categoryex)) {
    					 echo "yes";
    					}
    
    

     

    it should echo yes because $category='non-specific' and 'non-specific' is in the array...

  13. for example.. in one column it has "test1, test2, test3, test4"  .... when i search for test1... i only want rows that have 'test1' in them. 

     

    $search = test1

     

    i've tried LIKE %$test1% but it get's all rows with the word 'test' in it... i want only rows with the word 'test1' in it.

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