minitauros 151 Junior Poster Featured Poster

E.g.

var element = $('div#id');

$(window).scroll(function()
{
    if(
        $(window).scrollTop() > element.offset().top + element.outerHeight() - $(window).height()
        && $(window).scrollTop() < element.offset().top + element.outerHeight()
    )
    {
        //* The element is visible. Do some stuff here.
    }
});
minitauros 151 Junior Poster Featured Poster

You want to add all the values in the columns on the right side? What about something like:

var total = (column_1 || 0) + (column_2 || 0) ... etc

?

minitauros 151 Junior Poster Featured Poster

You could use jQuery's $(window).scroll() function, which can execute a function on scroll. That function could then check what the screen's height is ($(window).height()), how far the user has scrolled from the top ($(window).scrollTop()) and then use those values in a calculation to see what part of the screen is visible.

minitauros 151 Junior Poster Featured Poster

Depending on what value you want to automatically get added, you could change the || 0 parts into a value of your choice, e.g. || 15 or || 3387.

minitauros 151 Junior Poster Featured Poster

It is called Javascript ;). It would work something like:

<script>
function activateLinkOne()
{
    displayMessage('Link 2 is disabled.');
    link1.activate();
    return false;
}
</script>

<a href="link.com" onclick="return false;">Link 1</a>
<a href="link2.com" onclick="activateLinkOne()">Link 2</a>

(Note that this code will not work; it is merely an example).

minitauros 151 Junior Poster Featured Poster

The problem with your code is that you are assuming that every field always has a value. However, undefined * something will always return NaN. It works the same as 0 * anything: 0 times anything is always 0. Example:

var a = undefined;
var b = 15;
var c = a * b;
console.log(c); // Outputs: NaN

var a = undefined || 0;
var b = 15;
var c = a * b;
console.log(c); // Outputs: 0

var a = undefined || 1;
var b = 15;
var c = a * b;
console.log(c); // Outputs: 15

Therefore, you could use the following code to not display NaN values, but a 0 instead of NaN if a field has not been filled in:

var amount;

function doCal() {
    var nValue = document.getElementById("noofnights").value;
    var nValue1 = document.getElementById("rate").value;
    amount = parseFloat((nValue * nValue1)) || 0;
    document.getElementById("total").value = amount;

    var nValue2 = document.getElementById("noofnights1").value;
    var nValue3 = document.getElementById("rate1").value;
    amount = parseFloat((nValue2*nValue3)) || 0;
    document.getElementById("total1").value = amount;

    var nValue4 = document.getElementById("noofnights2").value;
    var nValue5 = document.getElementById("rate2").value;
    amount = parseFloat((nValue4*nValue5)) || 0;
    document.getElementById("total2").value = amount;

    var nValue6 = document.getElementById("noofnights3").value;
    var nValue7 = document.getElementById("rate3").value;
    amount = parseFloat((nValue6*nValue7)) || 0;
    document.getElementById("total3").value = amount;

    var nValue8 = document.getElementById("noofnights4").value;
    var nValue9 = document.getElementById("rate4").value;
    amount = parseFloat((nValue8*nValue9)) || 0;
    document.getElementById("total4").value = amount;

    var nValue10 = document.getElementById("noofnights5").value;
    var nValue11 = document.getElementById("rate5").value;
    amount = parseFloat((nValue10*nValue11)) || 0;
    document.getElementById("total5").value = amount;

    var nValue12 = document.getElementById("noofnights6").value;
    var nValue13 = document.getElementById("rate6").value;
    amount = parseFloat((nValue12*nValue13)) || 0;
    document.getElementById("total6").value = amount;

    //total amount
    totalamount = …
minitauros 151 Junior Poster Featured Poster

So are you then asking how you can loop through the submitted answers, or how you can write a loop in JSP? :) I thought this would be a theory-only question so with my knowledge of PHP I thought I'd be able to answer it. I'm not so good at JSP so let me give you an example of how you'd do this in HTML/PHP, to give you an idea of the workflow you could use.

Your HTML would look like:

