...

Hi! I’m Starx

experienced Software Developer. And this is my blog
Start Reading About me
Blog Page
April 7, 2012

Hide "www" text in URL bar (firefox)

Question by Futur Fusionneur

I was wondering if it is possible to hide the “www” text in the URL bar (only in Firefox) using CSS in Stylish addon or/and Java in Greasemonkey.

I want this to make Firefox even more compact.


This is some CSS code that i found for URL bar in firefox that will modify the text size using Stylish. Hope it can help.

@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");

.urlbar-input-box,
.searchbar-textbox {
 font-size: 11px !important;
}

Update

I don’t want to remove the “www”, I just want to hide it from the url bar.

Answer by Starx

You have to use .htaccess for this

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

Replace example.com with your domain name.

Read more

Put DIV ID into a PHP Variable

Question by drummer392

I am wanted to get the id’s of all the divs on my page with the class archive and put them in a MySQL query to check and see if the ids are archived in the database.

So basically I am wondering how I can do this: $div = $(this).attr('id');

Then I would throw it into the loop to check:

$matches = mysql_query("SELECT * FROM content WHERE `div` = '$div'");
        while ($post = mysql_fetch_assoc($matches)) 
        {
            if (mysql_num_rows($matches) > 0)
            { 
              //DO THIS
            }
        }

UPDATE

I have this code for the AJAX now:

$('div.heriyah').each(function() { 
var curID = $(this).attr('id'); 
$.post("admin/btnCheck.php", { div : curID }, function(data) {
if (data == "yes") {
    $('#' + curID).html('<div class="add"><div id="add_button_container"><div id="add_button" class="edit_links">  + Add Element</div></div></div><div class="clear"></div></div>');
} else {
    $('#' + curID).html('<div class="add"><div id="add_button_container"><div id="add_button" class="edit_links">  + Set As Editable Region</div></div></div><div class="clear"></div></div>');
}
  });
});

And my PHP:

$matches = mysql_query("SELECT * FROM content WHERE `div` = '".$_POST['div']."'");
 if (mysql_num_rows($matches) > 0)
 { 
    echo "yes";
 } else {
    echo "no";
 }

What am I doing wrong?

Answer by Starx

You cannot throw a javascript variable to PHP script like that. You have to send an ajax request to the page

$div = $(this).attr('id');
$.post("yourquerypage.php", { divid : $div }, function(data) {
    // Something to do when the php runs successfully
});

Next, configure your query to get the variable from $_POST()

$matches = mysql_query("SELECT * FROM content WHERE `div` = '".$_POST['divid']."'");

And of course, you have to take measures for injection.

Read more

php comparing 2 co-ords

Question by user1022585

I don’t know why, but this doesn’t seem to work.

Basically I want this to be true if the player1 ($playerX, $playerY) is within one square from player2 ($rs[x], $rs[y])

if (($rs[x] > $playerX-2 or $rs[x] < $playerX+2) && ($rs[y] > $playerY-2 or $rs[y] < $playerY+2)) {
    // code

Any idea what I’m doing wrong?

Answer by Starx

Your conditions end up on true due to the OR operator

if (($rs[x] > $playerX-2 && $rs[x] < $playerX+2) && ($rs[y] > $playerY-2 && $rs[y] < $playerY+2)) {
   //your code
}
Read more

jQuery CSS opacity overriding

Question by higfox

I’m trying to create a popup for which I am using jQuery’s CSS function.Here’s the code:

function Show_Popup(action, userid) {
 $('#content').css("opacity","0.7");
 $('#window').fadeIn('fast');
 $('#window').css("opacity","1.0");}

Here #window is inside #content.Hence when it “fades in”,its opacity is also set to 0.7,which I am trying to override via the 3rd line of code.But its not working.Any way around this?Thanks.

Answer by mightyuhu

use

 $('#content').css("opacity","0.7");
 $('#window').fadeIn('slow', function() {
      $('#window').css("opacity","1.0");}
  });

also you might want to consider $.animate() if thats what you’re looking for.

Remember: CSS-Opacity is chaining. So even if #window has an opacity of 100% its only a 100% from the 70% opacity of its parent..
See http://www.impressivewebs.com/css-opacity-that-doesnt-affect-child-elements/ for a hackish workaround

Answer by Starx

Use fadeTo()

$('#window').fadeTo('fast', 1.0);
Read more

How to detect whether css floated items overflows to the next line?

Question by Vlad

When you use float:left or float:right, how do you know when a line has overflown to the next line? For example, I would like a collection of items to flow from left to right side of the screen at the bottom, but when the line overflows to the next line, just hide it. Is there a way to know at which point the float items overflows into the next line?

Answer by Starx

One way to look at would be to

  • Collect the items as per the float Order
  • Calculate the total width
  • Compare against parent and see if its greater.
Read more

PHP header("Location: $url");

Question by Miomir Dancevic

Possible Duplicate:
Headers already sent by PHP

Here i have strange problem to protect my pages , to check is session started, if not redirect to login,

    <?php 
require_once ('includes/config.inc.php'); 

// Start output buffering:
ob_start();

// Initialize a session:
session_start();

// Check for a $page_title value:
if (!isset($page_title)) {
    $page_title = 'User Registration';
}

