...

Hi! I’m Starx

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

About 'XDEBUG NOT LOADED AS ZEND EXTENSION'

Question by lovespring

xdebug is loaded, but not loaded as a zend extension.
what this mean?
how to resolve it?

thanks!

Answer by Derick

This error means that you used “extension=” to load Xdebug. That could be in your normal php.ini, or in a file called xdebug.ini that some distributions like to add. In any case, Xdebug needs to be loaded as a Zend extension. The syntax for this depends on PHP version and build. I would suggest you use http://xdebug.org/wizard.php to provide you with the correct lines.

Answer by Starx

Make sure if it is configured to load correctly as a zend_extension. Inside php.ini add this line

zend_extension="/usr/local/php/modules/xdebug.so"
Read more

Why aren't these two divs displayed how I expect them to be?

Question by Bogdan

This jsfiddle example shows what I’m talking about, I gave the div in question a red border to show how it’s displayed.

I’d expect the #searchwrapper_3 div to go inside the #col_st_cautare one, but for some reason that’s not how it works. I’ve been staring at it for a while now and I got no idea why it’s showing like that

I also have an example of it looking ok simply because i’ve added another element after the #searchwrapper div here.

Issue’s fixed, TIL a div will collapse if it contains only floating elements.

Answer by Dutchie432

You need to do a clear:both; – see the end of http://jsfiddle.net/wzYry/3/

<div style="border: 1px solid red;" id="col_st_cautare">
    <div style="float: left;" id="searchwrapper_3">

        .... code ....

    </div>
    <div style="clear:both;"></div>
</div>​

On a side note, it may be easier to make clr class in your styles.

.clr{clear:both;}

This way you can use this anytime you need to clear

<div class='clr'></div>

Answer by Starx

This is happening because the child elements inside are floated and parent lost track of the how to wrap them.

Probably the easiest fix for this

#col_st_cautare { overflow: hidden; }

Demo

Other than this, the stable solution would be to add <div style="clear:both;"></div> before the closing the element.

Read more

How do you disable copy, paste, and print like Amazon's Kindle web e-reader?

Question by Dominic Tancredi