<form>
    <div class="section">
        <div class="question">
            <p>Question: ...</p>
            <input type="text" name="questions[your_question_id]">
        </div>
        <div class="answer">
            <p>Answer:</p>
            <input type="text" name="answers[your_question_id]">
        </div>
    </div>

    <!-- A question with multiple answers: -->
    <div class="section">
        <div class="question">
            <p>Question: ...</p>
            <input type="text" name="questions[your_question_id]">
        </div>
        <div class="answer">
            <p>Answer 1:</p>
            <input type="text" name="answers[your_question_id][]">
        </div>
        <div class="answer">
            <p>Answer 2:</p>
            <input type="text" name="answers[your_question_id][]">
        </div>
    </div>
</form>

If submitted, in PHP (so I think also in JSP) you would get an array like this:

answers => array(
    1348 => answer,
    143 => array(
        answer1,
        answer2
    )
)

The keys being the question ID's, with the values being the answers. You'd then loop through them using a loop of choice and execute the appropriate queries to insert the answers into your database. With this knowledge that would mean that in this query:

"insert into answer(answer,user_id,survey_id,question_id) values('" + ans + "','" + userid + "','" + sid + "',(select question_id from question where survey_id='"+sid+"'))"

you wouldn't need that subquery, because you already have knowledge of the question ID's …

minitauros 151 Junior Poster Featured Poster

Oh yes, of course :). Well I thought my HTML alone would be able to solve your problem. The course of action is:

  1. Get questions data (id, question, etc).
  2. List the questions (see the HTML example I provided).
  3. Submit the form.
  4. On the target page, parse the form data and insert the data into the database.

Is anything in any of these steps not working or unclear, or do you need help with any of them? :)

minitauros 151 Junior Poster Featured Poster

Oh sorry I thought that my answer had already solved your problem ^^. What I meant was (if I understand your case correctly) something like this:

<?php
// Retrieve questions. Something like:
$q = 'SELECT id,
        ...
    FROM questions
    ...';

// Handle the query... (I suppose you have code for this already)
?>

<form action="submit.php" method="post">
    <div class="entry">
        <p>Question 1: ...</p>
        <input type="text" name="answers[1]"><!-- 1 is the ID of the question here -->
    </div>
    <div class="entry">
        <p>Question 2: ...</p>
        <input type="text" name="answers[4]"><!-- 4 is the ID of the question here -->
    </div>
    <input type="submit" value="Submit">
</form>

On submit.php you will now receive an array called $_POST['answers'], of which the keys are the question ID's and the values are the answers to those questions.

minitauros 151 Junior Poster Featured Poster

That is true, but if you use time() as a base for your random image name, the chances that you will get a non-unique name are pretty small :).

minitauros 151 Junior Poster Featured Poster

Well your form is not being displayed in the way it should be, I think, in my browser (Firefox, 1920x1080px), but I think I get the point of it!

What about using code like this?:

var total_tax;

$('table tbody#item_rows tr.item-row').each(function()
{
    // Do we need to calculate tax for this row?
    var is_taxable = $(this).find('input.taxable').is(':checked');

    if(is_taxable)
    {
        // Get the subtotal amount that must be payed for this row.
        var subtotal_price = $(this).find('textarea[name^=costbox]').html();
        subtotal_price = parseInt(subtotal_price);

        // Calculate tax.
        var tax_percentage = 0.2;
        var tax = subtotal_price * tax_percentage;

        // Remember the total amount of tax that needs to be payed.
        total_tax += tax;
    }
});

I don't think this code will work straight away; it's just to give you an idea of what I think you could do. Am I understanding what you mean correctly now? ^^

minitauros 151 Junior Poster Featured Poster

Maybe you could temporarily disable the header? :)

minitauros 151 Junior Poster Featured Poster

Well let's say the name of these checkboxes will be omit_from_tax_calculation. You could then traverse your <tr> elements and find this checkbox, and see if it is checked. Like so:

var taxes = [];
var is_checked = false;

$('tr.your_selector').each(function()
{
    is_checked = $(this).find('input[name=omit_from_tax_calculation]').is(':checked') || false;
    if(!is_checked)
    {
        // This <tr> should be included in the tax calculation.
        taxes.push($(this).find('input.your_selector').val());
    }
});

// "taxes" now contains all the values of the <input> elements of your choosing
// which should be included in the tax calculation

I'm not sure I understand your problem 100% correctly (yet), but I think we're making progress :p.

