Pagina 1 din 1

anunt pentru fiecare zi

Scris: Dum Mai 02, 2010
de trif
buna ziua, am tot cautat pe net tot feluri de scripturi php care sa imi afiseze pe site cate o informatie in fiecare zi si nu am gasit nimic si mai ales nu stiu cum se face. am asa o ideie doar nu stiu sa o aplic si no. as vrea ca sa am o baza de date si in ea sa fie anunturile pe un an de zile iar scriptul sa imi ia de acolo de fiecare data anuntul potrivit dar cum am zis chiar nu stiu. daca ma puteti ajuta cu asa ceva m-as bucura. dar mai este o mica problema si aceasta este: hostul pe care il am sitele este cu cateva ore in urma si nu prea se potrivesc atunci anunturile si atunci as vrea ca sa fie la ceasul si data fiecarui vizitator care viziteaza sitele. multumesc mult. astept raspuns. cu stima trif

anunt pentru fiecare zi

Scris: Dum Mai 02, 2010
de MarPlo
Buna ziua
Iti scriu in mare cum se face acest script, daca vrei sa-l faci, urmeaza acesti pasi:
1. Creaza un tabel in baza de date, cu 2 coloane: ziua (PRIMARY AUTO_INCREMENT) si info.
2. Adauga in tabel 366 de randuri, de la 0 la 365 (poti sa le adaugi din PhpMyAdmin din CPanelul site-ului daca nu vrei sa te complici cu un formular de adaugare si le adaugi o singura data).
3. Faci un script care preia numarul zilei din an si in functie de aceasta selecteaza randul respectiv din tabel si-l afiseaza. Cam asa:

Cod: Selectaţi tot

<?php
$ziua = date('z');       // Preia nr. zi din an, de la 0 la 365
// Extrage randul zilei din tabel
$sql = "SELECT `info` FROM `tabel` WHERE `ziua`='$ziua' LIMIT 1";
$rezultat = mysql_query($sql);
if (mysql_num_rows($rezultat) == 0) {
    $info = '0 rezultate';
}
else {
  while ($rand = mysql_fetch_assoc($rezultat)) {
    $info = $rand['info'];
  }
}

// Afiseaza informatia
echo $info;
?>
- Paartea cu timpul in functie de ora utilizatorului e mai complicat, trebuie JavaScript si Ajax fiindca cu JS poti prelua ora calculatorului client, php se executa pe server. Daca studiezi cursul de Ajax de pe site poate o sa ai idee cum functioneaza.
Sau daca te intereseaza doar data romaniei, adaugi urmatorul cod in script, inainte de preluarea zilei:
date_default_timezone_set('Europe/Bucharest'); // Seteaza zona Romania pt. definirea datei

Cam asta e. Spor.

anunt pentru fiecare zi

Scris: Dum Mai 02, 2010
de trif
multumesc pentru script si o sa ma apuc astazi de baza de date dar este o mica problema ca cu java script nu prea ma am asa de mult doar stiu sa le modific si sa le implementez dupa ce vreau eu nu sa fac eu de la 0. daca ma poti ajuta si scuze pt nestiinta mea eu tot incerc sa fac dar cu cat ma aprofundez in ceva se complica tot mai mult :lol: adica iti vin idei tot mai multe si nu prea sti cum sa le rezolvi. ms inca o data. cu stima trif

anunt pentru fiecare zi

Scris: Dum Mai 02, 2010
de MarPlo
Daca utilizatorii sunt in majoritate din Romania, nu e nevoie de JS, ci adaugi codul de zona, cum am specificat.
Daca vrei neaparat data client, studiaza intai cursul de Ajax, ca asta trebuie foolosit.
In principiu, apelezi scriptul php prin Ajax, care-i transmite data calculatorului client, apoi JavaScript preia raspunsul de la php si-l afiseaza intr-un tag html din pagina.
Mai mult nu am cum sa explic si nici sa fac eu.
Unde te incurci, mai poti cauta si pe net resurse.

anunt pentru fiecare zi

