broj1 356 Humble servant Featured Poster

To my knowledge, the code:

$array1 = array_map('trim',explode(',',implode(',',$array1)));

is equal to the following:

$array1 = array_map('trim', $array1);
broj1 356 Humble servant Featured Poster

I think you first have to define (and let me know) what is the format the dojo chart expects. You were using javascript array in previous posts and now use json. Can you please post the exact format you want the dataEnrolled and dataExpected be.

What is the purpose of this line:

$array2 = array_map('trim',explode(',',implode(',',$array2)));
broj1 356 Humble servant Featured Poster

This brings us back to my first post to your question. You have to use a while loop to read all the rows. Within the while loop you have to construct the array that the charting function expects. From your hard-coded array examples I guess you need just two indexed arrays.

// initialize the array
$enrolled_array = array();

// add valus from each row
while ($row = mysql_fetch_array($result2)) {
    $enrolled_array[] = $row['participantsEnrolled'];
}

This is again my guess since I do not know the db structure and dojo. So please adapt that to your needs.

broj1 356 Humble servant Featured Poster

Now, it is a question of what parameters the dataStore1 and dataStore2 objects expect. If a JSON with one property and value an array, then you should add this code to create arrays in javascript format:

$enrolled_js_array = '[' . implode(',', $enrolled) . ']';
$expected_js_array = '[' . implode(',', $expected) . ']';

and change code in lines 42 and 43 to:

var dataEnrolled = {$enrolled_js_array}; // [5,10] in your case
var dataExpected = {$expected_js_array}; // [20,50] in your case

since you are using Items property name later in the object definition (I doubt you can use it twice). I am just guessing, as I said, since I do not know anything about using charts in dojo.

broj1 356 Humble servant Featured Poster

I agree, checking subscription time upon successful login and doing appropriate action is all you basically need to do to handle this. Additionally you can still do separate periodical checks to maybe warn users by mail about their subscription end approaching.

broj1 356 Humble servant Featured Poster

You can also use mysql events for triggering (v >= 5.1). I have actually never used them so do not know the deatils.

broj1 356 Humble servant Featured Poster

You have done it OK, only a double quote (as part of html attribute value) is missing after 240.

echo('<embed src="flash/' . rand(1, 5) . '.swf" type="application/x-shockwave-flash" width="320" height="240"></embed>');
broj1 356 Humble servant Featured Poster

Check if $_SESSION['access_level'] is really 220. You can also try to put the line

header('location:borangK8.php');

on top of the script to see whether redirection works.

Also make sure no html (not even a space) is sent before header() function. Check your script and included files for output.

broj1 356 Humble servant Featured Poster

Please put this temporary debug code immediately after line 26:

print_r($enrolled);
print_r($expected);
die();

and post what you get.

broj1 356 Humble servant Featured Poster

OK, you are basically doing it right (you should get the same result with while loop, too). But I do not think you can pass a PHP array to javascript (dojo) directly, just like that. You should convert it to string that looks like javascript array, something like:

$js_array = '[' . implode(',', $enrolled) . ']';
...
var dataEnrolled = {items: ($js_array)};
broj1 356 Humble servant Featured Poster

I am not familiar with dojo but I guess your problem appears to be reading the DB results. The mysql_fetch_array function returns only one row so you should run it in a while loop to retrieve all rows.

while ($row = mysql_fetch_array($result2)) {
    // do whatever you need with the row 
}

Now, what you do in the while loop depends on what is the structure of data that dojo expects.

If this is not the cause of your problem please post any error messages or debug output.

As a side note I would recommend replacing outdated mysql_* functions with more up to date versions: either myqli or PDO.

broj1 356 Humble servant Featured Poster

If you do not have many results for each div you can also fake pagging. You read all the product data but display only a portion of it and hide the rest (using CSS display:none). On clicking page links you can then unhide another portion and hide previous.

broj1 356 Humble servant Featured Poster