// If no first_name session variable exists, redirect the user:
if (!isset($_SESSION['first_name'])) {

    $url = BASE_URL . 'index.php'; 
    ob_end_clean(); // Delete the buffer.
    header("Location: $url");
    exit(); // Quit the script.

}
?>

I got this error: on line 8:

session_start() [function.session-start]: Cannot send session cache limiter – headers already sent

Can someone post a good solution to check if the session is started, and if not redirect to login page else stay on page??
Txanks

Answer by Starx

Whenever, you see headers already sent, that means somethings is being output before the PHP could send the headers.

In your case, it is the additional sources before the PHP tag as Oli Charlesworth said.

Read more

Bold Largest Value – Comparing Values

Question by Kevin Murphy

I’m trying to compare two numbers, and add an HTML class to the large one- in this case statistics for a video game. Now I could do $player1[stat]-$player2[stat] and if the result is negative, player2 had a large value or just do normal greater than or less than logic. But, the thing is, I have about 20 different statistics I have to compare and add the class.

What would be the easiest way of making the larger value bold?

I was going to try case switches but that seems tedious. 20 different if-statements also seemed unnecessary.

Thanks!

Edit: Just to be clearer, I need to echo the values as well, but have the largest bolded

$player1[kills] = 55;  
$player2[kills] = 40;  

$player1[deaths] = 15;  
$player2[deaths] = 10;

The desired result:

<table>  
    <tr> 
        <th>Statistic</th>
        <th>Player 1</th>   
        <th>Player 2</th>        
    </tr>
    <tr> 
        <th>Kills</th>
        <th><strong>40Player 2</th>        
    </tr>  
    <tr> 
        <th>Deaths</th>
        <th>15</th>   
        <th><strong>10</strong></th>        
    </tr>      
</table>

Another thing- less deaths is better, so is there a way to some how chose the smaller one for that instance?

Answer by Michael Berkowski

Retrieve the largest value from each group with something like:

$maxkills = max($player1['kills'], $player2['kills']);
$maxdeaths = max($player1['deaths'], $player2['deaths']);

On output:

if ($player1['kills'] == $maxkills) {
   // Add <strong> tag
   echo "<strong>{$player1['kills']}</strong>";
}
else {
   // output without <strong> tag
   echo $player1['kills'];
}

You can use a ternary operator to shorten this as well:

echo $player1['kills'] == $maxkills ? "<strong>{$player1['kills']}</strong>" : $player1['kills'];

By the way, please put quotes around your array keys. Although PHP parses them correctly (by assuming you meant to use strings instead of constants), it is issuing a notice for each time you do it even if those notices are just piling up in log files.

Answer by Starx

When you are retrieving the value of kills and death, add them onto a global array.

$kills = array();
$death = array();
while($row = mysql_fetch_assoc($query)) //... or some database operation
    $kills[] = $row['kills'];
    $death[] = $row['deaths';

    //do other details
}

Now find out the maximum of each values

$killMax = max($kills);
$deathMax = max($death);

Now wherever you are display compair to this

echo $player1['kill']==$killMax ? "<strong>".$killMax."</strong>" : $killMax;
Read more

JavaScript – Input a date then autopopulate next field with difference

Question by user1318430

Hi this is making me nuts. I am not a developer. Trying to get this to work.
User puts in a date (hire date) into form using Date object (calendar)
Next field should take that date and subtract todays date to get the length of employment.
But I get undefined in the field AND my original hire date disappears.
Here is what I have, help please, much appreciation!

//grab date of hire
try{document.getElementById("dData_DOH").onchange =          custom_calculateDate;}catch(e){}
//not sure if necessary - field that the difference should go to
try{document.getElementById("dData_LengthEmp").onblur =     insertDate;}catch(e){}

//Function to grab input hire date 
//Create variable for now
//Create variable for difference


function custom_calculateDate(){
 var hireDate = document.getElementById("dData_DOH").value = "";
     var timeNow= new Date();
 var diff = Math.abs(timeNow - hireDate);
document.getElementById("dData_DOH").setAttribute('value',     custom_calculateDate());
     }

//Function to get the difference into the LengthEmp field    
function insertDate() {
document.getElementById("dData_LengthEmp").setAttribute("",     custom_calculateDate());
}

I know this is completely wrong, as I said I am not a developer or programmer, I cannot figure out how to get this information into this field and get my original field to still show.

Thank you for reading this!

Answer by Starx

Use value instead of setAttribute

document.getElementById("dData_DOH").value = custom_calculateDate();
Read more

text-rotation – problem with IE

Question by user794035

Hi I’m trying to rotate a text, but i’m facing some problems with IE 8 and 9

.casaText{
     display:block;     
    -webkit-transform: rotate(-90deg);  
    -moz-transform: rotate(-90deg);
    -o-transform: rotate(-90deg);
    -ms-filter:rotate(-90deg);
    filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
    white-space:nowrap;
    position:relative;

In IE it doens’t rotate. Does anyone can tell me why??

thanks

Answer by Starx

Use Matrix for the rotation:

Here is for -90deg

filter: progid:DXImageTransform.Microsoft.Matrix(M11=6.123233995736766e-17, M12=1, M21=-1, M22=6.123233995736766e-17, sizingMethod='auto expand');
zoom: 1;
Read more
...

Please fill the form - I will response as fast as I can!