Lost in My Array

← Ask a Question — Started 22 Apr, 2011

leesester
22 Apr, 2011, 8:07 am (This post was last modified: 28 Apr, 2011 11:53 am by leesester.)
Hi Tomm

Yea, its that blasted Fish again. With my graphs. I have been trying and trying on this - but I cannot get it to work.

Situation:

I have a table in my db that records downloads of things that people have uploaded to leefish. I have a tabular representation of that and two graphs.
- The table shows all downloads EVER of a users items. (working)
- Graph 1 Shows all downloads of a users threads on a certain day - currently hardcoded today. (I dream that one day I will be able to put in a datepicker and then they can look at the graphs for a certain day - but that is a LONG way down the road) (working)
- Graph 2 shows all downloads of a users threads in a time period - I have it at 30 days. (sort of working) but shows no date of downloads so its all a bit meaningless.

The Problem

Graph 2 grabs the data for all of a users downloads info and puts it in a table. Unfortunately, if someone has no downloads in that period then no downloads are shown. When a user has downloads then it displays, but with no date. So the user cannot see what date it refers to......

I think I have two options here -

Option 1 = to only show the days that there is a download, and then to put a date in the tooltip. If someone has no downloads in a time frame that will probably break the graph.

Option 2 - pre-populate the graph with the dates and then loop through the dates and see if a user has a download in that timeframe. If they have no downloads then they just see an empty graph with all the dates along the bottom. If they have a download then they see the bar with the number of downloads on the relevant date.

I think Option 2 is the better option, but I just cannot get dates to show in the X-axis values. Probably because my php is wrong.

What I have managed to do:

A big fat nothing Sad . I cannot get either option to work and now have a big keyboard shaped bruise on my head from banging my head on my keyboard in frustration.

Please can you help me? I have attached my file.

ETA: Attachment removed as is fixed Smile
[Image: leelink.gif]
No problem! I always thought you might return one day Fish. Tongue

I'm on holiday at the moment until next week (the joys of having two public holidays in two weeks!) but I'll check it out as soon as I'm back. Smile
Oh indeed - its Easter and there is a wedding coming up I see Smile Have a great time and eat lots of chocolate...
[Image: leelink.gif]
Big Grin The royal wedding is coming up this friday Wink Its going to be popular, but i dont think i will bother watching it to be honest... I have studying to do for exams, so having time off for a wedding is not really going to help me Tongue
[Image: 1_15_01_11_6_52_28.png]
leesester
27 Apr, 2011, 8:40 pm (This post was last modified: 28 Apr, 2011 11:30 am by leesester.)
Hi Tom,

I have actually made progress Smile You should go on holiday more often maybe Tongue

Now I have the date in the tooltip and on the x-axis - its all looking pretty sharp and I am very proud of it. I now have one thing left in Phase One, and that is to show the full range of dates and a NULL value where there are no downloads on a particular day. That I am still struggling with.

I have attached the new slightly less fail version, maybe you could take a look at it and advise how to fix? I think I need to set a range on my x-axis.

Phase Two = to make it so I can use a datepicker for the today graphs. I am off researching that now.

Removed attachment as is fixed Smile
[Image: leelink.gif]
I did it!! All values show including null. Muwhahahah
[Image: leelink.gif]
Damn! I thought I could go 2-0. Well done - I guess that makes us evens in the coding wars... Dodgy
Well, I don't know about that...(re being even) but I was very pleased to work it out.

Now I am learning about $post and $get. I have my jQuery picker showing on the page (css and code running from the google/ajax/lib - did you know they provided the themes on CDN?) but its not doing very much at the moment.

What I am actually trying at the moment is to get the graph to show outside mybb. I have it posting. Just need to work out the url encode I think.