minitauros 151 Junior Poster Featured Poster

Well, you could, of course, check the value of $error_message to see if the if() statement gets triggered. What does a var_dump($error_message); above the if() statement do?

minitauros 151 Junior Poster Featured Poster

Well it seems like you already have some code. Is that not working correctly or? Checking if a checkbox is checked, by the way, can be done properly and easily by using .is(':checked') (jQuery, returns true or false).

minitauros 151 Junior Poster Featured Poster

Well if you have stored information about where these files are saved with your link, I guess you could retrieve this information when you delete the link, and delete the related files with it?

You can use the unlink() function for deleting files :).

minitauros 151 Junior Poster Featured Poster

First of all: are you then sure that your query is being executed?

Secondly: seems to me like a query problem, but I'm not sure! Have you tried either

$query = 'INSERT INTO ".$mysql_table." SET username = :username, password = :password, fullname = :fullname, email = :email, role = :role, active = :active, code = :code';

or

$query = 'INSERT INTO ".$mysql_table." (
        username,
        fullname,
        email,
        role,
        active,
        code
    ) VALUES (
        :username,
        :password,
        :fullname,
        :email,
        :role,
        :active,
        :code
    )';

?

minitauros 151 Junior Poster Featured Poster

A little help with that code:

header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="export.csv"');

These headers are sent to the browser, invisible to the end user. A browser always receives headers from a web server, telling it what kind of stuff it is working with. In this case the headers tell the browser that a text/csv file is being given to it, and that it should be offered to the user as a download called export.csv.

minitauros 151 Junior Poster Featured Poster

In addition to that example, you could generate your own unique image names using some random numbers and time variables. Example:

<?php
$extension = ''; // Make sure you get the extension of the upload image.
$random_image_name = md5(mt_rand(0, 100) . time() . mt_rand(0, 100)) . $extension;
minitauros 151 Junior Poster Featured Poster

Apparently your $row_panier['subtotal'] has no value. I guess you could start by finding out why that is =).

minitauros 151 Junior Poster Featured Poster

Nice piece of code :). @topic starter: Just don't forget to contain your database code within a try-catch block if you set PDO's errmode to PDO::ERRMODE_EXCEPTION, as in gabrielcastillo's example.

minitauros 151 Junior Poster Featured Poster
if (mysql_num_rows($userquery) != 1) /* I think this line is the problem but how to i fix this */
{
    die ("that member could not be found!");

These lines are saying: If not exactly one record is found, stop the script. Why don't you use this instead?:

if (mysql_num_rows($userquery) < 1)
{
    die ("that member could not be found!");
}
else
{
    // Your script goes here.
}

On top of that you could add a LIMIT 1 to this query: $query_Recordset1 = "SELECT first_name, last_name, email, password, sex FROM members"; as you seem to be selecting only the first retrieved result in the next lines.

minitauros 151 Junior Poster Featured Poster

So the user has to check some checkboxes, of which the values will then be converted to .csv and offered as a download? Or are there multiple .csv's available for download, and does the user have to select which of those he wants to download?

minitauros 151 Junior Poster Featured Poster

I guess you could use document.getElementById('loginstate').setAttribute('href', 'url');?

minitauros 151 Junior Poster Featured Poster

So you have something like:

questions
id INT PRIMARY KEY AUTO_INCREMENT

and

answers
id INT PRIMARY KEY AUTO_INCREMENT
question_id INT
FOREIGN KEY (question_id) REFERENCES (questions.id)

right? And you need to know the ID of a question when you insert an answer? It seems to me that the ID of that question should be known at that point, and that it should be set in an <input> element of the form that is used to submit an answer. Am I understanding this correctly? :)

minitauros 151 Junior Poster Featured Poster

Sorry man then I have no idea what else you could do :\ . I hope someone else can help..

minitauros 151 Junior Poster Featured Poster

Yes of course :). Note that in order for this to work you need to have loaded jQuery.

// As soon as the document becomes ready we want to execute a function. We cannot
// do this earlier, as our target elements won't exist yet when the Javascript is 
// parsed.
$(document).ready(function()
{
    // When the select with the ID of "id" changes, we want to execute a function.
    $('select#id').change(function()
    {
        // Let's get the value of the selected option.
        var value = $(this).val();

        // And let's then set the innerHTML of the <span> (which is what goes 
        // between the <span> and </span> tags) with the ID of "id" to
        // be that value.
        $('span#id').html(value);
    });
});
minitauros 151 Junior Poster Featured Poster