Scris: Joi Iul 01, 2010
de trif
am facut dar formatul campului "data" ce sa fie ca sa imi ia? am pus formatul data "2010-01-01" si nu imi merge si zice "0 rezultate". cu stima trif

anunt pentru fiecare zi

Scris: Joi Iul 01, 2010
de MarPlo
Daca e vorba de 365 de randuri, pt. fiecare zi din an, poti adauga doar numarul zilei, de la 0 la 365, iar in PHP se afla ziua din an cu date("z") si pe baza ei gasesti randul cu acel nr.
Daca vrei sa faci altfel, cu data zilei, nu stiu fiindca asi face cum am scris mai sus.

anunt pentru fiecare zi

Scris: Joi Iul 01, 2010
de trif
mersi merge!! am bd asta

Cod: Selectaţi tot

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

CREATE TABLE IF NOT EXISTS `anunturi` (
  `id` int(255) DEFAULT NULL,
  `mesaj` text,
  `data` int(255) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO `anunturi` (`id`, `mesaj`, `data`) VALUES
(0, '0', '0'),
(1, '1', '1'),
(2, '2', '2'),
(3, '3', '3'),
(4, '4', '4'),
(5, '5', '5'),
(6, '6', '6'),
(7, '7', '7'),
(8, '8', '8'),
(9, '9', '9'),
(10, '10', '10'),
(11, '11', '11'),
(12, '12', '12'),
(13, '3', '13'),
(14, '4', '14'),
(15, '5', '15'),
(16, '6', '16'),
(17, '7', '17'),
(18, '8', '18'),
(19, '9', '19'),
(20, '0', '20'),
(21, '1', '21'),
(22, '2', '22'),
(23, '3', '23'),
(24, '4', '24'),
(25, '5', '25'),
(26, '6', '26'),
(27, '7', '27'),
(28, '8', '28'),
(29, '9', '29'),
(30, '0', '30'),
(31, '1', '31'),
(32, '2', '32'),
(33, '3', '33'),
(34, '4', '34'),
(35, '5', '35'),
(36, '6', '36'),
(37, '7', '37'),
(38, '8', '38'),
(39, '9', '39'),
(40, '0', '40'),
(41, '1', '41'),
(42, '2', '42'),
(43, '3', '43'),
(44, '4', '44'),
(45, '5', '45'),
(46, '6', '46'),
(47, '7', '47'),
(48, '8', '48'),
(49, '9', '49'),
(50, '0', '50'),
(51, '1', '51'),
(52, '2', '52'),
(53, '3', '53'),
(54, '4', '54'),
(55, '5', '55'),
(56, '6', '56'),
(57, '7', '57'),
(58, '8', '58'),
(59, '9', '59'),
(60, '0', '60'),
(61, '1', '61'),
(62, '2', '62'),
(63, '3', '63'),
(64, '4', '64'),
(65, '5', '65'),
(66, '6', '66'),
(67, '7', '67'),
(68, '8', '68'),
(69, '9', '69'),
(70, '0', '70'),
(71, '1', '71'),
(72, '2', '72'),
(73, '3', '73'),
(74, '4', '74'),
(75, '5', '75'),
(76, '6', '76'),
(77, '7', '77'),
(78, '8', '78'),
(79, '9', '79'),
(80, '0', '80'),
(81, '1', '81'),
(82, '2', '82'),
(83, '3', '83'),
(84, '4', '84'),
(85, '5', '85'),
(86, '6', '86'),
(87, '7', '87'),
(88, '8', '88'),
(89, '9', '89'),
(90, '0', '90'),
(91, '1', '91'),
(92, '2', '92'),
(93, '3', '93'),
(94, '4', '94'),
(95, '5', '95'),
(96, '6', '96'),
(97, '7', '97'),
(98, '8', '98'),
(99, '9', '99'),
(100, '0', '100'),
(101, '1', '101'),
(102, '2', '102'),
(103, '3', '103'),
(104, '4', '104'),
(105, '5', '105'),
(106, '6', '106'),
(107, '7', '107'),
(108, '8', '108'),
(109, '9', '109'),
(110, '10', '110'),
(111, '11', '111'),
(112, '12', '112'),
(113, '3', '113'),
(114, '4', '114'),
(115, '5', '115'),
(116, '6', '116'),
(117, '7', '117'),
(118, '8', '118'),
(119, '9', '119'),
(120, '0', '120'),
(121, '1', '121'),
(122, '2', '122'),
(123, '3', '123'),
(124, '4', '124'),
(125, '5', '125'),
(126, '6', '126'),
(127, '7', '127'),
(128, '8', '128'),
(129, '9', '129'),
(130, '0', '130'),
(131, '1', '131'),
(132, '2', '132'),
(133, '3', '133'),
(134, '4', '134'),
(135, '5', '135'),
(136, '6', '136'),
(137, '7', '137'),
(138, '8', '138'),
(139, '9', '139'),
(140, '0', '140'),
(141, '1', '141'),
(142, '2', '142'),
(143, '3', '143'),
(144, '4', '144'),
(145, '5', '145'),
(146, '6', '146'),
(147, '7', '147'),
(148, '8', '148'),
(149, '9', '149'),
(150, '0', '150'),
(151, '1', '151'),
(152, '2', '152'),
(153, '3', '153'),
(154, '4', '154'),
(155, '5', '155'),
(156, '6', '156'),
(157, '7', '157'),
(158, '8', '158'),
(159, '9', '159'),
(160, '0', '160'),
(161, '1', '161'),
(162, '2', '162'),
(163, '3', '163'),
(164, '4', '164'),
(165, '5', '165'),
(166, '6', '166'),
(167, '7', '167'),
(168, '8', '168'),
(169, '9', '169'),
(170, '0', '170'),
(171, '1', '171'),
(172, '2', '172'),
(173, '3', '173'),
(174, '4', '174'),
(175, '5', '175'),
(176, '6', '176'),
(177, '7', '177'),
(178, '8', '178'),
(179, '9', '179'),
(180, '0', '180'),
(181, '1', '181'),
(182, '2', '182'),
(183, '3', '183'),
(184, '4', '184'),
(185, '5', '185'),
(186, '6', '186'),
(187, '7', '187'),
(188, '8', '188'),
(189, '9', '189'),
(190, '0', '190'),
(191, '1', '191'),
(192, '2', '192'),
(193, '3', '193'),
(194, '4', '194'),
(195, '5', '195'),
(196, '6', '196'),
(197, '7', '197'),
(198, '8', '198'),
(199, '9', '199'),
(200, '0', '200'),
(201, '1', '201'),
(202, '2', '202'),
(203, '3', '203'),
(204, '4', '204'),
(205, '5', '205'),
(206, '6', '206'),
(207, '7', '207'),
(208, '8', '208'),
(209, '9', '209'),
(210, '10', '210'),
(211, '11', '211'),
(212, '12', '212'),
(213, '3', '213'),
(214, '4', '214'),
(215, '5', '215'),
(216, '6', '216'),
(217, '7', '217'),
(218, '8', '218'),
(219, '9', '219'),
(220, '0', '220'),
(221, '1', '221'),
(222, '2', '222'),
(223, '3', '223'),
(224, '4', '224'),
(225, '5', '225'),
(226, '6', '226'),
(227, '7', '227'),
(228, '8', '228'),
(229, '9', '229'),
(230, '0', '230'),
(231, '1', '231'),
(232, '2', '232'),
(233, '3', '233'),
(234, '4', '234'),
(235, '5', '235'),
(236, '6', '236'),
(237, '7', '237'),
(238, '8', '238'),
(239, '9', '239'),
(240, '0', '240'),
(241, '1', '241'),
(242, '2', '242'),
(243, '3', '243'),
(244, '4', '244'),
(245, '5', '245'),
(246, '6', '246'),
(247, '7', '247'),
(248, '8', '248'),
(249, '9', '249'),
(250, '0', '250'),
(251, '1', '251'),
(252, '2', '252'),
(253, '3', '253'),
(254, '4', '254'),
(255, '5', '255'),
(256, '6', '256'),
(257, '7', '257'),
(258, '8', '258'),
(259, '9', '259'),
(260, '0', '260'),
(261, '1', '261'),
(262, '2', '262'),
(263, '3', '263'),
(264, '4', '264'),
(265, '5', '265'),
(266, '6', '266'),
(267, '7', '267'),
(268, '8', '826'),
(269, '9', '269'),
(270, '0', '270'),
(271, '1', '271'),
(272, '2', '272'),
(273, '3', '273'),
(274, '4', '274'),
(275, '5', '275'),
(276, '6', '276'),
(277, '7', '277'),
(278, '8', '278'),
(279, '9', '279'),
(280, '0', '280'),
(281, '1', '281'),
(282, '2', '282'),
(283, '3', '283'),
(284, '4', '284'),
(285, '5', '285'),
(286, '6', '286'),
(287, '7', '287'),
(288, '8', '288'),
(289, '9', '289'),
(290, '0', '290'),
(291, '1', '291'),
(292, '2', '292'),
(293, '3', '293'),
(294, '4', '294'),
(295, '5', '295'),
(296, '6', '296'),
(297, '7', '297'),
(298, '8', '829'),
(299, '9', '299'),
(300, '0', '300'),
(301, '1', '301'),
(302, '2', '302'),
(303, '3', '303'),
(304, '4', '304'),
(305, '5', '305'),
(306, '6', '306'),
(307, '7', '307'),
(308, '8', '308'),
(309, '9', '309'),
(310, '10', '310'),
(311, '11', '311'),
(312, '12', '312'),
(313, '3', '313'),
(314, '4', '314'),
(315, '5', '315'),
(316, '6', '316'),
(317, '7', '317'),
(318, '8', '318'),
(319, '9', '319'),
(320, '0', '320'),
(321, '1', '321'),
(322, '2', '322'),
(323, '3', '323'),
(324, '4', '324'),
(325, '5', '325'),
(326, '6', '326'),
(327, '7', '327'),
(328, '8', '328'),
(329, '9', '329'),
(330, '0', '330'),
(331, '1', '331'),
(332, '2', '332'),
(333, '3', '333'),
(334, '4', '334'),
(335, '5', '335'),
(336, '6', '336'),
(337, '7', '337'),
(338, '8', '338'),
(339, '9', '339'),
(340, '0', '340'),
(341, '1', '341'),
(342, '2', '342'),
(343, '3', '343'),
(344, '4', '344'),
(345, '5', '345'),
(346, '6', '346'),
(347, '7', '347'),
(348, '8', '348'),
(349, '9', '349'),
(350, '0', '350'),
(351, '1', '351'),
(352, '2', '352'),
(353, '3', '353'),
(354, '4', '354'),
(355, '5', '355'),
(356, '6', '356'),
(357, '7', '357'),
(358, '8', '358'),
(359, '9', '359'),
(360, '0', '350'),
(361, '1', '361'),
(362, '2', '362'),
(363, '3', '363'),
(364, '4', '364'),
(365, '5', '365');
si codul de la tine

Cod: Selectaţi tot

<?php
require_once('conectare.php'); 
$data = date('z');       // Preia nr. zi din an, de la 0 la 365
// Extrage randul zilei din tabel
$sql = "SELECT `mesaj` FROM `anunturi` WHERE `data`='$data' LIMIT 1";
$rezultat = mysql_query($sql);
if (mysql_num_rows($rezultat) == 0) {
    $mesaj = '0 rezultate';
}
else {
  while ($rand = mysql_fetch_assoc($rezultat)) {
    $mesaj = $rand['mesaj'];
  }
}
// Afiseaza mesajrmatia
echo $mesaj;
mysql_close();
?> 
de extragere date!
si mai este cel de conectare

Cod: Selectaţi tot

?php
$username="root";
$password="parola_ta";
$database="nume_bd";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Nu se poate deschide BD");
?>
l-am pus daca mai doreste cineva sa faca acest script!! sper ca am procedat bine!doar trebuie ca sa puna in loc de 1,2,3 randul mesaj sa puna mesajul care trebuie. si in rest este super bine. mersi inca o data! cu stima trif