Using the JQuery theme roller gave me an idea to try and use the one of the theme roller css sheets to theme mybb. Would be a colossal amount of work though.
[Image: leelink.gif]
leesester
6 May, 2011, 2:06 pm (This post was last modified: 6 May, 2011 2:11 pm by leesester.)
Hi Tomm, back again. I have some progress, but I think I need some help here.

What am I trying to do?
I am trying to update the contents of my graph when a user picks a date.
I have a graphs page, showing downloaded items today - the php query is as in the snippet:

Code:
require_once MYBB_ROOT."inc/3rdparty/ofc_charts/open-flash-chart.php";
$mydate=date("Ymd", (TIME_NOW-(60*60*24*2)));

    $days = $tids = array();
    $query = $db->simple_select("threads", "tid, subject, dateline", "uid = '".$mybb->user['uid']."'");

    if($db->num_rows($query))
    {
    $date = $mydate;
bla bla bla

The var $mydate gets passed into the query and all goes as planned. I am trying to make it so that when a user selects a date from the jQuery datepicker then the variable $mydate in the php query changes and then I can refresh the graph. This is my datepicker setup, it sets the date to the correct format as in my database table (example date format in the db = 20110428)

Code:
<script>
jQuery(document).ready(function()  {
        jQuery( "#datepicker").datepicker({
            showOn: "button",
            buttonImage: "{$mybb->settings['bburl']}/images/toplinks/calendar.gif",
            buttonImageOnly:true,
minDate: -30, maxDate: 0,
dateFormat: "yymmdd",
constrainInput: true,
onSelect: function(dateText, inst) {document.getElementById('mydate').value=dateText; }
        });
   });
</script>

and this is what I have in my HTML to make the datepicker show:
Code:
<form method="get" action=" " value="mydate" name="mydate" id="mydate">
                    <input type="text" id="datepicker">

</form>

As you can see the action bit is empty as I don't know what to put there Shy

I have managed to make my graph reload on a timer using AJAX to get real time data. Not that I want it to reload like that, but it shows I can manipulate the chart object. This is the timer code:

Code:
<script>
    var timerID = 0;
    function reload()
    {
        if (timerID)
        {
            clearTimeout(timerID);
        }
        tmp = findSWF("my_chart");
        x = tmp.reload("xmlhttp.php?action=get_upload_info");
          timerID = setTimeout("reload()", 3000);
    }
    function findSWF(movieName)
    {
        if (navigator.appName.indexOf("Microsoft")!= -1)
        {
            return window[movieName];
        }
        else
        {
            return document[movieName];
        }
    }
    timerID  = setTimeout("reload()", 3000);
</script>

Ideally I want it to reload once the date is submitted via the datepicker to the leegraphs2.php file.

So, my questions are:

How do I make the mydate variable in the php file update via the jQuery Datepicker?
What variable should I use in my AJAX reload to make it work via the submission of the date in the datepicker rather than a timer?
[Image: leelink.gif]
(6 May, 2011 2:06 pm)leesester Wrote:  As you can see the action bit is empty as I don't know what to put there

In the "action" field of a form, you put the filename that process it. If it's blank it will post the data to the page the form is on - never leave it blank. Wink

You need to add a "name" field to the datepicker.

This:

Code:
<input type="text" id="datepicker">

Should be

Code:
<input type="text" name="custom_date" id="datepicker">

Then, in your PHP, you can do this:

PHP Code:
if(!$mybb->input['custom_date'])
{
     
$mydate=date("Ymd", (TIME_NOW-(60*60*24*2)));
}
else
{
     
$mydate $db->escape_string($mybb->input['custom_date']); // Always escape string data from a user!


As for the AJAX reload, you'll need to put in an extra variable to look for in the code - so xmlhttp.php?action=getuploadinfo will need to become xmlhttp.php?action=getuploadinfo&custom_date={date}. Your PHP code for getting the chart via AJAX should recognize the custom_date field too (just like above) and sort via that rather than the current time.

Hopefully this makes total sense. Shy

User(s) browsing this thread: 2 Guest(s)