Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: code syntax

  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Posts
    245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    code syntax

    Hi,

    Can anybody tell me why this code isnt working perfectly...
    its giving me a large amount of records, even though i only have 2 of them in my database..im guessing it is because of the counter, but even if i take it out, it still gives me all those records.

    PHP Code:
                      <?php
    $counter 
    0;
    do {
    $color = ($counter 1)? "#ccc" "#fff";
    $counter++;

    mysql_select_db($database_gabriel$gabriel);
    $query_newsletter2 "SELECT * FROM newsletter_articles ORDER BY year DESC, month DESC, day DESC";
    $newsletter2 mysql_query($query_newsletter2$gabriel) or die(mysql_error());
    $row_newsletter2 mysql_fetch_assoc($newsletter2);
    $totalRows_newsletter2 mysql_num_rows($newsletter2);

    $year2 $row_newsletter2['year'];
    $month2 $row_newsletter2['month'];
    $day2 $row_newsletter2['day'];

    ?>
                      <tr style="background: <?php print $color;?>;">
                        <td align="left" valign="top"><a href="previousnewsletters.php?date=<? print "".$year2."-".$month2."-".$day2.""?>" class="LinkBlueLight" title="<?php echo $row_newsletter2['title']; ?>"><?php echo $row_newsletter2['title']; ?></a></td>
                        <td align="left" valign="top"><?php echo $row_newsletter2['description']; ?></td>
                        <td align="right"><?php echo $row_newsletter2['year']; ?> - <?php echo $row_newslette2['month']; ?> - <?php echo $row_newsletter2['day']; ?></td>
                      </tr>
                      <?php } while (
    $row_newsletter2 mysql_fetch_assoc($newsletter2)
    );
    ?>

  • #2
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    why do you have mysql_select_db($database_gabriel, $gabriel); in there ? that could be why

  • #3
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,778
    Thanks
    19
    Thanked 155 Times in 146 Posts
    something like this:

    PHP Code:
    <?php
    $counter 
    2;

    mysql_select_db($database_gabriel$gabriel);
    $query_newsletter2 "SELECT * FROM newsletter_articles ORDER BY year DESC, month DESC, day DESC";
    $newsletter2 mysql_query($query_newsletter2$gabriel) or die(mysql_error());
    $totalRows_newsletter2 mysql_num_rows($newsletter2);

    if (
    $totalRows_newsletter2 >= '1')
    {
        while (
    $row_newsletter2 mysql_fetch_assoc($newsletter2))
        {
                  
    $year2 $row_newsletter2['year'];
                  
    $month2 $row_newsletter2['month'];
                  
    $day2 $row_newsletter2['day'];

    ?>
                      <tr style="background: <?php 

    if ($counter == 0)
    {
         print 
    '#ccc';
    }
    else
    {
         print 
    '#fff';
    }

    ?>;">
                        <td align="left" valign="top"><a href="previousnewsletters.php?date=<? print "".$year2."-".$month2."-".$day2.""?>" class="LinkBlueLight" title="<?php echo $row_newsletter2['title']; ?>"><?php echo $row_newsletter2['title']; ?></a></td>
                        <td align="left" valign="top"><?php echo $row_newsletter2['description']; ?></td>
                        <td align="right"><?php echo $row_newsletter2['year']; ?> - <?php echo $row_newslette2['month']; ?> - <?php echo $row_newsletter2['day']; ?></td>
                      </tr>
                      <?php
               
               $counter
    ++;
           }
    }

    ?>
    Last edited by chump2877; 06-11-2006 at 12:12 AM.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #4
    Regular Coder
    Join Date
    Jan 2004
    Posts
    245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well its there because DreamWeaver automatically puts it..but i took it out, and it still gives me a huge amount of records

  • #5
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what happens if you run the query from phpMyAdmin or mysql itself? and, take out the first time you have this:
    Code:
    $row_newsletter2 = mysql_fetch_assoc($newsletter2);
    Last edited by fci; 06-11-2006 at 12:09 AM.

  • #6
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,778
    Thanks
    19
    Thanked 155 Times in 146 Posts
    the problem is that he's executing his query inside the do loop, when it onlt needs to be performed once (before the loop)...he's performing the the query over and over again, and the internal results pointer isn;t moving ahead, but rather stalling on the same record over and over again...he's not iterating through the result set, rather he's reproducing the result set over and over again and listing the first record that pops up...that's what it looks like
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •