Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

Quirky Coding Help Needed

Asked Modified Viewed 1,006 times
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
asked
Senior Member

It's me again; the old shade-tree-programmer. I am in need of some more help with my blog infusion. Please; w/o criticism of my quirky coding habits and procedures.
Everything is working beautifully except my calendar module's article links. Actually that works correctly too as long as it is hard-coded into the script. This is the hard-code
that is an existing part of my calendar script:
$days = array(
        1=>array('../grims_blog/filtered.php?post_id=8','link'),
        7=>array('../grims_blog/filtered.php?post_id=9','link'),
        23=>array('../grims_blog/filtered.php?post_id=12','link'),
        24=>array('../grims_blog/filtered.php?post_id=13','link'),
);

This produces linked articles for the given DAY in the calendar correctly. What I need to do is make this array a dynamic one after querying my database table GRIMS_BLOG_POST_TOPIC.
where I need to get the art_day(article day) and the post_id. Then I need to build a string that is the same as the arrays in the above code. Something like this:

1=>array('../grims_blog/filtered.php?post_id=8','link'),
day + "=>array('../grims_blog/filtered.php?post_id=" + post_id + "','link'),"

Here is the code from my create_post script that records the post_id, topic_id, month and day correctly.
$result = dbquery("INSERT INTO ".DB_GRIMS_BLOG_POST." (post_id, topic_id, post_title, post_body, post_img, post_thb, posted, active) VALUES ('', '$topic_id', '$post_title', '$post_body', '$post_img', '$post_thb', '$posted.', '$active')");
$last_id = db_lastid();
$mymon = date("n", $posted);
$myday = date("j", $posted);
$result = dbquery("INSERT INTO ".DB_GRIMS_BLOG_POST_TOPIC." (post_topic_id, post_id, topic_id, art_mon, art_day) VALUES ('', '$last_id', '$topic_id', '$mymon', '$myday')");

I'm not sure how to go about doing the query and then building the links. If this makes sense to anyone I sure would appreciate any help with this.
0 replies

7 posts

D
douwe_yntema
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question
answered
Senior Member

Maybe something like this (sorry adding as code is not working for me atm):

[color=#660000]$result [/color]= dbquery ("Select art_day, post_id From DB_GRIMS_BLOG_POST_TOPIC Where .....")
[color=#000080]if [/color](dbrows([color=#660000]$result[/color])) {
[color=#660000]$data [/color]= dbarray([color=#660000]$result)[/color]

[color=#660000]$na [/color]= [color=#000080]array[/color]();

[color=#000080]while [/color]([color=#660000]$data [/color]= dbarray([color=#660000]$result[/color])) {

[color=#660000]$mdata [/color]= [color=#000080]array[/color]();
$mdata['title'] = [code]'../grims_blog/filtered.php?post_id=".$data['post_id']."';
$mdata['link'] = 'link';

[color=#660000]$na[][/color] = [color=#660000]$mdata[/color];
}

}


You can check the contents of the array by adding statement var_dump($na) as test after the loop.



 [/code]
Edited by douwe_yntema on 01-12-2020 21:47,
1 reply
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

Well I think my brilliant idea is just not going to work. No matter what I do and no matter how I configure this thing it won't work. The
[code]$days = array(

in the script screws everything up. When I try to include the "query coding" within that array it will not work. I really appreciate your attempts at helping me douwe. It does generate the right stuff I just can't incorporate it in the original script so I suppose I'm going to abandon my pursuit.[/code]
Edited by Grimloch on 02-12-2020 18:37,
1 reply
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

When I do that in the calendar script itself this is what I get:
array(4) {
[1]=> array(2) { [0]=> string(36) "../grims_blog/filtered.php?post_id=8" [1]=> string(4) "link" }
[7]=> array(2) { [0]=> string(36) "../grims_blog/filtered.php?post_id=9" [1]=> string(4) "link" }
[23]=> array(2) { [0]=> string(37) "../grims_blog/filtered.php?post_id=12" [1]=> string(4) "link" }
[24]=> array(2) { [0]=> string(37) "../grims_blog/filtered.php?post_id=13" [1]=> string(4) "link" }
}

However I get this printed to the screen above the calendar proper for a VERY VERY LONG time: I assume for each day of the month:

 
Grimloch attached the following image:
Image not found
1 reply
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

It's the same but with an added array for the "link". What it boils down to I think, is a 4 dimensional array. I have no experience with multi-dimensional arrays. Consequently I have absolutely no idea how to solve this.
 
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

This is the most bizzare thing I have ever seen. I can generate the complete code but no matter where I put it in the calendar script it won't work. This is an image of my test file's output:
 
Grimloch attached the following image:
Image not found
1 reply
C
Chan
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,841 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
answered
Super Admin

Im sorry got busy with sorting out work for this site. I would like to post my share of input.

​I see that the column has day and month. To query multi column is slower than to query on 1 single column. I prefer the datestamp int(10) method. This would have been easier with this query to sort month and day using php. 

​​​​​​Insert to blog item using php timestamp. aka time(). To fetch the items would be easy with these:

// February 2020
WHERE MONTH(FROM_UNIXTIME(blog_timestamp)) = 2 AND YEAR(FROM_UNIXTIME(blog_timestamp)) = 2020

i would also add selector in SQL to give me the month and the year as well to sort into query output. 

SELECT * , MONTH(FROM_UNIXTIME(blog_timestamp)) as month, YEAR( FROM_UNIXTIME(blog_timestamp)) as year

So dbarray($res)) will have month and year in your dump. To sort into array I would do this:

$data['link'] = BASEDIR."....?id=$id";

$cache[ $year ][ $month ][ $id ] = $data;

​To callback items on your cached data.. 

Say month 2, Year 2020. will be

$feb =$cache[2020][2];

it will give u 2 dimension array you can loop like this

foreach ($feb as $id => $data) {
 print_p($data);
}

You can also use SQL to add selector DAY(FROM_UNIXTIME( datestamp )) as day, if you need it.

I did not include isset check or empty check in my code above. You can freely add them if needed.

That is how I would design dated stuffs with main priority in sortable and filter control at SQL level. PHP end is just mostly decorative adds and parser for best practise. I will not filter results using php.. proven very slow to render. 
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

OK thanks Chan. I have a new problem that I need help with. I have changed my infusion table field from 'posted' int(10) TO 'post_date' date not null default='0000-00-00' and there is so much confusing information when I do google searches on date/time functions. With my column being only 'date' (no time needed or wanted), I cannot insert a record. I have tried many different scenarios to do this. How can I insert the current date in this field at post creation time? 'yyyy-mm-dd' format.

Sorry nevermind. I got it figured out. $post_date = date("Y-m-d");
Edited by Chan on 12-12-2020 03:32,
0 replies

Labels

None yet

Statistics

  • Views 0 views
  • Posts 7 posts
  • Votes 0 votes
  • Topic users 3 members

3 participants

C
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,841 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
G
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
D
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet