minitauros 151 Junior Poster Featured Poster

I guess something like this should work:

$('table#your_table_id tr').not(':first').remove();
minitauros 151 Junior Poster Featured Poster

If you tell jQuery to element.after('<tr>');, the <tr> part is interpreted as "<tr></tr>" (as a whole tag). Therefore you should use another way to create the table you want. For example (with example data):

var table = $('table#table_id');
var tr = $('<tr>');
var td;

// Create a <td> tag, fill it with text and prepend it to the <tr>.
td = $('<td>');
td.html = 'text';
td.prependTo(tr);

// Create another <td> tag, fill it with text and prepend it to the <tr>.
td = $('<td>');
td.html('text2');
td.prependTo(tr);

// Append the <tr> to the table.
tr.appendTo(table);
minitauros 151 Junior Poster Featured Poster

This is not an error, not a warning, but merely a notice. It seems to be caused by $_POST['check'] not being defined, while your script is trying to access it. You can modify which errors are being reported by using the error_reporting() function, if you wish to not display notices, but (for example) only warnings and fatal errors. Besides using error_reporting(), you can also modify the error reporting value in your php.ini file (if I'm not mistaken).

minitauros 151 Junior Poster Featured Poster

Okay, good luck then!

minitauros 151 Junior Poster Featured Poster

Glad that it's working :). But why are you executing the exact same query twice? Seems like you can re-use the result stored in $count1_result instead of having to create $result2.

minitauros 151 Junior Poster Featured Poster

Hmm well, taking that I assume that you will be working with a huge bunch of rows, and that you will probably need to build pagination possibilities.

What you could do is the following:

SELECT *
FROM login
ORDER BY user ASC,
date DESC
LIMIT 50 -- Example limit

This will simply select the first 50 logins from the logins table, starting with the usernames starting with an A, moving up to the Z. Per username the results will be ordered by date.

Then you could use PHP to traverse to the results and display everything you need. For example:

<?php
if($results) {
    foreach($results as $result) {
        $date = $result['date'];
        $username = $result['username'];
        $status = $result['status'];
        $display_username = false;

        if(!$last_used_username || $username != $last_used_username) {
            //* Either we're working with a new username, or this is the first row.
            $display_username = true;
        }

        $last_used_username = $username;
        ?>
        <tr>
            <td>
                <?php if($display_username) echo $username; ?>
            </td>
            <td>
                <?php echo $date; ?>
            </td>
            <td>
                <?php echo $status; ?>
            </td>
        </tr>
        <?php
    }
}

Would this be of any help?

minitauros 151 Junior Poster Featured Poster

Well, it appears to me that he then wants the most recent logins, not necessarily grouped by username. You could solve this problem by simply retrieving the last x number of rows and displaying those one by one. You could use the DISTINCT() selector to select only unique usernames. E.g. SELECT DISTINCT(username), * FROM logins ORDER BY date DESC.

Would that be a solution to your problem?

minitauros 151 Junior Poster Featured Poster

What abouuuut you select the logins only for the user that is logged in? :) For example SELECT * FROM logins WHERE user = "julius".

You will then only fetch the login records for that user, which you can display one by one.

Alternatively, you can use an ORDER BY clause to sort your results per user, or per date. E.g. SELECT * FROM logins ORDER BY user ASC, date DESC to sort by the username (ascending) first, and then by the login date (descending) second.

minitauros 151 Junior Poster Featured Poster

I guess that the problem is that you are trying to display XML as XML in an HTML document.

It works like this: Your HTML document has already told your browser it's an HTML document. Therefore your browser will treat your document as an HTML document. If you want the XML to be displayed as how a plain XML file would be displayed if you'd open it with your browser, you need to create a whole new browser window and tell that window that it is an XML - not an HTML - file it should display, and then output the XML.

As M.Qawas Aslam says, using an iframe might do the trick. If that doesn't work, I suggest you open a whole new tab or browser window to display the XML. Or, alternatively, you could search for options to display XML as XML without opening a new window.

M.Waqas Aslam commented: Thanks for explanation :) +7
minitauros 151 Junior Poster Featured Poster

Yes, so that basically means that the returned value is NOT an integer, right? :) So that means that you are comparing a non-integer against an integer, which is why your if() statement isn't working as you want it to. I guess you'll first need to convert the returned value ("+1 day") to an integer, and then throw it into your if() statement.

minitauros 151 Junior Poster Featured Poster

Well, according to the examples in the manual, DateDiff::format() does not always return an integer. That's why I said: you should check what it is returning, because you're comparing it against an integer, and you cannot really compare a string value against an integer. If you know what I mean :). Maybe you can find another way to find out if this is what is happening, if var_dump() isn't returning anything (which I find weird, 'cause for as far as I know it always returns something and prints it on the screen).

minitauros 151 Junior Poster Featured Poster