Yes, but then you have to forget all the ayax stuff. This means that on each click (either on one of the links for categories or links for pages) the wholepage will be refreshed/reloaded. This in your case is OK since about 90% of page contents gets refreshed anyway.

To use Pager for paginating DB results see this link (from the maintainer of the package) and use method #2 which is simpler.

broj1 356 Humble servant Featured Poster

The only thing I can come up with is that the url might be incorrect. Have you checked spelling?

broj1 356 Humble servant Featured Poster

If you use this plugin you have to do a few more things:

  • get the number of total pages for that particular product (using COUNT(*) WHERE product_id=...) and store it into items varialble
  • prepare a php script that will return the records for one page, using itemsOnPage parameter (or modify existing script)
  • use onPageClick function which will call above mentioned php script to fetch pages

But documentation for this plugin is not very comprehensive. So maybe you try this one, which has a nice tutorial along with it.

I have never done any jquery/ajax pagination so I can not give you any finished code. I used PEAR Pager class for this purpose and it was doing it's job very well.

broj1 356 Humble servant Featured Poster

For online users you have to do some guessing. You do not log the logout time so you can't compare it with login time. And this method is not reliable since the user might just close the browser. You can also check sessions or write a fancy javascript such as this.

broj1 356 Humble servant Featured Poster

Just a few ideas. Can't say they are 100% OK, since I do not know much about your app. Do some tests.

// Unique visits by host
SELECT COUNT(*) AS hostcount, host FROM log GROUP BY host

// Unique visits by VisitorIP
SELECT COUNT(*) AS visitoripcount, VisitorIP FROM log GROUP BY VisitorIP 

// Pageviews
SELECT COUNT(*) AS pagevievcount, VisitPage FROM log GROUP BY VisitPage

// Returning visitors by VisitorIP
SELECT COUNT(*) AS returningcount, VisitorIP**Bold Text Here**  FROM log GROUP BY VisitorIP HAVING COUNT(*) > 1

Impressions? What is this?

broj1 356 Humble servant Featured Poster
broj1 356 Humble servant Featured Poster

It would be also expected that you logout visitors with access level less than 100, not greater than 100. The higher the acces level the more rights the user has. Like below:

if(!isset($_SESSION['access_level']) || $_SESSION['access_level'] < 100) {
broj1 356 Humble servant Featured Poster

Weel, it's time to check the UPDATE sql statement which I guess might be in update.php. Can you post it please.

BTW: I'll probably won't be able to reply sooner than tomorrow morning.

broj1 356 Humble servant Featured Poster

OK, try this in Update.php:

<input type="hidden" name="customer_id" class="customer_id" value="<?php echo $customer_id; ?>">

$customer_id actualy holds your customer ID (and not $customer['customer_id'] as in my previous post). My mistake, sory, it's a lot of code and sometimes hard to follow.

broj1 356 Humble servant Featured Poster

But for completeness and since I left it dangling there

Still very nice example of using bitwise operators. Useful in other cases, too, like PHP error reporting.

broj1 356 Humble servant Featured Poster

Can you put this debugging code into Update.php on the very beginning:

<?php
    die(print_r($_POST, 1));
?>

This will print the contents of the $_POST array and stop the script. Please post the output.
broj1 356 Humble servant Featured Poster

It's still going to the wrong page

What page does it go to? It should go to the Update.php.

broj1 356 Humble servant Featured Poster

OK, we are getting there. This could be due to stray single quote in the query:

WHERE id = {$customer_id'}";

Either remove it or change it to:

WHERE id = '{$customer_id}'";
broj1 356 Humble servant Featured Poster

I am guessing but I think customer ID should be in the value of hidden input on line 34. This is the current code:

<input type="hidden" name="customer_id" class="customer_id" value="">

Shouldn't it be:

<input type="hidden" name="customer_id" class="customer_id" value="<?php echo $customer['customer_id']; ?>">
broj1 356 Humble servant Featured Poster

OK, I see. TThe problem is that the ID is not comming to the update.php page from previous page. Can you post that page code too?

broj1 356 Humble servant Featured Poster

Well, the trouble is there is no id in your query. This is why this code:

if(!isset($_POST['id']) || !is_numeric($_POST['id'])) {
    // handle the error here
    ...
}

Redirecting to logout was just my guess. The thing is if there is no value in $_POST['id'] then you have to do something about it (warn the user, provide a default value...).

Why is there no $_POST['id'] is another question. How does the user pprovide the ID? If it is a form then the method of the form has to be post. If it is a link, it is usually get, but if updating, try to use post. Can you show the code for update.php?

broj1 356 Humble servant Featured Poster

The method in the form is POST while you are reading $_GET. Change it to $_POST.

$customer_id = $_POST['id'];

And for security reasons validate and/or escape it.

if(!isset($_POST['id']) || !is_numeric($_POST['id'])) {
    header('location:logout.php');
}

$customer_id = mysql_real_escape_string($_POST['id']);
broj1 356 Humble servant Featured Poster

OK, addme wass a bit quicker :-)

broj1 356 Humble servant Featured Poster

Have you escaped the double quotes:

if($exfreeformaddress == '') {
    $spanStyle = 'background-color: yellow;';
} else {
    $spanStyle = 'background-color: white;';
}

$body .= "<span style=\"$spanStyle\">Address - " . $exfreeformaddress . "</span>\n";
broj1 356 Humble servant Featured Poster

This won't work since you use links for your pagination which refresh the whole page which in turn defeats the purpose of ajax. If you want to keep the ajax approach then you have to do the pagination with ajax too (not using querystrings and $_GET) but this might be more complicated. If you want to use traditional non-ajax approach you will have to drop the ajax functionality just implemented.

And what is the difference and which approach to choose? When using non-ajax approach the page will refresh on each click on any link while with ajax approach only the contents of div will refresh. But ajax is meant to be used when you want to refresh a small portion f your page (i.e. the shopping basket contents) and you do not want to refresh the whole page. In your case the most of page will get refreshed anyway so it is maybe better to use non-ajax approach which is less complicated and easier to mantain.

If you want to stick with ajax approach I am happy to help but have never done this way of pagination through ajax calls so I am not sure how difficult it is. It might take some time. If you decide to do it non-ajax way than again I do not have much experience with coding pagination since I always used library for taht (PEAR Pager is a package that does this job nicely.

broj1 356 Humble servant Featured Poster

The ready handler will not change the functionality at all it will just make sure the functionality is loaded once the DOM is ready which in most cases takes just a fraction of second. And it affects only the page with jquery script not the ajax processing script (getProductData.php). In other words: you do not have to use the ready handler at this stage.

Pagination will work. In the getProductData.php page you have to prepare the html code for pagination and send it back into product-data div.

broj1 356 Humble servant Featured Poster

You are welcome, mate. Just to suggest an minor improvement: if the page grows and has more elments that might take some time to load, or if you change the triggers for ajax you might want to enclose the whole javascript/jquery code in $(document).ready handler which will ensure that functionality is available after the DOM is ready:

<script>
$(document).ready(function() {

    $('a.category').click(function(e) {

        ...

});
</script>

But that might not be absolutely neccessary in all cases.

broj1 356 Humble servant Featured Poster

You can do it using case statement:

if(!isset($_SESSION['access_level']) || $_SESSION['access_level'] < 180) {
    header('location: logout.php');
} else {
    switch($_SESSION['access_level']) {
        case 220 : header('location:restricted_page1.php'); break;
        case 200 : header('location:restricted_page2.php'); break;
        case 180 : header('location:restricted_page1.php'); break;
        default : header('location:logout.php');
    }
}

I haven't noticed your question to me about access levels in one of your previous posts. Have you got those answers yet?

broj1 356 Humble servant Featured Poster

Have you copied the above javascript code exactly as I posted it? Does it contain the line

e.preventDefault();

Your links should not go anywhere when you click on them (the above code prevents that) since you choose to use ajax. In this case links are there just to get people click on them but you allways stay on the same page, only the contents of the div changes.

broj1 356 Humble servant Featured Poster

This is when ajax comes in. Links will have a class, I'll name it category. jquery will catch clicks on all links having that class and sending a request to the php file that will retrieve the data and return it formated as html.

This is the file with links (the whole lot, containing the jquery bit):

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>

<!-- href attributes are the values of categories -->
<a href="1" class="category">Category 1</a>
<a href="2" class="category">Category 2</a>
<a href="3" class="category">Category 3</a>
<a href="4" class="category">Category 4</a>
<a href="5" class="category">Category 5</a>
<a href="100" class="category">Category 100</a>

<!-- This div will display the product data -->
<div id="product-data">
</div>
<?php
?>
<script>

// whenever a link with category class is clicked
$('a.category').click(function(e) {

    // first stop the link to go anywhere
    e.preventDefault();

    // you can get the text of the link by converting the clicked object to string
    // you something like 'http://mysite/categories/1'
    // there might be other methods to read the link value
    var linkText = new String(this);

    // the value after the last / is the category ID
    var categoryValue = linkText.substring(linkText.lastIndexOf('/') + 1);

    // send the category ID to the getProductData.php script using jquery ajax post method
    // send along a category ID
    // on success insert the returned text into the product-data div
    $.post('getProductData.php', {category: categoryValue}, function(data) {

        $('#product-data').html(data);
    });
});
</script>

</body>
</html>

And this is the script that reads data and echoes it back:

<?php
// if no …
broj1 356 Humble servant Featured Poster

if the user's access_level is below than 180 it will directly go to the logout page right?

Yes. It also redirects you to logout if the session variable does not exist.

i tried that way, but even the access level is higher that 180, it still directly go to logout page.

Can you show the code. Have you started the session? Does the $_SESSION['access_level'] exist at all?

broj1 356 Humble servant Featured Poster

Please post the code you have so far (the page with links) and structure of the table(s).

broj1 356 Humble servant Featured Poster

You might be better off declaring the method this way:

public  function load_Array($data)
{
    $this->anArray = array();

    foreach($data as $element) {
        $this->anArr[] = $element;
    }
    ...

Now you can pass an array as argument (as cereal suggested):

    $andy->load_Array(array("andy","bill"));
broj1 356 Humble servant Featured Poster

POST[customer] is incorrect while POST['customer'] is correct in php code.

broj1 356 Humble servant Featured Poster

my beautifully crafted DateTime extension class failed to work as expected because I was using a VC6 php build as opposed to the VC9

Took me some time to figure out what VC stands for :-) I have never used VS and rarely use Windows these days. Thanks for sharing this info.

broj1 356 Humble servant Featured Poster

Another variation is to use Ajax. The difference form Atli's approach is that the page does not get refreshed each time you click a link, only the content in the div changes. Te easiest way to do it is to use jQuery and it's ajax methods.

http://api.jquery.com/jQuery.ajax/
http://www.w3schools.com/jquery/jquery_ref_ajax.asp

With the chosen ajax method you call your php script that retrieves the contents from the DB and returns HTML code for displaying in the div.

broj1 356 Humble servant Featured Poster

Yes, it basicaly exits teh function if there are less than 3 chars in the search_term. Haven't tested it, though, but I am pretty sure return statement works like exit in php. Other way of doing it would be wrapping the whole ajax bit in if(search_term.length >= 3).

$(document).ready(function() {

    $('.autosuggest').keyup(function () {

        var search_term = $(this).attr('value');

        if(search_term.length >= 3) {

            // read the values of the select elements (drop downs)

            // read the value of category 
            var category=$('#category').attr('value');

            // this is the conditions you will post over to the searchApp.php script
            // assembled here for clarity
            var conditions = {

                'search_term' : search_term,
                'category' : category
            }; 

            // alert(conditions.toSource());

            // post the conditions over to the searchApp.php script
            $.post('ajax/searchApp.php', conditions, function(data) {

                //alert(data);
                $('.result').html(data);

                /*
                // you can sort this out yourself
                $('.result li').click(function() {

                    var result_value=$(this).text();
                    $('.autosuggest').attr('value',result_value);
                    //alert(result_value);
                    $('.result').html('');

                });
                */

            });
        });
    });
}
broj1 356 Humble servant Featured Poster

I hope I got your question. You want to draw radio button which is either enabled or disabled, depending on a query result.

$result=mysqli_query($mysqli,"SELECT tableselect FROM reserve WHERE reserveDate = '". $date ."' AND reserveTime = '". $time ."'");

if($row = $result->fetch_array(MYSQLI_ASSOC)){
    echo $row['tableselect'];
    if($t){
        $disabledAttr = ' disabled="disabled"';
    } else {
        $disabledAttr = '';
    }
}

echo '<input type="radio"' . $disabledAttr . ' />';
broj1 356 Humble servant Featured Poster

visitortimezone give Europe/Berlin, (India Standard Time) for localhost
VisitTime give 05:29:37 for 10 AM IST for localhost

Will this link help?

http://stackoverflow.com/questions/3905193/convert-time-and-date-from-one-time-zone-to-another-in-php

broj1 356 Humble servant Featured Poster

And also I made a small mistake in the html code, sory. I put the result unnumbered list (ul) at the end of the page. I later realized that it should be in the place where you put it originally, just after the input box, since it is the basis for extending the input box into combo box. So please move it back there.

<input type="text" name="tag" value="" placeholder="All" class="autosuggest" />
<div class="dropdown">
<ul class="result">
</ul>
...
broj1 356 Humble servant Featured Poster

for the 3 characters that have to be typed in so the jquery to launch and resource for that ?

All you have to do is check in the javascript code whether the search_term is at least 3 chars long. If not, you do not do an ajax call at all.

$(document).ready(function() {

    $('.autosuggest').keyup(function () {

        var search_term = $(this).attr('value');

        // if we have less than 3 chars just exit the function
        if(search_term.length < 3) {

            return;
        }

        ...
broj1 356 Humble servant Featured Poster

mysql_fetch_array function returns result in both associative and numeric arrays while

mysql_fetch_assoc function returns result only in an associative array.

It is the matter of what you want when choosing among them.

broj1 356 Humble servant Featured Poster

And finaly the html page with the form. I have ammended a few things here, too. First I put the javascript directly in the html but you can keep it separate in Primary.js file, if you wish. The most important thing is that you add an ID to all of the select elements (drop downs) you want to use in the query. I have done so for the category. This way jacascript (jquery) can read the selected values and send them over to searchApp.php.

The div block that displays the results (id= result) should be placed outside the form just for sematic reasons, but should work inside too, I guess.

And there is a span tag towards the end that is in wrong place. I suggest you put it somewhere else.

There are some other small errors in the html. Open the html in a good editor, you will get the errors highlighted.

And here is my version of the code (with the javascript included directly):

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="searchAppliance.php" method="post" name="search1" onsubmit='return validateForm()'>

   <table width="685" border="0">
  <tr>
       <td width="238" height="23" valign="top">
  <font size="-2">Search</font><font size="-1"><strong> APPLIANCES </strong></font>

       </td>
       <td width="443" valign="top">
       <input type="submit" value="Find" id="findbuton">
       </td>
       </tr>
       </table>
       <div id="dropdown">
       <table width="621" border="0" align="center">
       <tr><td width="100">

        <span>Category</span><br />

            <!-- give category dropdown an ID so you can read it's value with jQuery -->
            <select name="category" id="category" 
            style="width: ; background-color: #FFF; font-weight: bold; font-size: 12px; width: 120px;">

            <!-- onchange="setup(document.search1.category.value)"> -->

              <option value="all" selected="selected">All</option>
              <option value="cleaning">Cleaning</option>
              <option value="cooling">Cooling</option> …