Web Dev Questions That Don't Need Their Own Thread v4
5,001 replies, posted
[QUOTE=BoowmanTech;43555482]I was thinking how to make a webpage that has different pages.
Ex: Like on here are 64 Pages. So like you have a list when it has 10 item on the page it creates a new page 1 , 2 on the second page will be another items.
Could someone point me in the right direction, I just need something that could help me with that.[/QUOTE]
Have a div on a page, clicking the number passes the page number via ajax, change the url to reflect this page change (onload check the page and give those results).
Php then takesthe page number and turns it into a range, eg
1 = 0,9
2 = 10, 19
etc
Then use this range with a mysql limit query to get the posts/results.
Then either use php to make the html to replace the innerhtml of your div or pass the results as json and have javascript rebuild the innerhtml of that page.
In short:
use page number to build range
use mysql limit to get values in that range
use data to build content
I have a chart showing a day-by-day LineChart view of some GA metrics. When the user clicks Month-By-Month, the chart redraws (in the same place, using the same DIV) as a ColumnChart with different values. When the user then clicks back to Day-By-Day, the chart should redraw again as a LineChart, however the chart doesn't redraw at all after the first redraw.
Here is an example of what I'm talking about. The chart starts as a ColumnChart, and you are able to get the LineChart to draw, but if you want to switch back to the ColumnChart, you can't!
[CODE]
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(initialize);
function initialize() {
var chart = new google.visualization.ColumnChart(document.getElementById('chart-div'));
var line = new google.visualization.LineChart(document.getElementById('chart-div'));
var data = [];
data[0] = new google.visualization.DataTable();
data[0].addColumn('string', 'x');
data[0].addColumn('number', 'A');
data[0].addColumn('number', 'B');
data[0].addRow(['A', 123, 40]);
data[0].addRow(['B', 17, 20]);
data[1] = new google.visualization.DataTable();
data[1].addColumn('string', 'x');
data[1].addColumn('number', 'C');
data[1].addColumn('number', 'D');
data[1].addRow(['C', 222, 13]);
data[1].addRow(['D', 542, 80]);
var options = {
width: 400,
height: 240,
vAxis: {minValue:0, maxValue:1000},
animation: {
duration: 1000,
easing: 'out'
}
};
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
var barsButton = document.getElementById('b1');
var lineButton = document.getElementById('b2');
function drawChart() {
chart.draw(data[0], options);
}
function drawLine() {
line.draw(data[1], options);
}
barsButton.onclick = function() {
drawBars();
}
lineButton.onclick = function() {
drawLine();
}
drawChart();
}
</script>
</head>
<body>
<input type = 'button' id = 'b1' value = 'Draw Column Chart' />
<input type = 'button' id = 'b2' value = 'Draw Line Chart' />
<div id="chart-div"></div>
</body>
</html>
[/CODE]
Any ideas as to why this is?
[editline]16th January 2014[/editline]
Aghh! It's so frustrating! I found this example which works perfectly:
[url]http://jsfiddle.net/LtVV3/[/url]
So I did a comparison and built this from using the example as a reference:
[CODE]
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(initialize);
function initialize() {
var data;
var quarter = [['Year', 'Crime', 'Incidence', 'Stock Loss'],
['1', 500, 340, 550],
['2', 1817, 846, 821],
['3', 686, 584, 482],
['4', 687, 589, 582]];
var yearly = [['Year', 'Crime', 'Incidence', 'Stock Loss'],
['1', 950, 934, 559],
['2', 9117, 946, 219],
['3', 966, 954, 429],
['4', 967, 959, 529]];
var options = {
width: 400,
height: 240,
vAxis: {minValue:0, maxValue:1000},
animation: {
duration: 1000,
easing: 'out'
}
};
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
var barsButton = document.getElementById('b1');
var lineButton = document.getElementById('b2');
function drawChart() {
var chart = new google.visualization.ColumnChart(document.getElementById('chart-div'));
data = google.visualization.arrayToDataTable(quarter);
chart.draw(data, options);
}
function drawLine() {
var line = new google.visualization.LineChart(document.getElementById('chart-div'));
data = google.visualization.arrayToDataTable(yearly);
line.draw(data, options);
}
barsButton.onclick = function() {
drawBars();
}
lineButton.onclick = function() {
drawLine();
}
drawChart();
}
</script>
[/CODE]
Unfortunately, it still doesn't work! Same issue! I don't know how the JSFiddle did it!
[editline]16th January 2014[/editline]
I don't know what happened to the above code paste, but it got really fucked up.
[editline]16th January 2014[/editline]
Please help! I'm dying!
[editline]16th January 2014[/editline]
Please help! I'm dying!
I am working on my portfolio but I am not sure what is suppose to contain. Could anyone give me some link to other's or yourself's portfolio so I could have a look at it. I also want it because I can't find developers portfolio.
[QUOTE=BoowmanTech;43559288]I am working on my portfolio but I am not sure what is suppose to contain. Could anyone give me some link to other's or yourself's portfolio so I could have a look at it. I also want it because I can't find developers portfolio.[/QUOTE]
I used to bookmark the best portfolios I came across:
[url=http://moreira.ch/]http://moreira.ch/[/url]
[url=http://www.matcheck.cz/]http://www.matcheck.cz/[/url]
[url=http://v2.desandro.com/]http://v2.desandro.com/[/url]
[url=http://www.jproductions.be/]http://www.jproductions.be/[/url]
[url=http://trevoro.net/]http://trevoro.net/[/url]
[url=http://brunobernardino.com/]http://brunobernardino.com/[/url]
I personally like the two last ones and recommend you do something along the lines of that.
[QUOTE=BoowmanTech;43559288]I am working on my portfolio but I am not sure what is suppose to contain. Could anyone give me some link to other's or yourself's portfolio so I could have a look at it. I also want it because I can't find developers portfolio.[/QUOTE]
It should showcase your work and tell people a little bit about your self and your process. It's also really important to showcase the kind of work that you want to continue doing, because that's the stuff you'll get hired for when people see your portfolio and decide to hire.
How can I get the automatically scroll ?
Ex: [url]http://www.jproductions.be/[/url]
[QUOTE=BoowmanTech;43560133]How can I get the automatically scroll ?
Ex: [url]http://www.jproductions.be/[/url][/QUOTE]
[url]https://developer.mozilla.org/en-US/docs/Web/API/Window.scrollTo[/url]
Or you can use some plugin, I don't know any but it's probably easy to Google one.
I am having a hard time wrapping my head around a few thingies here. I have only developed front-end, HTML/CSS and I have no idea how implementing something like Joomla (for example) into an already hosted website, works. Using 123reg and I need to quickly deploy a CMS for 4 websites and I have no idea where to start, or what fits where. Sorry if this is too vague I don't even know what I am asking really.
[QUOTE=zero_slo;43545374]A quick Ruby question.
How would i go about writing a method that works like this:
[CODE]
[2,4,3].rep {print "*"}
Output:
**
****
***
[/CODE]
I know I need to use yield, but I'm not quite sure how to access the array elements (2,4,3) from the rep function.
[editline]15th January 2014[/editline]
Nevermind, figured it out
[CODE] class Array
def rep
each do |v|
v.times { yield }
print "\n"
end
end
end
[1,2,1].rep {print "*"}[/CODE][/QUOTE]
I have to say in response to this that a) monkey patching core classes is not recommended, and b) block syntax is normally written as [1,2,1].rep { print "*" }, with spaces between the code and the brackets.
[editline]16th January 2014[/editline]
You could also do
[code]
puts [1, 2, 1].map { |x| "*" * x }.join("\n")
[/code]
How can I create a sort off active thing using CSS.
Example: When I click the button, that certain button will have something different and when I click another button that one will have something different.
I tried to use active but It didn't worked.
I don't understand the question.
I made it co complicated.
Basically if I click on a button I want it to show that you are on the current page.
[url=http://i.imgur.com/azkbiag.jpg][img]http://i.imgur.com/azkbiagl.jpg[/img][/url]
Is CodeAcademy a valid place to begin learning HTML? I've been looking into it for a while, and it seems alright, but would you guys recommend it, or are there better things/places?
[QUOTE=BoowmanTech;43562714]I made it co complicated.
Basically if I click on a button I want it to show that you are on the current page.
[url=http://i.imgur.com/azkbiag.jpg][img]http://i.imgur.com/azkbiagl.jpg[/img][/url][/QUOTE]
unless you're going to separately coded pages, you'll have to do some JS
if they're separate pages all you do is change the colour in the CSS with a new ID like #active-nav
[QUOTE=BoowmanTech;43562714]I made it co complicated.
Basically if I click on a button I want it to show that you are on the current page.
[url=http://i.imgur.com/azkbiag.jpg][img]http://i.imgur.com/azkbiagl.jpg[/img][/url][/QUOTE]
I would personally remake the header bar, some people will not like this though so here is some jquery.
Make a css class for all your buttons. This defines what they look like etc.
call this class my-button
All buttons should have this class.
Make another class selected-button
This class with define what the button looks like when it is pressed.
[code]
function resetButtons() {
$( ".my-button" ).each(function( index )
$( this ).removeClass( "selected-button" );
});
}
[/code]
Every time this function is called it will select all buttons with my-button class and remove the select-button. Effectively "deselecting" the button. You will need to call this before you give the clicked button this class. So something like this.
Give your button id = myButton
[code]
$( "#myButton" ).click(function() {
resetButtons();
$( this ).addClass( "selected-button" );
doOtherStuff();
});
[/code]
When you click element with id "myButton" it will first run the function to reset buttons, then it will add the "selected-button" class to that button, then finally run the function doOtherStuff() This will send your ajax or whatever it is you want it to do.
Abit messy. I'm sure somebody will give a neater answer.
[U]NOT FOR LAYOUT[/U]
But tables are cool for things that ACTUALLY need a table right?
Like comparing a long list of somewhat plantext data?
Should I just be fancy and use <li> and lots of CSS or are tables generally still okay to use in HTML5?
[QUOTE=lkymky;43570029][U]NOT FOR LAYOUT[/U]
But tables are cool for things that ACTUALLY need a table right?
Like comparing a long list of somewhat plantext data?
Should I just be fancy and use <li> and lots of CSS or are tables generally still okay to use in HTML5?[/QUOTE]
If your data is tabular, you should use a table.
Is there any better Django starter tutorial than the official polls one? I'm going through it and I'm just doing the steps while thinking "what the fuck am I doing".
[QUOTE=lkymky;43570029][U]NOT FOR LAYOUT[/U]
But tables are cool for things that ACTUALLY need a table right?
Like comparing a long list of somewhat plantext data?
Should I just be fancy and use <li> and lots of CSS or are tables generally still okay to use in HTML5?[/QUOTE]
An example of when a table would be the best solution:
[IMG]http://i.imgur.com/N2aoP2M.png[/IMG]
I want to insert text into mysql using php from a textarea the problem is when I use ' I get an error. How can I make it so before it sends it in the database it replaces all ' with \'
Use PDO's prepared statements or mysqli's string escaping method
[editline]17th January 2014[/editline]
And that should be done whenever you're dealing with user input and a database, not just in this instance. As it stands right now you can SQL inject your website.
[QUOTE=BoowmanTech;43575298]I want to insert text into mysql using php from a textarea the problem is when I use ' I get an error. How can I make it so before it sends it in the database it replaces all ' with \'[/QUOTE]
To directly answer your question you can use addslashes($string) and removeslashes($string) but there's a lot of different ways of inserting apostrophes into a mysql database and securing your queries, [B]but don't rely on addslashes for security at all![/B]
You can also use mysqli real_escape_string which escapes special characters in the query (There's more special characters than just apostrophes which will throw errors) - [URL]http://uk1.php.net/mysqli_real_escape_string[/URL]
But for the best security I suggest using prepared PDO statements - [URL]http://www.php.net/manual/en/pdo.prepare.php[/URL]
[QUOTE=seanm07;43575988]To directly answer your question you can use addslashes($string) and removeslashes($string) but there's a lot of different ways of inserting apostrophes into a mysql database and securing your queries, [B]but don't rely on addslashes for security at all![/B]
You can also use mysqli real_escape_string which escapes special characters in the query (There's more special characters than just apostrophes which will throw errors) - [URL]http://uk1.php.net/mysqli_real_escape_string[/URL]
But for the best security I suggest using prepared PDO statements - [URL]http://www.php.net/manual/en/pdo.prepare.php[/URL][/QUOTE]
Thanks for helped, I used mysqli_real_escape_string.
[QUOTE=BoowmanTech;43576123]Thanks for helped, I used mysqli_real_escape_string.[/QUOTE]
You should probably learn how to use PDO and get it over with.
Is there a web tooltip that works well, looks ok and most importantly, will work as soon as it is loaded on a page? I need one that can load like that due to me showing data on pages that load slowly.
How does one handle a countdown?
I I have a to date in my database, how can I get mail send when the current date reaches that date?
[QUOTE=gokiyono;43580377]How does one handle a countdown?
I I have a to date in my database, how can I get mail send when the current date reaches that date?[/QUOTE]
[URL=http://en.wikipedia.org/wiki/Cron]cron[/URL]
How to block folders from a website.
Ex: if you go on [url]www.website.com[/url] and you want to go in the images folder [url]www.website.com/images/[/url] how to make it so it's blocked and if you try that it will say you don't have permission or something like that.
If your website is on an Apache webserver you can use .htaccess files
[QUOTE=BoowmanTech;43583035]How to block folders from a website.
Ex: if you go on [url]www.website.com[/url] and you want to go in the images folder [url]www.website.com/images/[/url] how to make it so it's blocked and if you try that it will say you don't have permission or something like that.[/QUOTE]
[QUOTE=Banana Lord.;43583170]If your website is on an Apache webserver you can use .htaccess files[/QUOTE]
In the .htaccess file put:
[code]Options -Indexes[/code]
It'll prevent access to file directory listings.
Sorry, you need to Log In to post a reply to this thread.