What about something like:

$(document).ready(function()
{
    $('select#id').change(function()
    {
        var value = $(this).val();
        $('span#id').html(value);
    });
});
minitauros 151 Junior Poster Featured Poster

Have you tried reinstalling XAMPP? Maybe in another folder? Run it with admin privileges?

minitauros 151 Junior Poster Featured Poster

Do you want an AJAX request to be executed when that happens? And do you maybe have some more information about the case? Like what does the <select> element look like, and how does the percentage get calculated?

minitauros 151 Junior Poster Featured Poster

I don't think it will give you any more info, but have you checked the "Netstat" window of XAMPP? (It's on the right side in the control panel and might give you some more information).

Also, I have no idea if it might work, but if (in your XAMPP control panel) you click the "Config" button for your Apache server, you can open "httpd.conf". In that file, there's a line that says "Listen 80" (for me). Maybe you could change the port to something other than 80 and see if that works. I know it's not the 443 port that you're changing, while that IS the one that is causing you troubles, but I can't find where the 443 port is coming from myself, so I wouldn't know where to look to change it.

For the rest I don't think I can help you :(.

minitauros 151 Junior Poster Featured Poster

Pfew this maybe is a pretty vague description of your problem ^^. Could you be a bit more specific please?

You have two database columns which both have an INT field set as primary key, of which the one references to the other? And you want to store which value in what table?

minitauros 151 Junior Poster Featured Poster

Could you add the following code right before your Total input and tell us what it says?

<?php
echo '<p>$shipping1 is now:';
var_dump($shipping1); echo '</p>';

echo '<p>$row_panier[subtotal] is now:';
var_dump($row_panier['subtotal']); echo '</p>';

echo '<p>The same stuff, number formatted is now:';
var_dump(number_format($shipping1 + $row_panier['subtotal'], 2, '.', '')); echo '</p>';
minitauros 151 Junior Poster Featured Poster
1:06:52 PM [Apache] Problem detected!
1:06:52 PM [Apache] Port 80 in use by "Unable to open process" with PID 4!
1:06:52 PM [Apache] Apache WILL NOT start without the configured ports free!
1:06:52 PM [Apache] You need to uninstall/disable/reconfigure the blocking application
1:06:52 PM [Apache] or reconfigure Apache and the Control Panel to listen on a different port

This means that the process with Process ID 4 is operating on a port Apache is configured to use. You can either reconfigure Apache to use another port (but god I wouldn't know how :p), or press ctrl + alt + delete, go to the "Details" tab and check which process has Process ID 4, and halt that process (this is in windows 7/8).

I have no idea why Apache is emitting this error, though:

1:21:03 PM [Apache] Error: Apache shutdown unexpectedly.
1:21:03 PM [Apache] This may be due to a blocked port, missing dependencies,
1:21:03 PM [Apache] improper privileges, a crash, or a shutdown by another method.
1:21:03 PM [Apache] Press the Logs button to view error logs and check
1:21:03 PM [Apache] the Windows Event Viewer for more clues
1:21:03 PM [Apache] If you need more help, copy and post this
1:21:03 PM [Apache] entire log window on the forums
minitauros 151 Junior Poster Featured Poster

Well same to you ^^.

minitauros 151 Junior Poster Featured Poster

What about hosting a website locally, for testing purposes? You could maybe tell something about WAMP/XAMPP/LAMPP etc., which enables you to test your PHP websites locally, without having to pay for a hosting provider? :)

minitauros 151 Junior Poster Featured Poster

Try replacing <link rel="style" href="main.css" > with <link type="text/css" rel="stylesheet" href="main.css">, and check if main.css is in the same folder as your main.html =).

minitauros 151 Junior Poster Featured Poster

What is the error that is being caused?

minitauros 151 Junior Poster Featured Poster

I disagree on that you NEED a color picker, and there are a lot more resources that can help you to learn how to code. Maybe you could expatiate on all these subjects a bit more? Because I don't think this short post gives someone who wants to start coding enough information to do so :o.