You should place the var_dump($verscil_huwelijksdat_tot_zestien_jaar->format('%R%a')); line before the if statement if you want to make sure it is executed :). Does it return an integer, a boolean, or something else? And what exactly?

minitauros 151 Junior Poster Featured Poster

I'm not sure, but I don't think that that function is returning an integer, which is what you are comparing it against.

I suggest you check out what exactly is being returned by the format() function, e.g.:

var_dump($verscil_huwelijksdat_tot_zestien_jaar->format('%R%a'));
minitauros 151 Junior Poster Featured Poster

You start a session with session_start(). That should probably be one of the first lines, if not the first line, of any of your files in which you want to use the session.

Then, after starting the session, you can save values to it or retrieve values from it, using $_SESSION. E.g.:

Page 1:

<?php
session_start();
$_SESSION['test'] = 'hello';

Page 2:

<?php
session_start();
echo '<p>The session value for test is now: ' . $_SESSION['test'] . '</p>';

Hope that helps a bit ;). If not, have you tried searching Google for tutorials on PHP sessions?

minitauros 151 Junior Poster Featured Poster

Not sure but I think it's not recommended you place HTML elements outside your <body> tags (which is what your CSS is doing with the black bar).

minitauros 151 Junior Poster Featured Poster

In line 2, you are comparing session to null. However, firstly, there is an error in your code here, as "session" is no PHP language. It should either be $session or $_SESSION. If you want to check if a session has been started, I recommend you use session_id() to check that, instead of just $_SESSION.

Secondly, you are now returning some HTML. I would rather return true or false, and then echo some HTML according to if true or false is returned when you execute the function.

Third, you are not executing your function correctly in your HTML. Instead of executing the function, you are redefining it. You could try this:

<?php
public function isLoggedIn() 
{
    if(!session_id()) {
        // No session ID has been set.
        return false;
    }
    else {
        // Session ID has been set.
        return true;
    }
}
?>

<ul>
    <li><a href="index.php">Home</a></li>

    <?php
    $is_logged_in = isLoggedIn();

    if($is_logged_in) {
        echo '<li><a href="login.php">Login</a></li>';
    }
    else {
        echo '<li><a href="logout.php">Logout</a></li>';
    }
    ?>

    <li><a href="allstock.php">All Our Stock</a></li>
</ul>
minitauros 151 Junior Poster Featured Poster

If you are still looking for a regex, something like this might work:

/\[url\](?!\[url\])(.*?)\[\/url\]/is

It returns only [url] tags that are not followed by another [url] tag.

minitauros 151 Junior Poster Featured Poster

You could use mysql_real_escape_string() to escape all necessary characters within stuff you insert, I guess. E.g.

INSERT ... VALUES (mysql_real_escape_string($your_value), mysql_real_escape_string($your_value_2)) etc.

minitauros 151 Junior Poster Featured Poster

Maybe the varchar (225) kicks in here. Does the article that you are submitting not exceed the field's maximum storage size (225)?

minitauros 151 Junior Poster Featured Poster

Ok so let's clear this up a little bit. You have a page called index.php. It retrieves data from your database. Now which ID do you want to use on page 2, and how do you get to page 2? Do you get there by submitting a form, clicking a link, something like that?

Using the session to save a variable goes as follows, in case you need to use it:

  1. At the start of your page, place the session_start(); command.

  2. You can now save anything on your page in $_SESSION['your_key_name'], e.g. $_SESSION['user_id'] = $user_id;.

  3. You can now also access session information on your page. Let's say that on a previous page you have saved something in $_SESSION['page_id']. You can now access that variable by simply using $_SESSION['page_id'];, e.g. echo $_SESSION['page_id'];.

minitauros 151 Junior Poster Featured Poster

Index page:

<?php
session_start();
echo '<p>Your session id is: ' . session_id() . '</p>';

Other page:

<?php
session_start();
echo '<p>Your session id is: ' . session_id() . '</p>';

See if they match if you will ;).

minitauros 151 Junior Poster Featured Poster

Hm I don't know about using it in that way, actually, just thought I'd help you out with something of which I know for certain that it works. Are you allowed to declare functions without brackets, by the way? :O

minitauros 151 Junior Poster Featured Poster

For as far as I know, the css() function only accepts two parameters, being index and value. E.g. you would execute css('width', 420). I'm not completely sure though, but I can provide you with an example of which I'm sure it works:

var new_width = $('#div').width() + 120;
$('#div').css('width', new_width);

Be sure to also check out the innerWidth() and outerWidth() functions! :) Hope this helps!

minitauros 151 Junior Poster Featured Poster

What's going wrong? :)

minitauros 151 Junior Poster Featured Poster

What about modifying your query just a little bit, to:

SELECT * FROM dbAdd WHERE add_city = '" . mysql_real_escape_string($wil) . "' ORDER BY add_city DESC LIMIT 200

