how can I spend those weeks in MySQL in this table? - mysql

So I want to release the weeks in MySQL here in this table but how do I do that I had tried something but nothing can be released here can anyone here help me and give a good example if it is possible. year weeks must be included.
a little explanation here if I have to calculate a score every week I have to see that. and if I do that every week I always see a zero here a picture
I hope you understand a little what I mean
enter image description here
-- phpMyAdmin SQL Dump
-- version 4.4.14
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Dec 12, 2017 at 10:59 AM
-- Server version: 5.6.26
-- PHP Version: 5.5.28
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `stefaanphp`
--
-- --------------------------------------------------------
--
-- Table structure for table `tblusers`
--
CREATE TABLE IF NOT EXISTS `tblusers` (
`id` int(11) NOT NULL,
`Auditeur` varchar(150) NOT NULL,
`Afdeling` varchar(150) NOT NULL,
`Zone` varchar(120) NOT NULL,
`Stand` varchar(150) NOT NULL,
`Score` varchar(150) NOT NULL,
`number1` char(11) NOT NULL,
`number2` char(11) NOT NULL,
`number3` char(11) NOT NULL,
`number4` char(11) NOT NULL,
`number5` char(11) NOT NULL,
`number6` char(11) NOT NULL,
`number7` char(11) NOT NULL,
`PostingDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`Week` INTEGER NOT NULL -- 1 to 52/53
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;
--
-- Dumping data for table `tblusers`
--
INSERT INTO `tblusers` (`id`, `Auditeur`, `Afdeling`, `Zone`, `Stand`, `Score`, `number1`, `number2`, `number3`, `number4`, `number5`, `number6`, `number7`, `Week`,`PostingDate`) VALUES
(1, 'stef', 'Combine', 'Hoofdlijn st1-4 + Onderraam 1010', 'St 6008', 'Totale Score:10', '5', '3', '3', '5', '10', '5', '1', '02', '2019-02-12 08:27:53');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `tblusers`
--
ALTER TABLE `tblusers`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `tblusers`
--
ALTER TABLE `tblusers`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=7;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;
and I still have a question to change that date with time to only date can not get time I had already done many other options for example date just get 000-00-0000

About your week question: you can use the MySQL week function to calculate the weeknumber of specific dates:
https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_week
The function expects a date or datetime, so you can just use the PostingDate that you are using in your insert statement.
About the other questions: maybe rephrase it so we can understand what you actually are asking.

Related

Create Mysql tables

I downloaded the script that I want to install on my VPS, and as the creator who created this script said in the instructions, I import only the file that is called sql.sgl into the root folder where the database is created, but after that I can not run the script, and as I see in MySql no tables was created, so I wonder if there is a possibility to create everything from sql.sql file via commands in mysql, If someone can tell me just what commands in Linux I use to manually create all the tables and the rest from the file bellow:
anyway i just checked the error.log file and the error is on this script line 9 , please help , is this code ok ?
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_saha = "111.111.111.135";
$database_saha = "search";
$username_saha = "root";
$password_saha = "me111";
$saha = mysqli_connect($hostname_saha, $username_saha, $password_saha, $database_saha) or trigger_error(mysqli_error($saha),E_USER_ERROR);
mysqli_set_charset( $saha, 'utf8');
?>
-- version 4.6.0
-- http://www.phpmyadmin.net
--
-- Host: localhost:3306
-- Generation Time: Dec 04, 2016 at 12:02 PM
-- Server version: 5.5.52-cll-lve
-- PHP Version: 5.6.14
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `hello`
--
-- --------------------------------------------------------
--
-- Table structure for table `admin`
--
CREATE TABLE `admin` (
`id` int(11) NOT NULL,
`un` varchar(30) NOT NULL,
`pw` varchar(30) NOT NULL,
`demo` enum('Y','N') NOT NULL DEFAULT 'Y',
`max_pages` int(11) DEFAULT '20',
`max_content` int(11) DEFAULT '500'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Dumping data for table `admin`
--
INSERT INTO `admin` (`id`, `un`, `pw`, `demo`, `max_pages`, `max_content`) VALUES
(1, 'administrator', 'admin', 'N', 20, 500);
-- --------------------------------------------------------
--
-- Table structure for table `crawl`
--
CREATE TABLE `crawl` (
`id` int(11) NOT NULL,
`base_url` varchar(1000) NOT NULL,
`actual_url` varchar(2000) NOT NULL,
`title` varchar(2500) NOT NULL,
`description` varbinary(200) DEFAULT NULL,
`keywords` varbinary(200) DEFAULT NULL,
`content` varchar(500) DEFAULT NULL,
`current_url` varchar(2000) NOT NULL,
`last_update` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`deleted` enum('Y','N') DEFAULT 'N',
`block_update` enum('Y','N') DEFAULT 'N',
`visits` int(11) DEFAULT '0',
`manual` enum('Y','N') DEFAULT 'N'
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table `settings`
--
CREATE TABLE `settings` (
`id` int(11) NOT NULL,
`base_url` varchar(1000) NOT NULL,
`actual_url` varchar(2000) NOT NULL,
`demo` enum('Y','N') DEFAULT 'N',
`date` timestamp NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `admin`
--
ALTER TABLE `admin`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `un` (`un`),
ADD UNIQUE KEY `un_2` (`un`);
--
-- Indexes for table `crawl`
--
ALTER TABLE `crawl`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `settings`
--
ALTER TABLE `settings`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `admin`
--
ALTER TABLE `admin`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=18;
--
-- AUTO_INCREMENT for table `crawl`
--
ALTER TABLE `crawl`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=747;
--
-- AUTO_INCREMENT for table `settings`
--
ALTER TABLE `settings`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=26;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;```

how can i change with timestamp mysql in a date

I have here MySQL code for my table but I want to change this date but I do not want time but just date what should I do I have already searched a lot on the internet but still found nothing. and I also have a week overview here how I would apply that.
I hope you can help me
regards stefaan
``-- phpMyAdmin SQL Dump
-- version 4.4.14
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Dec 12, 2017 at 10:59 AM
-- Server version: 5.6.26
-- PHP Version: 5.5.28
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `phpcurdpdo`
--
-- --------------------------------------------------------
--
-- Table structure for table `tblusers`
--
CREATE TABLE IF NOT EXISTS `tblusers` (
`id` int(11) NOT NULL,
`Auditeur` varchar(150) NOT NULL,
`Zone` varchar(120) NOT NULL,
`NOKOK01` char(11) NOT NULL,
`NOKOK02` char(11) NOT NULL,
`NOKOK03` char(11) NOT NULL,
`NOKOK04` char(11) NOT NULL,
`Bericht` varchar(255) NOT NULL,
`PostingDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`Week` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1;
--
-- Dumping data for table `tblusers`
--
INSERT INTO `tblusers` (`id`, `Auditeur`, `Zone`, `NOKOK01`, `NOKOK02`, `NOKOK03`, `NOKOK04`, `Bericht`, `PostingDate`) VALUES
(1, 'Stefaan', 'Zone 2060', 'NOK', 'OK', 'OK', 'NOK', 'graag een verandering', '2017-12-12 06:27:53');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `tblusers`
--
ALTER TABLE `tblusers`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `tblusers`
--
ALTER TABLE `tblusers`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=7;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;

How to solve duplicate mySQL entry?

I'm pulling stats down from an external source but the external source has changed how it handles things which is causing me problems, everything else works but for 1 section of the database which is giving me duplicate entries, as nothing is being pulled the database enters the value of 0 so the next field would also have a value of 0, I tried auto increment but I still end up with a duplicate entry.
-- phpMyAdmin SQL Dump
-- version 3.4.11.1deb2+deb7u6
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Oct 27, 2016 at 02:44 AM
-- Server version: 5.5.52
-- PHP Version: 5.6.26-1~dotdeb+zts+7.1
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `forum`
--
-- --------------------------------------------------------
--
-- Table structure for table `xf_yfl_rival_stats`
--
CREATE TABLE IF NOT EXISTS `xf_yfl_rival_stats` (
`match_id` bigint(30) NOT NULL,
`player_ea_id` bigint(60) NOT NULL,
`persona_name` varchar(50) NOT NULL,
`club_id` bigint(20) NOT NULL,
`assists` int(2) NOT NULL,
`cleansheetsany` int(2) NOT NULL,
`cleansheetsdef` int(2) NOT NULL,
`cleansheetsgk` int(2) NOT NULL,
`goals` int(2) NOT NULL,
`goalsconceded` int(2) NOT NULL,
`mom` int(1) NOT NULL,
`passattempts` int(3) NOT NULL,
`passesmade` int(3) NOT NULL,
`pos` int(3) NOT NULL,
`rating` double(4,2) NOT NULL,
`redcards` int(2) NOT NULL,
`saves` int(3) NOT NULL,
`shots` int(3) NOT NULL,
`tackleattempts` int(3) NOT NULL,
`tacklesmade` int(3) NOT NULL,
`yellowcards` int(2) NOT NULL DEFAULT '0',
PRIMARY KEY (`player_ea_id`),
UNIQUE KEY `match_id` (`match_id`,`player_ea_id`),
KEY `club_id` (`club_id`),
KEY `player_ea_id` (`player_ea_id`),
KEY `match_id_2` (`match_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;
I'm getting the duplicate entry for the field player_ea_id is there any possible way to bypass this?
My understanding of mySQL isn't the greatest, for example I pull down the match_id or persona_name and both of these fields have the same entry for the players however the player_ea_id is supposed to be unique, how do I get around this?
I dont see where you're using AUTO_INCREMENT. But that is indeed what you need if you are not getting that column from your source.
Change the player_ea_id line of your table creation to this.
`player_ea_id` bigint(60) NOT NULL AUTO_INCREMENT,
#Strawberry, every other part of that database works, its collects stats from the EA sports title FIFA 17, and the 4.2 is related to the players overall match rating which works fine.
#TheValyreanGroup I already tried auto increment it still ends up giving me a duplicate error although not on 0 but on 6 for example or 10, or 15 just whenever it decides to break down. I can run a query and show you what it does on auto increment compared to how it is now if you like?

Cannot add foreign key constraint

First, here's my main reference table mysql dump
-- phpMyAdmin SQL Dump
-- version 4.1.14
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Nov 17, 2015 at 03:15 AM
-- Server version: 5.6.17
-- PHP Version: 5.5.12
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */; /*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */; /*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */;
--
-- Database: `j_inventory`
--
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` ( `user_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(200) COLLATE utf8_unicode_ci NOT NULL, `password` varchar(500) COLLATE utf8_unicode_ci NOT NULL, `real_password` varchar(250) COLLATE utf8_unicode_ci NOT NULL, `role` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `full_name` varchar(250) COLLATE utf8_unicode_ci NOT NULL, `remember_token` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `status` varchar(100) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=44 ;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;
and the second table where the hopefully the foreign key resides
-- phpMyAdmin SQL Dump
-- version 4.1.14
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Nov 17, 2015 at 03:14 AM
-- Server version: 5.6.17
-- PHP Version: 5.5.12
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */; /*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */; /*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */;
--
-- Database: `j_inventory`
--
-- --------------------------------------------------------
--
-- Table structure for table `user_details`
--
CREATE TABLE IF NOT EXISTS `user_details` ( `id` int(11) NOT NULL AUTO_INCREMENT, `phone` varchar(200) NOT NULL, `age` int(100) NOT NULL, `gender` varchar(50) NOT NULL, `address` varchar(250) NOT NULL, `course` varchar(250) NOT NULL, `college` varchar(200) NOT NULL, `year` int(11) NOT NULL, `user_id` int(100) NOT NULL, `updated_at` timestamp NOT NULL, `created_at` timestamp NOT NULL, PRIMARY KEY (`id`), KEY `user_id` (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;
the foreign key (not set up due to mysql error "Cannot add foreign key constraint ") in the users_details is the 'user_id' and the reference table is the 'users' table where the reference key for the foreign key is the 'user_id' on the users table and I tried this
ALTER TABLE user_details ADD FOREIGN KEY fk1(user_id) REFERENCES
users(user_id) ON DELETE CASCADE ON UPDATE NO ACTION;
but sadly and unfortunately it throws me an error
Error SQL query:
ALTER TABLE user_details ADD CONSTRAINT fk1 FOREIGN KEY
(user_id) REFERENCES j_inventory.users(user_id) ON DELETE
CASCADE ON UPDATE NO ACTION; MySQL said: Documentation
1215 - Cannot add foreign key constraint Documentation
any help, clues, ideas, suggestions, recommendations please?
Your user id is unsigned on the users table. Remove 'unsigned' from this field in your users table create statement and see if it works. I think what you're seeing is an error caused by a mismatch between the user_id field types on your users and user_details tables

Mysql Database not creating table [messy code]

I tried to add this:
-- phpMyAdmin SQL Dump
-- version 3.4.5
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Nov 09, 2013 at 04:43 PM
-- Server version: 5.5.16
-- PHP Version: 5.3.8
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
/*!40101 SET #OLD_CHARACTER_SET_RESULTS=##CHARACTER_SET_RESULTS */;
/*!40101 SET #OLD_COLLATION_CONNECTION=##COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `rezzion`
--
-- --------------------------------------------------------
--
-- Table structure for table `punishments`
--
CREATE TABLE IF NOT EXISTS `punishments` (
`username` varchar(20) NOT NULL AUTO_INCREMENT,
`punisher` varchar(20) NOT NULL,
`server` varchar(15) NOT NULL,
`type` int(255) NOT NULL,
`date` varchar(1024) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
/*!40101 SET CHARACTER_SET_CLIENT=#OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=#OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=#OLD_COLLATION_CONNECTION */;
to my database "rezzion" & for some reason i'm getting this error:
Anyone know why it's doing this? I have my database set to utf8-bin & it's name is rezzion... I'm confused why the code above isn't working?
Your error starts, at least, here:
`username` varchar(20) NOT NULL AUTO_INCREMENT,
This is not allowed in MySQL. And, besides, you're declaring primary key with another column:
PRIMARY KEY (`id`)
Auto Increment can only be used on a INT change it to a integer and your problem is solved
AUTO_INCREMENT my only be used with number types. You are applying it to a VARCHAR column. Also, you specify an "id" column as your primary key which does not exist.
You probably want it to look like this:
CREATE TABLE IF NOT EXISTS `punishments` (
`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`username` varchar(20) NOT NULL,
`punisher` varchar(20) NOT NULL,
`server` varchar(15) NOT NULL,
`type` int(255) NOT NULL,
`date` varchar(1024) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;