January 17, 2011

<ul> within another <ul> inherits style

Question by JamWaffles

I have the following structure in some HTML:

<ul class="li_inline">
    <li>
        <ul class="li_block">
            <li>Stuff</li>
            <li>Stuff under stuff</li>
        </ul>
    </li>
    <li>
        <ul class="li_block">
            <li>Stuff</li>
            <li>Stuff under stuff</li>
        </ul>
    </li>
</ul>

With the CSS like this:

.li_inline li
{
    display: inline;
}

.li_block li
{
    display: block;
}

What I would like to happen is to have the two inner <ul>s side by side, but any <li>s inside them to be below each other. This is so I can get a sidebar and main body side by side, but elements inside them behave normally (ie. one below the other).

Can someone suggest some CSS I can use so that the inner (li_block) lists’ <li> elements are displayed as block elements, but the <ul>s themselves are displayed side by side?

Thanks,

James

Answer by Starx

Use a reset rule.

ul ul { list-style:none; padding: 5px 20px; margin: 5px 10px; }

In your case using the !important can get your job done. But try not to use it

UPDATE

Solution: http://jsfiddle.net/Starx/KHjmP/ (FF3+, Safari 4+, IE8+)

January 13, 2011

PHP get all function arguments as $key => $value array?

Question by web lover

<?php
function register_template(){
    print_r(func_get_args());
    # the result was an array ( [0] => my template [1] => screenshot.png [2] => nice template .. ) 

}

register_template(     # unkown number of arguments
    $name = "my template",
    $screenshot = "screenshot.png",
    $description = "nice template .. "
)
?>

BUT , I want the result array as $key => $value form , $key represents the parameter name.

Answer by Starx

It’s easy. Just pass the array as the parameter instead then later access it as $key => $value inside the function.

UPDATE

This was the best I could think of

$vars = array("var1","var2"); //define the variable one extra time here
$$vars[0] = 'value1'; // or use $var1
$$vars[1] = 'value2'; // or use $var2

function myfunction() {
    global $vars;
    $fVars = func_get_args();
    foreach($fVars as $key=>$value) {
       $fvars[$vars[$key]] = $value;
       unset($fvar[$key]);
    }
    //now you have what you want var1=> value1
}

myfunction(array($$vars[0],$$vars[1]));

I haven’t tested it…BTW. But you should get the point

January 12, 2011

Center div horizontally

Question by Don

On this page, I would like to horizontally center the main #container div relative to the page. Normally I would achieve this by adding a CSS rule,

#container { margin: 0 auto }

However, the layout of this page (which I did not write), uses absolute positioning for #container and most of its child elements, so this property has no effect.

Is there any way I can achieve this horizontal centering without rewriting the layout to use static positioning? I’ve no problem with using JavaScript/JQuery if that’s the only way to achieving my objective.

Answer by Starx

Same as @rquinn answer but this will adjust to any width. Check this demo

http://jsfiddle.net/Starx/V7xrF/1/

January 10, 2011

How to avoid original msg while reply using PHP?

Question by VinothPHP

Dear all,
how to avoid original message while reply for incoming mail using php, Am download the mail from mail server, the message content ll be combine with original messages, so its confused, and some of html entities are placed with that content,because of that original messages,
So how to avoid that original messages using php, anyone can help me…

Thanks in Advance….

Regards,
Vinoth S

Answer by Starx

I am not sure, if this is your answer but

$message = preg_replace ('/<[^>]*>/', '', $message);

OR

$message = strip_tags($message);

Will remove all the html entities from your message? Try it

January 9, 2011

Count especific table rows in mysql

Question by NORM

I want to count how many rows I have in a mysql table and display it in html.

For example:

There is: Item 1, Item 2, Item 3, Item 4, Item 5, Item 6

If Item 1 and Item 2 are filled, I want a html code to say – 2 items in row

any ideas?

Answer by Starx

IF its total rows you are after, then as Nishant mentioned above you could do something like this

$query = "SELECT COUNT(*) FROM mytable WHERE myfield='myvalue'"; 

I am counting all the ids, because it will reduce the time taken to calculate the total instead of ‘*’ and

Thanks to Nico, count(*) and count(column) are not so different considering performance. Here is a comparision

Use a where condition to narrow your total as you require.