minitauros 151 Junior Poster Featured Poster

Have you tried what has been posted here (StackOverflow)?

minitauros 151 Junior Poster Featured Poster

Your query seems to be incorrect. You should probably not use WHERE $add_city but WHERE add_city (without the $).

Besides that, a COUNT() query might be more efficient here. E.g.:

<?php
$q = 'SELECT COUNT(add_city) AS c FROM dbAdd WHERE add_city = "' . mysql_real_escape_string($wil) . '"';
$rq = mysql_query($q);
$fetch = mysql_fetch_assoc($rq);
$count = $fetch['c'];
minitauros 151 Junior Poster Featured Poster

Well, if you need only one record from the tblStudents table, and multiple records from the tblGrades table, I suggest you just perform two queries. The first query will retreive the student info from the tblStudents table. Then, with the studentId that was retrieved, the second query retrieves the student's grades from the tblGrades table. You will have to merge the arrays with PHP or whatever language you are using to display the results. Example:

<?php
$q = 'SELECT StudId,
        LastName,
        FirstName
    FROM tblStudents';

// Let's say the results of that query were stored in $students.
// We will first prepare a query to retrieve each student's grades.
// Guessing and hoping you are using for example PDO or mysqli, you will understand
// the following query (with the questionmark in it).
$q = 'SELECT SubjectCode,
        Grade
    FROM tblGrades
    WHERE StudId = ?
    ORDER BY SubjectCode ASC';

foreach($students as &$student)
{
    // The query is executed here. Let's say the results are stored in $grades.
    // We will add the grades to the current student now:
    $student['grades'] = $grades;
}

// The $students array now contains info about the students and their grades.
echo '<p>Students and grades:</p><pre>'; print_r($students); echo '</pre>';
minitauros 151 Junior Poster Featured Poster

You're welcome :). Glad you got it to work.

minitauros 151 Junior Poster Featured Poster

UPDATE saudi_journal SET AU ='' WHERE RID = '3'

This query sets AU to null (removes its value). You should make sure $AU has a value in your script (so that AU = '"$AU"' will actually work) :).

minitauros 151 Junior Poster Featured Poster

Well, have you checked if the variables you are using in your query actually have a value? Does echo-ing your query show anything particular? E.g. what does echo $query; say? Are the variables filled in, or are they empty?

minitauros 151 Junior Poster Featured Poster

Well I guess then you'd have to assign the URL you want to add to a record to a variable, like $url = 'your_url', and then update your database, for example 'UPDATE table_name SET url = "' . mysql_real_escape_string($url) . '" WHERE fill_in_key = "' . mysql_real_escape_string($key) . '" (this looks like your current query).

minitauros 151 Junior Poster Featured Poster

Well, it could be because you're not actually specifying a value to update your record with. You could try this to see if an error is generated. If not, I guess it's your query that is using faulty data.

$RID = $_POST['RID'];
$AU = $_POST['AU'];
$TI = $_POST['TI'];
$SO = $_POST['SO'];

// In your query, $FULTEXT is probably null, or does it get defined somewhere else?
$query = "UPDATE saudi_journal SET FULTEXT = '$FULTEXT' WHERE RID = '$RID'";

echo '<p>The query that was executed, is as follows:<br>' . $query . '</p>';

mysql_query($query);
$error = mysql_error();

if($error)
    echo $error;
else
    echo "<center>Successfully Updated in DATABASE</center>";
minitauros 151 Junior Poster Featured Poster

Woops, my bad :). The first if() statement is not doing a proper check. It should be

if(!$_POST['form_name'])
minitauros 151 Junior Poster Featured Poster

Could you replace the last elseif() construction by the following?

elseif($_POST['form_name'] == 'update')
{
    //* The update form has been submitted. Update the database.

    // Let's see if we actually arrive at this part:
    echo '<p>Run the update...</p>';

    $RID = $_POST['RID'];
    $AU = $_POST['AU'];
    $TI = $_POST['TI'];
    $SO = $_POST['SO'];
    $query = "update saudi_journal SET FULTEXT='$FULTEXT' WHERE RID='$RID'";
    mysql_query($query);
    echo "<center>Successfully Updated in DATABASE</center>";
}

And could you add the following line BEFORE the first if() statement?

echo '<p>The following data has been submitted:</p><pre>'; print_r($_POST); echo '</pre>';

It should give you some more info on what is happening, so that you can trace why it's not working as you want it to.

minitauros 151 Junior Poster Featured Poster

Oh I see there is still a if (isset($_POST['submit'])) line in the second elseif() statement. You could remove that - the if() statement that comes a couple of lines earlier should do the work.

Are you getting any errors or is it just not updating?

You don't have to name any of the forms. I have included a hidden <input> in each form, that holds its name. That's what is being checked :).

