PHP - How To Create A Monthly Archive (no Mysql Och Any Databases)?
I would like some tips on how to create a monthly archive for my weblog.
I am not using MySQL or any databases. Everything is saved on file. any tips or tutorials? Thanks Similar TutorialsI want to create a text file based blog ( not using MySQL or other databases). I have tried to google for tutorials but I couldn't find anything. is there anyone who can help me and give me some tips? is there any tutorials about this because I found nothing? Any good books? This is an assignment that I have to do and I am using this book: Spring into PHP 5 by Addison Wesley. I am a newbie in php and really want to do this because this is my last task and I really want to learn. So I'm grateful if anyone can help me. I got an idea with my homepage in progress. It's a blog and I want to sort my post in a navigation bar. Is it possible to do a script with $date function to create a new file the 1th of every month. Then use file_get_content on the current month.
To clarify in this stage I haven't started connecting my database.
Edited by DexterTheCat, 05 June 2014 - 11:16 AM. hi all, I am trying to link 2 mysql tables and display some information from each of them. I have a list of all the possible items for sale in table1 and I am trying to count the number of rows in the other table2 where the items exist. E.g. 'table1' manufacturer model man1 item1 man1 item2 man1 item3 'table2' id model 1 item3 2 item3 3 item2 And the result would show: item1(0) item2(1) item3(2) It would list all the items from table1 and show next to it how many rows are related to that item from table2. I have inserted a quote where I have tried many times to enter something similar to that show in the note below - but I can not get it to work - it just shows the total number of models in table1 for a given manufacturer. The php I have made so far is: <?php case 'manufacturer': $query = " SELECT * FROM table1"; $query .= " WHERE manufacturer = '".$data."' "; $query .= " ORDER BY model "; $result = mysqli_query($cxn,$query); $returnData[''] = "Select a Model..."; while($row = mysqli_fetch_assoc($result)){ // I THINK I NEED TO INSERT SOMETHING LIKE $query2 = "SELECT * FROM table2 WHERE model = table1.model"; $k=$row['model']; $k2=$row2['model']; $counter[$k]+=1; $returnData[$k]=$k; } foreach($counter as $k => $row) { $returnData[$k] .= " ($row)"; } break; ?> is it possible to have two open connections to two different mysql dbs at the same time? when i tried it, only the one on the bottom of the list was active. my config file looks like this: //---------------------------------------------// $dbname = 'xxx'; # Database Name $dbuser = 'xxx'; # Database Username $dbpass = 'xxx'; # Database Password $dbhost = 'xxx'; # Database Host $conn2 = mysql_connect($dbhost,$dbuser,$dbpass) or die ("Could not connect to $dbname: ".mysql_error()); mysql_select_db($dbname) or die ("Could not access the database: ".mysql_error()); $dbname5 = 'yyy'; # Database Name $dbuser5 = 'yyy'; # Database Username $dbpass5 = 'yyy'; # Database Password $dbhost5 = 'yyy'; # Database Host $conn = mysql_connect($dbhost5,$dbuser5,$dbpass5) or die ("Could not connect to $dbname5: ".mysql_error()); mysql_select_db($dbname5) or die ("Could not access the database: ".mysql_error()); //--------------------------------------// so i want to be able to do mysql_query($query,$conn2) when i need to access xxx db, but it doesn't seem to work that way. am i doing something incorrectly? any help would be greatly appreciated. Hello, I have created database "acc" which stores my income and expenses in a table called "inex" . I want to see the monthly total expense and incomes in view.php i tried to do it but messed up with the code as i am a newbie. does anyone know a sample code for this kinda purpose or help me with the query? thanks alot Okay guys, I figured out how to calculate monthly subscriptions into days, but I am stuck on calculating multiple monthly subscriptions.. for example Heres my mysql table: How would I calculate this: Subscription Start: February 21, 2011, 12:00 am Subscription End: April 22, 2011, 12:00 am Subscription Left: 60 days My trouble is that when the user buys another month, it calculates the end time based on the new "Subscription Start Date". Or vice versa. Any ideas guys? Thanks. Hi, i have created a mysql table for account info which stores basic expenses and income I have also account.php page that shows the all transactions 10 transaction (row) per page. there is no problem with that but I like it to show the transactions(entries) per month base. I mean when i open this page i want it to show this month's entries. and when i click previous button i like to see last month's entries. any help will be appreciated. thanks in advance. regards. Hi all, I'm trying to make a webpage that allows the user to enter new sales figures for a certain product in a chosen month of a chosen year. I thought my code was correct but it doesn't really do anything. It just displays the table but it's not updated. Can anybody spot an error? Code: [Select] $describeQuery = "SELECT p.ID, p.NAME, dt.[Year], dt.[Month], dt.SalesVolume from Products p join (select ProductCode, sum(SalesVolume) as SalesVolume, [Month], [Year] from MonthlySales where [Year] = '$desiredYear' AND [Month] = '$desiredMonth' group by ProductCode, [Year], [Month])dt on dt.ProductCode = p.ID"; $editQuery = "UPDATE MonthlySales SET SalesVolume = '$newSales' WHERE Month ='$desiredMonth' AND Name = '$desiredProduct' AND Year = '$desiredYear'"; $results = sqlsrv_query($conn, $describeQuery); $resultsx = sqlsrv_query($conn, $editQuery); echo '<table border="1" BORDERCOLOR=Black>'; echo '<tr><th bgcolor = "LightBlue">Name</th><th bgcolor = "LightBlue" >ID</th> <th bgcolor = "LightBlue" >Sales</th><th bgcolor = "LightBlue" >Month</th> <th bgcolor = "LightBlue" >Year</th> </tr>'; while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) { echo '<tr>'; echo '<td >' .$row['NAME'].'</td>'; echo '<td>' .$row['ID'].'</td>'; echo '<td>' .$row['SalesVolume'].'</td>'; echo '<td>' .$row['Month'].'</td>'; echo '<td>' .$row['Year'].'</td>'; echo '</tr>'; } echo '</table>'; while($row = sqlsrv_fetch_array($resultsx, SQLSRV_FETCH_ASSOC)) { } sqlsrv_close($conn); Hey, I'm new at this and a friend came to me and said "You know web design". Which, YES, design not coding. Can someone help me with some PHP. I need to have my blogs archives only give me posts from the blog category, oh did I mention it's a Wordpress site... lol. Here's the code: <?php /** * @package Corporate Theme */ get_header(); ?> <?php $page_headline = get_post_meta($post->ID, 'page_headline', true); $page_description = get_post_meta($post->ID, 'page_description', true); if($page_headline || $page_description) { ?> <div class="wrap_wide slogan"> <div class="wrap"> <h1><?php echo $page_headline; ?></h1> <div class="clear"></div> <p><?php echo $page_description; ?></p> </div> </div> <?php } ?> <div class="clear"></div> <div class="wide_wrap content"> <div class="wrap padding-top-bottom"> <!--Content area--> <?php if (have_posts()) : ?> <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?> <?php /* If this is a category archive */ if (is_category()) { ?> <h1 class="search_archive">‘<?php single_cat_title(); ?>’ Archives</h1> <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?> <h1 class="search_archive">Posts Tagged ‘<?php single_tag_title(); ?>’</h1> <?php /* If this is a daily archive */ } elseif (is_day()) { ?> <h1 class="search_archive">Archive for <?php the_time('F jS, Y'); ?></h1> <?php /* If this is a monthly archive */ } elseif (is_month()) { ?> <h1 class="search_archive">Archive for <?php the_time('F, Y'); ?></h1> <?php /* If this is a yearly archive */ } elseif (is_year()) { ?> <h1 class="search_archive">Archive for <?php the_time('Y'); ?></h1> <?php /* If this is an author archive */ } elseif (is_author()) { ?> <h1 class="search_archive">Author Archive</h1> <?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?> <h1 class="search_archive">Blog Archives</h1> <?php } ?> <ul class="archive_list"> <?php while (have_posts()) : the_post(); ?> <li> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <span class="date"><?php echo get_the_time('F j, Y'); ?></span> <span class="comments"><?php comments_number('no responses','one response','% responses'); ?></span> <?php the_title(); ?> </a> </li> <?php endwhile; ?> </ul> <!--Pagination --> <?php if(get_next_posts_link()|| get_previous_posts_link()) { ?> <div class="clear"></div> <div class="pagination_wide"> <ul> <li class="left"><?php next_posts_link('<span>« Previous</span>') ?></li> <li class="right"><?php previous_posts_link('<span>Next »</span>') ?></li> </ul> </div> <div class="clear"></div> <?php } ?> <!--End pagination --> <?php else : ?> <?php if ( is_category() ) { // If this is a category archive printf("<h1 class='center'>Sorry, but there aren't any posts in the %s category yet.</h1>", single_cat_title('',false)); } else if ( is_date() ) { // If this is a date archive echo("<h1>Sorry, but there aren't any posts with this date.</h1>"); } else if ( is_author() ) { // If this is a category archive $userdata = get_userdatabylogin(get_query_var('author_name')); printf("<h1 class='center'>Sorry, but there aren't any posts by %s yet.</h1>", $userdata->display_name); } else { echo("<h1 class='center'>No posts found.</h1>"); } ?> <?php endif; ?> </div> </div> <?php get_footer(); ?> Thanks, M In a webpage I am making a tar.gz file to download to the user. The file gets to the user perfectly fine but in the process I make a .tar archive and .tar.gz file on the server. I am able to delete the tar.gz file with 'unlink($targzFile);' but I am not able to delete the archive. I have tried treating the archive like a folder and removing all items in the folder and then deleting the folder with 'rmdir($folderName);' as seend below but that hasn't worked for me.
$files = glob($tarName. "/database/*"); hi everybody, i have a php code; it returns year,month,item(post) and works with foreach but year,month display similar as sample:2010 December for all posts:confused:! $select = mysql_query("SELECT title, id, dateColumn FROM theTable"); $list = array(); while( $row = mysql_fetch_assoc($select) ) { $year = date("Y", $row['dateColumn']); $month = date("m", $row['dateColumn']); $list["$year"]["$month"][] = '<a href="site address by $row[id]">' .$row['title']. '</a>'; } foreach($list as $years) { echo "$year : "; foreach($years as $months) { echo "$month : "; foreach($months as $item) echo $item; } } I use $key=>$value but it doesn't work...TNX. Hello guys, i want to create array from mysql what is the script for this...? value like $data = array("1" => .0032, "2" => .0028, "3" => .0021, "4" => .0033, "5" => .0034, "6" => .0031, "7" => .0036, "8" => .0027, "9" => .0024, "10" => .0021, "11" => .0026, "12" => .0024, "13" => .0036, "14" => .0028, "15" => .0025); What I mean by dynamic is say I created a function to generate a random code. I put it in a variable named $key. I make a form with a hidden input type with the name and value of $key. When the form posts, it generates the table name to whatever $key is. Because I tried something like this & its not querying. Heres my code: <?php $dbc = mysqli_connect('localhost', 'cpacrop_todo', 'pass', 'cpacrop_todo') or die('Failed to connect to database!'); function make_key($num_chars) { if ((is_numeric($num_chars)) && ($num_chars > 0) && (! is_null($num_chars))) { $key = ''; $accepted_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; //seed srand(((int)((double)microtime()*1000003)) ); for ($i=0; $i<=$num_chars; $i++) { $random_number = rand(0, (strlen($accepted_chars) -1)); $key .= $accepted_chars[$random_number] ; } return $key; } } $key = make_key(6); ?> <form action="" method="post"> <input type="hidden" name="<?php echo "$key"; ?>" /> <input type="submit" name="submit" value="Submit" /> </form> <?php if ($_POST['submit'] == "Submit") { $query = "CREATE TABLE `$key` ( `id` INT AUTO_INCREMENT, `title` VARCHAR(35), `description` VARCHAR(365) );"; mysqli_query($dbc,$query) or die('Unable to query database.'); echo "Success"; } ?> If this is possible, what am I doing wrong? Thanks! Hey yall! I'm working on a new site idea and I've run across a problem that I know is simple enough but I'm stumped. It's in the signup form What I want to do is insert the new user into the 'Login' table and get the user id that was just created and use that to create a table with the user id in the name. Here is what I have: // now we insert user into 'Login' table mysql_real_escape_string($insert = "INSERT INTO `Login` (`UID`, `pass`, `HR`, `mail`, `FullName`) VALUES ('{$_POST['username']}', '{$_POST['pass']}', '{$_POST['pass2']}', '{$_POST['e-mail']}', '{$_POST['FullName']}')"); mysql_query($insert) or die( 'Query string: ' . $insert . '<br />Produced an error: ' . mysql_error() . '<br />' ); $error="Thank you, you have been registered."; setcookie('Errors', $error, time()+20); // Get user ID mysql_real_escape_string($checkID = "SELECT * FROM Login WHERE `mail` = '{$_POST['e-mail']}'"); while ($checkIDdata = mysql_fetch_assoc($checkID)) { $userID = $checkIDdata; // now we create table 'Transactions" for the user mysql_real_escape_string($create = "CREATE TABLE `financewatsonn`.`Transactions_{$userID}` ( `ID` INT( 20 ) NOT NULL AUTO_INCREMENT COMMENT 'Transaction ID', `name` VARCHAR( 50 ) NOT NULL COMMENT 'Name/Location', `amount` VARCHAR( 50 ) NOT NULL COMMENT 'Amount', `date` VARCHAR( 50 ) NOT NULL COMMENT 'Date', `category` VARCHAR( 50 ) DEFAULT NULL COMMENT 'Category', `delete` INT( 1 ) NOT NULL DEFAULT '0', UNIQUE KEY `ID` ( `ID` ) ) ENGINE = MYISAM DEFAULT CHARSET = utf8 COMMENT = 'User ID {$userID}'"); mysql_query($create) or die( 'Query string: ' . $create . '<br />Produced an error: ' . mysql_error() . '<br />' ); } I know in 'Get user ID' that I need to get the ID but I'm not sure how to get that information. i get the error Quote Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource at 166 which is the while line under Get user ID i have two tables, employee details table(empno, emp_name , branch) and attendance table(date, Ot, attendence). I want to create a relation between two tables Hey guys, Currently Im using the code: while($row=mysql_fetch_array($nt)){ echo" $row[user_login],$row[user_email],$row[CallHistoryTimes],$row[CallHistoryInfo],$row[CallHistoryLastOp]$row[CallHistoryLastDate],<br>"; } To list a mysql array; what I am trying to do is to use the mysql row ID and turn the entire string above into a list. So for example, the database would get the ID information & create a link of edit.php/?id=3 If someone could help me on this it would be mega appreciated. Thanks Hello
I have a mysql table like this:
id | user | car 1 | 1 | fiat 500 2 | 2 | vw polo 3 | 2 | vw golf 4 | 3 | renault clio 5 | 2 | fiat panda 6 | 3 | seat ibiza From this table how can i get a query that the result be like: user 2 - 3 cars user 3 - 2 cars user 1 - 1 cars Thanks Hi there, I hope somebody can help me creating a loop for the following code: What it currently does is, showing only 1 image, while in fact there are 3 of them. I've combined a loginsystem with slideviewer. When i use the original php code (or a part of it) it only shows one listing. I need it to list all of them. <div id="mygalone" class="svw"> <ul> <li> <?php $result = mysql_query("SELECT reference FROM user_photos WHERE`profile_id`='".$row['id']."'"); while ($row2 = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<a href=\"".$_GET['username']."/pics/".$row2['reference']."\"> <img src=\"".$_GET['username']."/pics/thumbs/".$row2['reference']."\"></a><br/><br/>"; } } ?> </li> </div> What can be stripped down to this: <?php { $result = mysql_query("SELECT reference FROM user_photos WHERE`profile_id`='".$row['id']."'"); while ($row2 = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<img src=\"".$_GET['username']."/pics/".$row2['reference']."\">"; } } ?> You would asume that this is allready a loop, but it does not act like it. Best regards, Martijn (the netherlands) |