Light HTML webpage designer to use along side netbeans on my mac?

Question by LondonGuy

I would like to know if there is a plugin for netbeans that would make it easy for me to edit html and build simple temp pages while coding so I can place things in the right place on my page etc..

If there isn’t a plugin is there any lightweight HTML webpage editor I could use?

Thanks in advance..

I also don’t mind buying..

Answer by Starx

Lightweight HTML Editor? :O

Try http://brandonsoft.com/htmlide/

January 7, 2011

How to add duplicate image on same page with java Script after page loaded

Question by Shoun

i m facing a problem, what i ma doing is that. i have a server side image button. what i wana do is that after that page loads at client side, i want to place that same image with same navigation url at another location on same page. Can any body tell me how to do that? same as i also want to hide some text on page with javascript. any idea??

Answer by Starx

use .clone() method.

An Example:

Let ‘s suppose your img being this

<img class="yourimageclass" src="Your/path/to/image.jpg" ?>
<!-- And this being where you want to copy it -->
<div class="whereuwanttocopy"></div>

Then your jQuery would be

$('.yourimageclass').clone().appendTo('.whereuwanttocopy');

To hide some text in your page, wrap them into some container, so that we could address that piece of content

<span class="todhide">here is the text to hide</span> and here is the text to not hide

Then use simple $(".tohide").hide() whenever you want to hide the text

Is it possible to Copy images from web to your Hard Drive?

Question by Starx

I am trying to create a page for just personal use. What I want to do is, create a system through which I can download images to my local hard disk, directly by providing the link through a localhost like WAMP. The reason I am trying to do is, I want the images to be automatically sorted onto my hard disk. My form field will be something like this

<form method="POST" action="process.php">
   <input type="text" name="URL" id="URL" />
   <input type="text" name="category" id="category" />
   <input type="text" name="subcategory" id="category" />
   <input type="submit">
</form>

Now, in the process.php

//This is just a sample... So please ignore the roughness of the coding

copy($_POST['url'],$_POST['category']."/".$_POST['subcategory']."/somename.jpg");

// If you noticed, the categories and subcategories are actually the name of directory, where I want the picture to go be saved....

I am thinking my approach is wrong. How can I achieve something like this?

Error

Warning: copy(images/image.jpg) [function.copy]: failed to open stream: No such file or directory in

Answer by Starx

Ok, I used curl instead to achieve what i am expecting. Here is the piece of code

$img = $_POST['url'];
$fullpath = $_POST['category']."/".$_POST['subcategory']."/".basename($img);
$ch = curl_init ($img);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec($ch);
curl_close ($ch);                   
$fp = fopen($fullpath,'x');
fwrite($fp, $rawdata);
January 6, 2011

jQuery – .css("right", posVar); does not work

Question by Tomkay

The Main objective here is to make an instand “jump” to the right. Like I said – I dont want to use .animate, because it makes a little “flashing” effect – because it is not instant. I think .css will make an instant “jump” to the right, without flashing effect.

You can find the full javascript code for my gallery here (german comments):
http://codeviewer.org/view/code:15dd

And the HTML
http://codeviewer.org/view/code:15df

I dont know why this will not work.. Instead of using .css I actually have to workaround this issue with .animate $("#gallery ul").animate({right: posVar},0);

I dont get it.. here is my actual (Javascript, JQuery) code:

setTimeout(function(){
   var posVar = 2838;        
   $('#gallery ul').css("right", posVar);
},300);

Whats wrong with that?

#gallery ul css

#gallery ul {
display:block;
position:relative;
width:14000px; /*auto calculated from javascript */
}

Answer by Starx

Css attributes:left, right, top, down will not work with display:block try display:absolute or display:fixed

I dont know what was on my mind when I wrote that answer. I mean to say…. you need position:absolute or position:fixed or position:relative

And I think the problem with your code is there is not “px” at the end…

I have fiddeled it, and here it is http://jsfiddle.net/Starx/8w6cS/

YOUR CODE IS WORKING HERE IS A PROOF

http://jsfiddle.net/Starx/8w6cS/1/


AND IF YOU TRYING TO MOVE YOUR ul to 2838px to the right Here is your solution

http://jsfiddle.net/Starx/8w6cS/2/

...

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