1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

date() problem

Discussion in 'PHP' started by moondancer, Sep 29, 2007.

  1. #1
    Hi, guys.
    I need some help for this piece of code:

    //define vars
    $date = $_POST['date'];
    $one = $_POST['one'];
    $two = $_POST['two'];
    $three = $_POST['three'];


    $d = date("D");

    $aa = time() + (1 * 24 * 60 * 60);
    $bb = time() + (2 * 24 * 60 * 60);
    $cc = time() + (3 * 24 * 60 * 60);
    $dd = time() + (4 * 24 * 60 * 60);
    $ee = time() + (5 * 24 * 60 * 60);
    $ff = time() + (6 * 24 * 60 * 60);
    $gg = time() - (6 * 24 * 60 * 60);
    $hh = time() - (5 * 24 * 60 * 60);
    $ii = time() - (4 * 24 * 60 * 60);
    $jj = time() - (3 * 24 * 60 * 60);
    $kk = time() - (2 * 24 * 60 * 60);
    $ll = time() - (1 * 24 * 60 * 60);

    if ($d=="Mon") {
    $varone = date('Y-m-d');
    $vartwo = date('Y-m-d', $aa);
    $varthree = date('Y-m-d', $bb);
    $varfour = date('Y-m-d', $cc);
    $varfive = date('Y-m-d', $dd);
    $varsix = date('Y-m-d', $ee);
    }

    else {
    if ($d=="Tue") {
    $varone = date('Y-m-d', $ll);
    $vartwo = date('Y-m-d');
    $varthree = date('Y-m-d', $aa);
    $varfour = date('Y-m-d', $bb);
    $varfive = date('Y-m-d', $cc);
    $varsix = date('Y-m-d', $dd);
    }

    else {
    if ($d=="Wed") {
    $varone = date('Y-m-d', $kk);
    $vartwo = date('Y-m-d', $ll);
    $varthree = date('Y-m-d');
    $varfour = date('Y-m-d', $aa);
    $varfive = date('Y-m-d', $bb);
    $varsix = date('Y-m-d', $cc);
    }

    else {
    if ($d=="Thu") {
    $varone = date('Y-m-d', $jj);
    $vartwo = date('Y-m-d', $kk);
    $varthree = date('Y-m-d', $ll);
    $varfour = date('Y-m-d');
    $varfive = date('Y-m-d', $aa);
    $varsix = date('Y-m-d', $bb);
    }

    else {
    if ($d=="Fri") {
    $varone = date('Y-m-d', $ii);
    $vartwo = date('Y-m-d', $jj);
    $varthree = date('Y-m-d', $kk);
    $varfour = date('Y-m-d', $ll);
    $varfive = date('Y-m-d');
    $varsix = date('Y-m-d', $aa);
    }

    else {
    if ($d=="Sat") {
    $varone = date('Y-m-d', $hh);
    $vartwo = date('Y-m-d', $ii);
    $varthree = date('Y-m-d', $jj);
    $varfour = date('Y-m-d', $kk);
    $varfive = date('Y-m-d', $ll);
    $varsix = date('Y-m-d');
    }

    else {
    if ($d=="Sun") {
    $varone = date('Y-m-d', $gg);
    $vartwo = date('Y-m-d', $hh);
    $varthree = date('Y-m-d', $ii);
    $varfour = date('Y-m-d', $jj);
    $varfive = date('Y-m-d', $kk);
    $varsix = date('Y-m-d', $ll);
    }
    }
    }
    }
    }
    }
    }


    Here comes the problem:

    $sql = "SELECT one, two, three, date FROM table WHERE date='$varone'";

    $result = mysql_query($sql) or die("Couldn't execute query");
    if(mysql_num_rows($result)) {
    while($row = mysql_fetch_row($result))
    {

    echo("<ul><li>$one</li><li>$two</li><li>$three</li></ul>");
    }

    } else {

    echo("<p>No results for $varone.</p>");

    }


    If $varone exists the result I get is only HTML code:
    <ul><li></li><li></li><li></li></ul>

    if it doesn't:
    <p>No results for $varone.</p> (the expected one)

    I'm stuck. Please help!
     
    moondancer, Sep 29, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Perhaps:
    
    echo("<ul><li>{$row['one']}</li><li>{$row['two']}</li><li>{$row['three']}</li></ul>");
    
    PHP:
    ??
     
    nico_swd, Sep 29, 2007 IP
  3. moondancer

    moondancer Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the quick reply, but ... again: only the HTML code is parsed. :(
     
    moondancer, Sep 29, 2007 IP
  4. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #4
    I can't see the purpose of this line:
    if(mysql_num_rows($result)) {

    Try..

    $sql = "SELECT one, two, three, date FROM table WHERE date='$varone'";

    $result = mysql_query($sql) or die("Couldn't execute query");
    while($row = mysql_fetch_row($result))
    {
    $one = $row['one'];
    $two = $row['two'];
    $three = $row['three'];

    echo '<ul><li>$one</li><li>$two</li><li>$three</li></ul>';
    }

    } else {

    echo '<p>No results for $varone.</p>';

    }
     
    crazyryan, Sep 29, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    ^^ Note that variables won't be parsed between single quotes.
     
    nico_swd, Sep 29, 2007 IP
  6. moondancer

    moondancer Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    :(

    I did COPY / PASTE of this code:

    $sql = "SELECT one, two, three, date FROM table WHERE date='$varone'";

    $result = mysql_query($sql) or die("Couldn't execute query");
    while($row = mysql_fetch_row($result))
    {
    $one = $row['one'];
    $two = $row['two'];
    $three = $row['three'];

    echo "<ul><li>$one</li><li>$two</li><li>$three</li></ul>";
    }


    and again - the result is only html


    -----
    if this helps - here is my SQL structure


    CREATE TABLE `table` (
    `id` int(11) NOT NULL auto_increment,
    `one` varchar(255) NOT NULL default '',
    `two` varchar(255) NOT NULL default '',
    `three` varchar(255) NOT NULL,
    `date` date NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `date` (`date`)
    )
     
    moondancer, Sep 29, 2007 IP
  7. moondancer

    moondancer Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thank you, guys.

    I figure it out (at last)

    Here it is:

    $sql = "SELECT one, two, three, date FROM table WHERE date='$varone'";

    $result = mysql_query($sql) or die("Couldn't execute query");
    while($row = mysql_fetch_array($result))
    {
    $one = $row['one'];
    $two = $row['two'];
    $three = $row['three'];

    echo "<ul><li>$one</li><li>$two</li><li>$three</li></ul>";
     
    moondancer, Sep 29, 2007 IP