minitauros 151 Junior Poster Featured Poster

Well I'm not so fond of storing images in a database, because I don't think that's what a database is for. If you absolutely need to store images in a database I suggest you check out the base64_encode() and base64_decode() functions.

I would however still suggest saving the images in a directory on your server. You can use move_uploaded_file() to save an uploaded image (uploaded through a form) on your server.

minitauros 151 Junior Poster Featured Poster

Why are you uploading images to your database? Wouldn't it be much easier to just upload the images to a specific destination on your server, and then insert the location of that image into your database? E.g. you save your images in /uploads/images and you then save the location of a specific image in your database. For example an image called "image1.jpg" would be saved as "/uploads/images/image1.jpg" and saved as "/uploads/images/image1.jpg" in your database.

minitauros 151 Junior Poster Featured Poster

Well, reading your post I'm assuming this is your problem:

In Javascript you have an array with values (var chart in your example), which you want to be converted to a string and then to be set as the value of a specific input checkbox. This can be achieved as follows:

var array = [[1,23 ],[20,70],[40,100],[64,120]];

for(var i = 0; i < array.length; i++)
{
    var record = array[i].join();
    array[i] = record;
}

var string = array.join('|');
// String now has the value "1,23|20,70|40,100|64,120"

To set your input's value to be this value, you can use one of the following snippets, depending on if you're using jQuery or not:

// Non jQuery:
document.getElementById('val').value = string;

// jQuery:
$('input#val').val(string);
minitauros 151 Junior Poster Featured Poster

I've never used this API before and this might sound really really dumb, but have you tried using the keyword "flying" instead of "fly"? (Since you're also talking about driving, walking)

minitauros 151 Junior Poster Featured Poster

That sounds like some basic Javascript (I would suggest jQuery) tutorials. I would say: check out these pages:

http://www.w3schools.com/jquery/ (If you have never worked with jQuery before)
http://www.w3schools.com/jquery/jquery_ajax_intro.asp (Introduction to jQuery's AJAX functions)
http://api.jquery.com/jQuery.ajax/ (The jQuery ajax() function)

minitauros 151 Junior Poster Featured Poster

Well I cannot think of any smoother way to achieve that using jQuery, except... maybe...

What if you place the text you want to search inside a <p> element, and then use is.(':contains(test)') on that <p>? :) That way you can ignore the <select>.

minitauros 151 Junior Poster Featured Poster

Well, your checkboxes will not be in the $_POST['hidden'] array if they have not been checked. Therefore you cannot set them to 0 using a foreach() loop the way you are using it. You will somehow need to compare the checked checkboxes against the present checkboxes, and work with the difference. Or, you could create two checkboxes: one called "show" and one called "hide", and use those to determine the action of your query.

minitauros 151 Junior Poster Featured Poster

It's probably this:

You use while($row = mysql_fetch_array($result)) to fetch your data, so you cannot use $_SESSION["valid_id"] = $row->id; (an object) to access the fetched data. You should use $_SESSION["valid_id"] = $row['id']; (an array), since you are working with an array, not an object.

Indians commented: you are good at code. its working now. thanks. next i need to do upload employee image and then need to fetch. if i have any doubt i will ask you... +1
minitauros 151 Junior Poster Featured Poster

Can't you just post the error messages here? :o Doesn't feel very safe having to download that stuff for no apparent reason (but that could be me..).

minitauros 151 Junior Poster Featured Poster

A working solution, although maybe not the fastest, could be:

$(this).find('td:nth-child(2)').each(function()
{
    // Create a clone of the <td>, so that we can modify its contents.
    var clone = $(this).clone();

    // Remove the <select> from the cloned <td>, so that we can properly use
    // the :contains selector.
    clone.find('select').remove();

    // Check if the clone contains value X.
    if(clone.is(':contains(' + fValue + ')'))
    {
        $(this).closest('tr').show();
        bFound = true;
    } 
    else
    {
        $(this).closest('tr').hide();
    }
});
minitauros 151 Junior Poster Featured Poster

Well, for as far as I know the ? indicates the start of a query string, while & indicates the start of a new key/value pair inside that query string. E.g.:

website.com?key=value&key2=value2&this=that

The ? indicates the start, the & separates the key/value pairs.