Web Dev Questions That Don't Need Their Own Thread v4
5,001 replies, posted
[QUOTE=Cowabanga;39999320]Alright so I've started learning html5 and I'm seeing a bunch of retarded tags that (from what I've seen) nobody uses, such as header, nav, footer, aside. Are they basically div's with fancy names?[/QUOTE]
Pretty much, you just use them just like body etc.
[code]
<footer>lol</footer>
=>
footer {
}
[/code]
Fuck that I prefer ID'd divs. Glad to know that they're near useless anyway so thanks!
Semantics aren't useless.
How so? What's the advantage of using them over div's?
[editline]22nd March 2013[/editline]
Excluding "making the html code prettier".
I have a jquery script that makes a button slide right when pushed and then slide left when pushed again. It works in chrome, but doesn't work in IE or Firefox. Is there a general solution to this? (all other jquery scripts work on all browsers)
If not, I will post the code.
[QUOTE=Cowabanga;39999365]Fuck that I prefer ID'd divs. Glad to know that they're near useless anyway so thanks![/QUOTE]
They're not at all useless, read up on semantic markup.
[editline]22nd March 2013[/editline]
[QUOTE=Cowabanga;39999539]How so? What's the advantage of using them over div's?
[editline]22nd March 2013[/editline]
Excluding "making the html code prettier".[/QUOTE]
HTML is for marking up content. Having markup that does a better job of describing the content is inherently better.
Some good answers here: [url]http://stackoverflow.com/questions/1729447/what-are-the-benefits-of-using-semantic-html[/url]
Alright, will look into those, thanks!
[editline]22nd March 2013[/editline]
Yeah figures, just to make your code look prettier and stand up more for HTML's cleaniness aspect thingy. Only if you want to nitpick it seems.
You missed the entire part about SEO benefits like the search engine actually knowing what your main content is. You also missed the accessibility implications for people using screen readers.
Not to mention that as a developer you should always strive to write the cleanest, most easily understandable and readable code possible. I don't know about you but I think that...
[code]
<body>
<header>
<nav></nav>
</header>
</body>
[/code]
is a hell of a lot cleaner than...
[code]
<div id="body">
<div id="header">
<div id="nav"></div>
</div>
</div>
[/code]
If you have a bunch of markup in your header you know exactly what tag closes the header if you use the HTML5 tags, instead of having to scroll up to see what indentation level the closing div tag you are looking for is at.
I have no idea why you would not want to use them.
Oh woops completely overlooked the SEO benefits part, sorry! :v: Looks like I can squeeze some use for those after all, thanks for pointing that out.
[QUOTE=MuffinZerg;40000137]I have a jquery script that makes a button slide right when pushed and then slide left when pushed again. It works in chrome, but doesn't work in IE or Firefox. Is there a general solution to this? (all other jquery scripts work on all browsers)
If not, I will post the code.[/QUOTE]
Post the code.
I need a way to pick a random key from an array based on probability (in PHP). I'm wanting to know if there's a solution better than this:
[php]
function probability($array)
{
$rand = mt_rand(1,100);
$currentWeight = 0;
foreach ($array as $key=>$value)
{
$currentWeight += $value;
if ($currentWeight > $rand)
{
return $key;
}
}
}
/* Example array:
$array = array(
'soccer' => 50,
'football' => 25,
'kickball' => 25
);
*/
[/php]
-snip-
[QUOTE=jetboy;40004843]I need a way to pick a random key from an array based on probability (in PHP). I'm wanting to know if there's a solution better than this:
[php]
function probability($array)
{
$rand = mt_rand(1,100);
$currentWeight = 0;
foreach ($array as $key=>$value)
{
$currentWeight += $value;
if ($currentWeight > $rand)
{
return $key;
}
}
}
/* Example array:
$array = array(
'soccer' => 50,
'football' => 25,
'kickball' => 25
);
*/
[/php][/QUOTE]
[PHP]/**
* Generate a more truly "random" alpha-numeric string.
*
* @param int $length
* @return string
*/
public static function random($length = 16)
{
if (function_exists('openssl_random_pseudo_bytes'))
{
$bytes = openssl_random_pseudo_bytes($length * 2);
if ($bytes === false)
{
throw new \RuntimeException('Unable to generate random string.');
}
return substr(str_replace(array('/', '+', '='), '', base64_encode($bytes)), 0, $length);
}
return static::quickRandom($length);
}[/php]
EDIT: This is for string, though. lol.
[QUOTE=jetboy;40004843]I need a way to pick a random key from an array based on probability (in PHP). I'm wanting to know if there's a solution better than this:
[php]
function probability($array)
{
$rand = mt_rand(1,100);
$currentWeight = 0;
foreach ($array as $key=>$value)
{
$currentWeight += $value;
if ($currentWeight > $rand)
{
return $key;
}
}
}
/* Example array:
$array = array(
'soccer' => 50,
'football' => 25,
'kickball' => 25
);
*/
[/php][/QUOTE]
[url]http://www.php.net/manual/en/function.array-rand.php#60268[/url]
Hey guys, I want to load 10 entries into an SQL table at a time. Any advice on how to do this? So far I have...
[code]
<?php
$query = $db->query("SELECT * FROM links");
if($query->numRows() != 0)
{
while($row = $query->fetchObject())
{
$date = strtotime($row->publish);
echo '<div class="post">';
echo '<h3>', date('l jS F', $date), '</h3>';
echo '<a target="_blank" href="', $row->url, '">', $row->title, '</a>';
echo '</div>';
}
}
?>
[/code]
[QUOTE=Loli;40023168]Hey guys, I want to load 10 entries into an SQL table at a time. Any advice on how to do this? So far I have...
[code]
<?php
$query = $db->query("SELECT * FROM links");
if($query->numRows() != 0)
{
while($row = $query->fetchObject())
{
$date = strtotime($row->publish);
echo '<div class="post">';
echo '<h3>', date('l jS F', $date), '</h3>';
echo '<a target="_blank" href="', $row->url, '">', $row->title, '</a>';
echo '</div>';
}
}
?>
[/code][/QUOTE]
[code]SELECT * FROM links LIMIT 10[/code]
i am designing a site and i cant get the site to be 100% of the screens height neither can i get the left bar to expand to the right bar needs. i have tried allsorts.
looks like this atm:
[IMG]http://i.imgur.com/3luFqLY.png[/IMG]
style.css
[CODE]#main{
height:auto;
background-color:#FFFFFF;
overflow:hidden;
}
#leftc{
width:230px;
height:auto;
float:left;
background-color:#F5F5F5;
border-right:solid 1px #D6D6D6;
}
#left{
width:210px;
height:auto;
float:left;
padding:20px 0 20px 20px;
border-right:solid 1px #D6D6D6;
background-color:#F5F5F5;
}
#right{
background-color:#FFFFFF;
width:699px;
display:inline-block;
padding:20px 0 20px 20px;
}[/CODE]
index.php
[CODE]<div id='main'>
<div id='leftc'>
<div id='left'>
<?php
if ((1+1 == 3) === true) {
include 'includes/modules/profile.php';
} else {
}
?>
</div>
</div>
<div id='right'>
<?php
if ((1+1 == 2) === true) {
include 'includes/menu/profile/change_username.php';
} else {
include 'includes/modules/login.php';
}
?>
</div>
</div>[/CODE]
enlighten me please.
[QUOTE=boshuajackman;40024299]i am designing a site and i cant get the site to be 100% of the screens height neither can i get the left bar to expand to the right bar needs. i have tried allsorts.
style.css
[CODE]#main{
height:auto;
background-color:#FFFFFF;
overflow:hidden;
}
#leftc{
width:230px;
height:auto;
float:left;
background-color:#F5F5F5;
border-right:solid 1px #D6D6D6;
}
#left{
width:210px;
height:auto;
float:left;
padding:20px 0 20px 20px;
border-right:solid 1px #D6D6D6;
background-color:#F5F5F5;
}
#right{
background-color:#FFFFFF;
width:699px;
display:inline-block;
padding:20px 0 20px 20px;
}[/CODE]
index.php
[CODE]<div id='main'>
<div id='leftc'>
<div id='left'>
<?php
if ((1+1 == 3) === true) {
include 'includes/modules/profile.php';
} else {
}
?>
</div>
</div>
<div id='right'>
<?php
if ((1+1 == 2) === true) {
include 'includes/menu/profile/change_username.php';
} else {
include 'includes/modules/login.php';
}
?>
</div>
</div>[/CODE]
enlighten me please.[/QUOTE]
You have to make sure that html and body have height set to 100% as well.
[QUOTE=KmartSqrl;40024315]You have to make sure that html and body have height set to 100% as well.[/QUOTE]
[CODE]
html{
height:100%;
}
body{
background-image:url('images/background.gif');
background-color:white;
font-family:Ubuntu, sans-serif;
height:100%;
}
[/CODE]
doesnt affect at all.
you have height set to auto on #main which is going to make it the height of its content not the height of its parent. Also floated elements aren't going to work very well with height: 100%
Is there actually any real reason why a site would impose an upper limit on the length of a password? Or is it just a sign that they're doing things wrong?
I'm trying to insert an actual query into my database, using php pdo, but for some reason it doesn't work.
My query:
UPDATE `versioncontrol_database` SET `start_query`=:v0 WHERE `id`=:v1
':v0' is actually a create table query, but for simplicity let's say it holds "SELECT * FROM `table`".
How do I get it to work?
Back end:
[code]
$stmt = $identifier->prepare($query);
for($i = 0; $i < $length; $i++) {
$stmt->bindParam(':v'. $i, $raw_var_array[$i]);
}
$stmt->execute();
[/code]
$raw_var_array in this case is an array with 1 value, the query.
[b]EDIT:[/b] After some more debugging I found it didn't get the correct ID, fixed that, and now it works. Thanks anyways.
[QUOTE=Epic Sandwich;40031669]Is there actually any real reason why a site would impose an upper limit on the length of a password? Or is it just a sign that they're doing things wrong?[/QUOTE]
That's usually a hint that they are storing the passwords directly in the database without prior hashing. Hashes will always result in a defined number of bits.
[QUOTE=P1raten;40023543][code]SELECT * FROM links LIMIT 10[/code][/QUOTE]
So... How would I say "SELECT * FROM link LIMIT 10" After an id. The id will change (I basically want to load the first 10, then the next 10 when the people click "Load More")
use OFFSET
[QUOTE=Loli;40034696]So... How would I say "SELECT * FROM link LIMIT 10" After an id. The id will change (I basically want to load the first 10, then the next 10 when the people click "Load More")[/QUOTE]
[CODE]
... LIMIT 0, 10 -- first 10 rows
... LIMIT 10, 10 -- rows 10-20
... LIMIT 10, 20 -- rows 10-30, not 10-20
... LIMIT 20, 30 -- rows 20-50, not 20-30
[/CODE]
Anyone have a guide on how to format your PHP well? I've been writing it my own way mostly so far and it's probably going to make some people cringe.
[code]
function getItemPrice( $itemTemp )
{
//$itemTemp = array ($defindex, $quality, $allItemValues, $effect );
//var_dump ($itemTemp);
$defindex = $itemTemp[ 'defindex' ];
$quality = $itemTemp[ 'quality' ];
$allItemValues = $itemTemp[ 'allItemValues' ];
$effect = $itemTemp[ 'effect' ];
$itemValue = $allItemValues[ "response" ][ "prices" ][ "$defindex" ][ "$quality" ][ "0" ][ "value" ];
if ( $quality == 5 ) //unusual item.
{
$itemValue = $allItemValues[ "response" ][ "prices" ][ "$defindex" ][ "$quality" ][ "$effect" ][ 'value' ];
}
if ( !isset( $itemValue ) ) $itemValue = 0;
return $itemValue;
}
[/code]
I occasionally use a PEAR formatter to make my code tidy when I am working, I want to know if the PEAR format and my changes / breaks from the format are good or not.
This is an actual piece of code I use in a program so you can tear me apart on it without any doubts because I genuinely leave my code this way.
Two tabs for indentation is way too much for my taste, your eyes have to jump too far with two tabs. I use two spaces.
You're also not adding any clarity to your code by setting your curly braces on their own indentation level. Keep them at the same level as the statement they are for, it makes scanning easier I think.
This is how I would do it
[code]
function getItemPrice($itemTemp)
{
// $itemTemp = array ($defindex, $quality, $allItemValues, $effect );
// var_dump ($itemTemp);
$defindex = $itemTemp['defindex'];
$quality = $itemTemp['quality'];
$allItemValues = $itemTemp['allItemValues'];
$effect = $itemTemp['effect'];
$itemValue = $allItemValues["response"]["prices"][$defindex][$quality]["0"]["value"];
// unusual item.
if ( $quality == 5 ) {
$itemValue = $allItemValues["response"]["prices"][$defindex][$quality][$effect]['value'];
}
if (!isset($itemValue)) {
$itemValue = 0;
}
return $itemValue;
}
[/code]
[QUOTE=KmartSqrl;40037135]Two tabs for indentation is way too much for my taste, your eyes have to jump too far with two tabs. I use two spaces.
You're also not adding any clarity to your code by setting your curly braces on their own indentation level. Keep them at the same level as the statement they are for, it makes scanning easier I think.
This is how I would do it
[code]
function getItemPrice($itemTemp)
{
// $itemTemp = array ($defindex, $quality, $allItemValues, $effect );
// var_dump ($itemTemp);
$defindex = $itemTemp['defindex'];
$quality = $itemTemp['quality'];
$allItemValues = $itemTemp['allItemValues'];
$effect = $itemTemp['effect'];
$itemValue = $allItemValues["response"]["prices"][$defindex][$quality]["0"]["value"];
// unusual item.
if ( $quality == 5 ) {
$itemValue = $allItemValues["response"]["prices"][$defindex][$quality][$effect]['value'];
}
if (!isset($itemValue)) {
$itemValue = 0;
}
return $itemValue;
}
[/code][/QUOTE]
I always see people saying whitespace in PHP is important, but how important? I've come into the habit of formatting my code a certain way because of the way I format my JavaScript, but now I'm moving into PHP I am afraid it is wrong. What will usually cause errors in PHP because of whitespace?
[QUOTE=Shadow801;40040024]I always see people saying whitespace in PHP is important, but how important? I've come into the habit of formatting my code a certain way because of the way I format my JavaScript, but now I'm moving into PHP I am afraid it is wrong. What will usually cause errors in PHP because of whitespace?[/QUOTE]
Basically nothing save for whitespace inside quotes or breaking up function-words.
You can do stuff like this:
[code]
$num =
1;
If ($num ==
1
)
{
echo"lol"
. ' no.'
;
/*white {}{}}}}{}}} space*/
}else echo"whoo" . '' . 'ps';
[/code]
Sorry, you need to Log In to post a reply to this thread.