minitauros 151 Junior Poster Featured Poster

Please read my post carefully again, as I think you might benefit from it in the future. If you have questions about it, feel free to ask! Here's an example of what you could do:

<?php
/***********************************************************************
Create database connection
*/

$db_host="localhost";
$db_name="";
$db_user="";
$db_pass="";
$conn = mysql_connect($db_host, $db_user, $db_pass) or die (mysql_error());

// Select database. Your line - mysql_select_db("$db_name"); - was okay, but you don't need to use
// quotes here :).
mysql_select_db($db_name);


/***********************************************************************
HTML output
*/
?>

<html>
<head>
    <meta name="description" content="Php Code Search & Display Record" />
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>

    <?php
    // Find out which form/action we need to load. I have created some
    // hidden input fields to help identifying the forms.
    if(!$_POST['search'])
    {
        //* No search query has been submitted yet. Display the search form.
        ?>

        <form name="search" method="post" action="search.php">
            <input type="hidden" name="form_name" value="search">
            <table style=" border:1px solid silver" cellpadding="5px" cellspacing="0px" align="center" border="0">
                <tr>
                    <td colspan="3" style="background:#0066FF; color:#FFFFFF; fontsize: 20px">
                        Search
                    </td>
                </tr>
                <tr>
                    <td width="140">Enter Search Keyword</td>
                    <td width="240"><input type="text" name="search" size="40" /></td>
                    <td width="665"><input type="submit" value="Search" /></td>
                </tr>
                <tr bgcolor="#666666" style="color:#FFFFFF">
                    <td>Record ID</td>
                    <td>Description</td>
                    <td> </td>
                </tr>
            </table>
        </form>

        <?php
    }
    elseif($_POST['form_name'] == 'search' && $_POST['search'])
    {
        //* The search form has been submitted. Display the update form(s).
        $search = $_POST["search"];
        $result = mysql_query("SELECT * FROM saudi_journal WHERE SO like '%$search%'")or die(mysql_error());

        while($row = mysql_fetch_array($result))
        {
            ?>
            <form action="search.php" method="post">
                <input type="hidden" name="form_name" value="update">
                <input type="text" name="RID" value="<?php echo $row['RID'];?>" size=6>
                Author
                <input type="text" name="author" value="<?php echo $row['AU'];?>">
                Title …
minitauros 151 Junior Poster Featured Poster

I would like to suggest a (in my opinion) cleaner solution :). This solution is as follows:

  1. Create a database file, in which you create your database connection, etc. You can include that file in every file that you need a database connection in. This way, you don't need to modify your database connection related code in every file if you once decide to change your database info. You can include a file using PHP's include(), include_once(), require() or require_once() functions. Look them up on php.net ;).

  2. I myself like to have separate files for each action/process, but in this particular situation, I guess you could have 2 forms on one page, and have the one that matches the action (e.g. update) be shown. That would go, for example, as follows (this is actually pretty much the same as vipula suggests):

    <?php
    // Include the file that manages your database connection.
    include('includes/database_connection.php');
    
    // Find out if we need to display the search form or the update form.
    if($_POST['search'])
    {
        //* A search query has been given. Display the update form.
    
        // Perform queries.
        $query = 'SELECT ...';
        // etc..
        ?>
    
        <form>
            <!-- Display your HTML stuff here... -->
        </form>
    
        <?php
    }
    else
    {
        //* A search query wasn't given. Display the search form.
    
        // Perform queries.
        $query = '';
        // etc...
        ?>
    
        <form>
            <!-- Display your HTML stuff here... -->
        </form>
    
        <?php
    }
    
minitauros 151 Junior Poster Featured Poster

I suppose something like this should work:

$_SESSON['username'] =  $result[0]['username'];
$_SESSON['fullname'] =  $result[0]['fullname'];
minitauros 151 Junior Poster Featured Poster

I haven't done this with editable <div>s before, but usually you get a div's content by using div.innerHTML, not div.value. So changing your code to

function maths()
{
    var qt = document.getElementById("quantity1").innerHTML;
    var up = document.getElementById("unitprice1").innerHTML;
    qtup = parseFloat((qt * up)) || 0;
    document.getElementById("total1").innerHTML = qtup;
}

might work. Why are you using editable <div>s instead of just inputs? :o

minitauros 151 Junior Poster Featured Poster

I think you could add

RewriteRule ^product.php/([a-zA-Z0-9]+)$ product.php?id=$1

to get that working. Or you could use this:

RewriteEngine on

Options -Indexes

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

to redirect everything to your index page, and then use $_SERVER['REQUEST_URI'] to parse the URI and load the appropriate files.

minitauros 151 Junior Poster Featured Poster

I guess that by "certifications" they mean something like "which languages have you proven yourself certified to program in?". So I guess you could fill in the languages you have a lot of experience with?

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

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

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?