How does Amazon Kindle’s web e-reader (https://read.amazon.com/) disable copy and paste?

Also, how does it make the “printing” of the page render only a blank page?

I reviewed it in the Google Chrome browser, and would like to know what browsers this can be implemented on.

They still allow text selection (for Highlight or Note) so they’re not disabling selection, I believe.

Answer by Starx

Mostly they are done by JavaScript. They catch the key stroke of ctrl + c & ctrl + v then cancel the propagation. And also they disable the right click, by catching the mouse event for right button and stop its propagation.

But this is of no use because once the java script is disabled, they are all gone.

The printer printing blank can be done using media queries

@media print {

    * { display: none; }

}
Read more

How to count characters in array after while loop

Question by sdfgsdfg

Do u have any ideas how to count all characters in string $chars after while loop ?

$x = 0;
$b = 0;

while ($x++ < 10) {
  echo $chars = $item->zodziai[$b++];
  echo ' ';
}

echo strlen($chars);

Answer by Starx

Concatenate the characters then count them

<?php 
$x = 0; $b = 0;
$char = ''; //define a variable to collect all the chars
while ($x++ < 10) {
   $char .= $item->zodziai[$b++]; //add to the char
   echo $chars = $item->zodziai[$b++]; echo ' ';
}
echo strlen($char); //then count all the array combined
?>
Read more

How do I make a overflow:scroll div have the same height of its container? Details inside

Question by Bror Bojlén

I have a website with two columns, within a wrapper div.

The wrapper has the same height as the tallest div by giving floating everything and giving the wrapper height:100%.

Here’s my problem: one of the columns is a div with overflow:scroll and several images in it. I tried to set its height to 100%, thinking that it would take up the full height of the wrapper. Instead, it became the height of all the images on top of each other.

If I set the height of the column with images (#rightbox) to a specific height in pixels, this happens.

I want it to have the same height as the other div with text, so I set its height to 100%. Then this happens.

How can I make the two columns have the same height?

EDIT: I forgot to mention that the amount of text varies, so I can’t define a specific height for the wrapper.

Answer by Starx

You cannot define height as 100% unless your parents provides an actual heights.

#wrapper {
   height: 800px;
}

/* Now you can make the columns inside take the full height of its parent *?
#wrapper .columns {
   height: 100%;
   overflow: auto;
}

Note: if the wrapper sits inside the body element then you will need to set html,body { height: 100%; } before the wrapper can be set to 100%

Read more
April 5, 2012

While loop returning data

Question by relentless

In the code below, I’m pulling all upcoming training classes from my database. I’m checking to see if the endDate has passed and I’m also checking if the status !='2'

I want this to return the 4 most recent results. It works fine until statusdoes =2. I understand that the loop is technically running 4 times, but only displaying the results with status !='2'

How can I change this so that if status = '2' the loop will continue until it finds 4 results that meet the criteria?

<?php
$today = date("Y-m-d");
$count = 0;
$sth = $dbh->query('SELECT * from training ORDER BY startDate ASC');  
        $sth->setFetchMode(PDO::FETCH_ASSOC); 
            while($count <= 4 && $row = $sth->fetch()) { 
                if($row['endDate'] > $today && $row['status'] != '2') {?>
                    <li>
                    <img class="post_thumb" src="/images/img.jpg" alt="" />
                    <div class="post_description">
                        <small class="details">
                            <?php echo date("m/d/Y", strtotime($row['startDate'])) . ' - ' . date("m/d/Y", strtotime($row['endDate'])) ?>
                        </small>
                        <a class="post_caption" href="/register.php?course_id=<?php echo $row['courseId'] . '&id=' . $row['id'] ?>"><?php echo $row['title'] ?></a>
                    </div>
                    </li>
                <?php }
                    $count++;
                    }
                ?>  

Answer by Victor Nitu

You must put the $count++ inside the if loop, otherwise it will always get incremented.
As in:

<?php
$today = date("Y-m-d");
$count = 0;
$sth = $dbh->query('SELECT * from training ORDER BY startDate ASC');  
        $sth->setFetchMode(PDO::FETCH_ASSOC); 
            while($count <= 4 && $row = $sth->fetch()) { 
                if($row['endDate'] > $today && $row['status'] != '2') {?>
                    <li>
                    <img class="post_thumb" src="/images/img.jpg" alt="" />
                    <div class="post_description">
                        <small class="details">
                            <?php echo date("m/d/Y", strtotime($row['startDate'])) . ' - ' . date("m/d/Y", strtotime($row['endDate'])) ?>
                        </small>
                        <a class="post_caption" href="/register.php?course_id=<?php echo $row['courseId'] . '&id=' . $row['id'] ?>"><?php echo $row['title'] ?></a>
                    </div>
                    </li>
                <?php 
                $count++;
                }
            }
?>

Answer by Starx

You can break out out of the loop, if its four

while($row = $sth->fetch()) { 
        ....
        if($row['status']=='2' && $count >="4") break;
        $count++;
}
Read more

'alt' inside span

Question by user1184254

If ‘alt’ is inside ‘span’ would I need to change the following script

        function setNavi( $c, $i ) {
                var title = $i.attr( 'alt' );
                $('#title').text( title );

                var current = $c.triggerHandler( 'currentPosition' );
                $('#pagenumber span').text( current+1 );

            }

    $(function() {

        $('#carousel').carouFredSel({
            debug: true,
            responsive: true,
            circular: false,
            auto: true,
            prev: '#prev',
            next: '#next',
            items: {
                visible: 1,
                width: 200,
                height: '66%'
            },
            scroll: {
                onBefore: function( $oI, $nI ) {
                    setNavi( $(this), $nI );
                }
            },
                onCreate: function( $vI ) {
                    setNavi( $(this), $vI );
                }
            });

html:

<div id="carousel">
<span id="1"><img src="images/someimage.jpg"  alt="sometitle" /></span>
<span id="2"><img src="images/someimage2.jpg" alt="sometitle2" /></span>
</div>

<div id="navi">
 <p id="pagenumber">Now showing image <span></span> of 7.</p>
 <p id="title"></p>
</div>

the pagenumber is displaying correctly, but not the image title. also tried using ‘title’ instead of ‘alt’ but it still results in a blank title.

Answer by Starx

You dont need to do this, its semantically incorrect. There is title field for span. Use that instead of alt.

Read more

missing ) after argument list on line 1

Question by Rafael

 <script type="text/javascript">$('#multipleResults').show(); $('#multipleResultsOut').html('<table><tr><td colspan="2"><?php echo $lang['search.limited']; ?></td></tr><?php while ($bQr = mysql_fetch_assoc($botquery22)) { echo ('<tr><td style="width: 40px;"><div style="width: 40px; height: 40px; overflow: hidden; background-position: center; background-repeat: no-repeat; background-image: url('%www%/images/badges/'.$bQr['name'].'');"></div></td><td><a href="#" onclick="getBadge('%www%/', ''.$bQr['name'].''); return false;">'.$bQr['badgename'].'</a><br />'.$bQr['desc'].'</td></tr>'); } ?><?php echo $end; ?>;</script><?php echo $lang['search.x.results']; ?>

And I’ve rolled the code again, but still the same error.

Answer by Starx

May be the problem of quotes, the php snippets are also using single quotes as your js script.

Try them this way

$('#multipleResults').show();
$('#multipleResultsOut').html('<table><tr><td colspan="2">'+
<?php echo $lang['search.limited ']; ?>+'</td></tr>'+
<?php while ($bQr = mysql_fetch_assoc($botquery22)) { 
    echo (' < tr > < td style = "width: 40px;" > < div style = "width: 40px; height: 40px; overflow: hidden; background-position: center; background-repeat: no-repeat; background-image: url('%www%/images/badges/'.$bQr['name'].'');" > < /div></td > < td > < a href = "#" onclick = "getBadge('%www%/', ''.$bQr['name'].''); return false;" > '.$bQr['
badgename '].' < /a><br / > '.$bQr['
desc '].' < /td></tr > '); 
} 
?>
<?php echo $end; ?>;
Read more

How to bind enter key to callback in Javascript without slowing down the typing?

Question by HappyDeveloper

I need this for a chat box. When the user press enter, I want to trigger a callback (to send the message and clean the input field)

So far I got this, but the typing becomes slow:

$('#chat_input').keydown(function(event) {
  if(event.keyCode == '13') {
    // do something
  }
});

How would you optimize this?

UPDATE: It’s not a huge slow down, but I can feel it. I’m pretty sure this code is the responsible. I have always had this problem, so I thought it was about time to find a different way if possible.

Answer by Starx

No, your code are not the guilty one here. Since you are building a chat system, you must be running other scripts as well. But here is another way to look into the problem.

Make a mini form

<form name="chatline" ... >
   <input type="text" />
   <input type="submit" />
</form>

Then catch the submit event of the form, which will be triggered on enter automatically by the browser

$("form").submit(function() {
    //there you go, you caught your enter
});
Read more

Is there a reason not to use <=> (null safe equals operator) in mysql instead of =?

Question by cellige

MySql provides a nice operator <=> that works with comparisons that could contain a null such as null <=> null or null <=> 5 etc giving back intuitive results as many programming languages. Where as the normal equals operator always just returns null, which catches many new MySql users such as myself awry.

Is there a reason MySql has both and not JUST the functionality in <=> ? Who really needs an operator that is effectively undefined with built in language types?

Answer by Starx

Is there a reason MySql has both and not JUST the functionality in <=>
?
The operators are completely different from each other.

<=> performs an equality comparison like the = operator, but returns 1 rather than NULL if both operands are NULL, and 0 rather than NULL if one operand is NULL.

Who really needs an operator that is effectively undefined with built
in language types?

This depends on case, just because you haven’t encountered such cases, does not mean nobody needs it.

Read more
...

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