+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11

Thread: Need PHP/SQL code help...to fix written code

  1. #1
    Barn Newbie honeybeeaz is an unknown quantity at this point honeybeeaz's Avatar
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    4

    Need PHP/SQL code help...to fix written code

    I do volunteer work to a website by putting up their calendar and putting new entries into their database for their webpages.

    The old webmaster wrote the .php code a few years agoand it's been working fine until this week, but maybe it's because they are doing more photo collections this year??

    I added three entries into the database and the page doesn't show them. I "think" it's because the page will only display nine entries for the "new" photos. It divides the newest and then the older ones go in the second half of the table, entitled "archived".

    I don't know hardly anything about php. The only reason I do this is because I do understand databases.

    Can someone just take a look at the code and tell me what might need to be changed?

    THANK YOU IN ADVANCE! I will learn this...and I wish I could return the favor!

    Here's the code:
    PHP Code:
       echo "<div style='width:100%;height:180px;background-color:#FFFFFF;border-style:solid;border-width:2;overflow-x:auto;overflow-y:auto;'>";
    }
    ?>                            

    <table cellpadding="2" cellspacing="2" width="100%" border="0">
                             
    <?php     
    $sql 
    "SELECT collection_name, collection_desc, collection_link, photographer, date_format(collection_dt,'%b %e, %Y') AS collection_dt FROM photos ";
    $sql .= "WHERE datetime BETWEEN date_add(now(), interval -365 day) AND now() ";
    $sql .= "ORDER BY datetime DESC";                            
    $result mysql_query($sql$conn) or die(mysql_error());
    while (
    $newArray mysql_fetch_array($result)) {
        
    $pName $newArray['collection_name'];
        
    $pDesc  $newArray['collection_desc'];
        if (
    strlen($pDesc) < 1) {
        
    $pDesc $pName." Photo Collection";
        }
        
    $pURL $newArray['collection_link'];
        
    $pPhotographer $newArray['photographer'];
        if (
    strlen($pPhotographer) < 1) {
        
    $pPhotographer "Anonymous";
        }
        
    $pDate $newArray['collection_dt'];
        if (
    strlen($pDate) < 1) {
        
    $pDate "";
        } else {
        
    $pDate "&nbsp&nbsp[Taken:&nbsp".$pDate."]";
        }

        echo 
    "<tr>";
        echo 
    "<td class='row1'><a href='$pURL' style='text-decoration:none' title='Click to open this Photo Collection'><b>";
        echo 
    $pName;
        echo 
    "</b><br>$pDesc<br>";
        echo 
    "<font class='Copyright'>Photographer: $pPhotographer $pDate</font>";
        echo 
    "</a></td>";
        echo 
    "</tr>";
    }
    ?>

    </table>
    </div>
    </td>
    </tr>
    <tr height="20" class="BlueHeader">
        <td width="100%">Archived Photo Collections</td>
    </tr>
    <tr>
        <td align="center">

    <?php
    if (strpos($browser"MSIE") > 0) {
        echo 
    "<div style='width:100%;height:180px;background-color:#FFFFFF;border-style:solid;border-width:2;overflow-x:auto;overflow-y:auto;'>";
    }
    ?>    

    <table cellpadding="2" cellspacing="2" width="100%" border="0">
                             
    <?php     
    $sql 
    "SELECT collection_name, collection_desc, collection_link, photographer FROM photos ";
    $sql .= "WHERE datetime BETWEEN date_add(now(), interval -1460 day) AND date_add(now(), interval -365 day)";
    $sql .= "ORDER BY datetime DESC";
                            
    $result mysql_query($sql$conn) or die(mysql_error());

    while (
    $newArray mysql_fetch_array($result)) {
        
    $pName $newArray['collection_name'];
        
    $pDesc  $newArray['collection_desc'];
        if (
    strlen($pDesc) < 1) {
        
    $pDesc $pName." Photo Collection";
        }
        
    $pURL $newArray['collection_link'];
        
    $pPhotographer $newArray['photographer'];
        if (
    strlen($pPhotographer) < 1) {
        
    $pPhotographer "Anonymous";
        }

        
    $pDate $newArray['collection_dt'];
        if (
    strlen($pDate) < 1) {
        
    $pDate "";
        } else {
        
    $pDate "&nbsp&nbsp[Taken:&nbsp".$pDate."]";
        }

        echo 
    "<tr>";
        echo 
    "<td class='row1'><a href='$pURL' style='text-decoration:none' title='Click to open this Photo Collection'><b>";
        echo 
    $pName;
        echo 
    "</b><br>$pDesc<br>";
        echo 
    "<font class='Copyright'>Photographer: $pPhotographer</font>";
        echo 
    "</a></td>";
        echo 
    "</tr>";
    }
    ?>

    </table>
    </div>
    Last edited by don94403; November 10th, 2008 at 01:10 AM. Reason: Add [php] tags to make code readable.

  2. #2
    Moderator don94403 is a jewel in the rough don94403 is a jewel in the rough don94403 is a jewel in the rough don94403's Avatar
    Join Date
    Mar 2008
    Location
    San Mateo, CA, USA
    Posts
    313
    Blog Entries
    8
    Real Name
    Don Ravey
    Rep Power
    6

    I can appreciate the difficult situation in which you find yourself, but it's quite hard to help a non-programmer to debug a program at a distance.

    From what I can see, there's nothing that limits the items that are displayed, besides the one-year and four-year past dates. However, you have only shown a part of the script, and significantly, not the code that inputs new items.

    In situations like this where a program has been working for a long time, but suddenly doesn't work properly, the thing to ask is What changed? Computer programs don't take whims and stop working. Something always has changed. Try to determine what has changed.

    As a wild, outside guess, my first thought is that the 3 new entries never actually got entered in the database, or were entered without the appropriate date value in the field "datetime" (which, by the way, is really bad practice, since that is a keyword in PHP, and shouldn't be used as the name of a field in a table. But since it has been working for several years, it's apparently not causing a problem in your script). If you have the ability to look at your data, perhaps using phpMyAdmin or a similar database utility, the first thing to do would be to see if the data ever got entered in the table.

  3. #3
    Barn Newbie honeybeeaz is an unknown quantity at this point honeybeeaz's Avatar
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    4

    Okay, I thought I should post an image that shows database entries. The collection_dt has never been used consistently, some of the entries show NULL, yet they work. I've tried changing the datetime to an earlier date, just a few months. And, tried matching the collection_dt to the same date.

    Do I need to show any include files?

    I wondered if the table was limiting to 9 entries.

    On the image, the rows for 103,104, and 105 are the ones that don't show. The entries for 100, 101, and 102 do work. Row 104 is the entry that I modified on datetime collection_dt. Normally, I don't put anything in the collection_dt the reason it shows NULL-- but then those rows worked!

    This code has been used for a few years and I've been putting in the entries for about one year... not quite one year. For all I know, it's been broken in the past, but no one else noticed. I always check the pages after I do database entries....

    If you can help... I'll post whatever you need. It is a volunteer job, no money to the website. We are bikers and any money raised is for local charities (kids, shelters, etc)

    Thanks in advance... really, thanks!!


  4. #4
    Moderator don94403 is a jewel in the rough don94403 is a jewel in the rough don94403 is a jewel in the rough don94403's Avatar
    Join Date
    Mar 2008
    Location
    San Mateo, CA, USA
    Posts
    313
    Blog Entries
    8
    Real Name
    Don Ravey
    Rep Power
    6

    Ahh! So what has changed is that you entered a date value in the 3 records where all the others have no value (NULL). And those are the records that are not being displayed.

    I think the issue is in the name of the column (field) that you are referring to as collection_dt. That's fine, if that's the name of the column that contains some null values. But that's not what the SQL query in your script is looking for. It now says (in 2 places):
    Code:
    WHERE datetime BETWEEN date_add(now(), interval -365 day) AND now()
    
    but it appears that it should say:
    Code:
    WHERE collection_dt BETWEEN date_add(now(), interval -365 day) AND now()
    
    This would also resolve my earlier criticism that "datetime" was being used as a column name. The mystery is how it could have worked all this time with that error. Perhaps because nobody was using that field, I'm not sure.

    Again, it's hard to guide someone who is inexperienced with PHP in debugging a script, but you might want to try making the above substitution in both places where the SQL string ($sql) is being defined. Just to make sure you don't create an even bigger problem, though, you should first make a backup copy of the script (perhaps name it xxxxx.php.bu, or something).

    I'm kind of groping in the dark, though, since I don't have the ability to see what the names of the columns in your table are. The above suggestion is based on the assumption that the column where some records have a NULL value is actually named "collection_dt". "Datetime" is a data type that determines what kind of data is stored in a column.

    As a temporary fix, I would first try removing the date values from those 3 records to see if they then appear.

  5. #5
    Barn Newbie honeybeeaz is an unknown quantity at this point honeybeeaz's Avatar
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    4

    I should have thought of including the column headers... sorry about that. So, here's another image.



    I don't normally put the date in the collection_id, but I did in the three latest in an effort to make them appear. I've taken the date out again, and the entry shows null.

    I've made a backup copy of the script and I'll make the edit you suggested. I hope it works....

  6. #6
    Barn Newbie honeybeeaz is an unknown quantity at this point honeybeeaz's Avatar
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    4

    What does this mean?

    $sql = "SELECT collection_name, collection_desc, collection_link, photographer,

    date_format(collection_dt,'%b %e, %Y') AS collection_dt FROM photos ";



    I understand the select for column names, but it seems to be converting to something and being used as the collection_dt?

  7. #7
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    It's taking the value from the column named "collection_dt" and converting the date format to this: %b %e, %Y

    It is then returning that new formatted date with an alias, which is also called "collection_dt".
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  8. #8
    Barn Newbie honeybeeaz is an unknown quantity at this point honeybeeaz's Avatar
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    4

    I thought maybe I should show you the settings on the database. Image one is for the entry.... image two is the database.




  9. #9
    Barn Newbie honeybeeaz is an unknown quantity at this point honeybeeaz's Avatar
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    4

    Don,

    I created a test .php page. I changed the datetime to be collection_dt in four places, because the sort was set to datetime.

    $sql .= "WHERE collection_dt BETWEEN date_add(now(), interval -1460 day) AND date_add(now(), interval -365 day)";
    $sql .= "ORDER BY collection_dt DESC";

    That resulted in blank results in the current section. Archived section seems to be the same. So, I changed the order by back to datetime.

    Still blank results in the current section. Archived seems to be the same.

    This is only on my test page, which is a edited copy of the current.

  10. #10
    Barn Newbie honeybeeaz is an unknown quantity at this point honeybeeaz's Avatar
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    4

    Quote Originally Posted by jmurrayhead View Post
    It's taking the value from the column named "collection_dt" and converting the date format to this: %b %e, %Y

    It is then returning that new formatted date with an alias, which is also called "collection_dt".
    Like an alias? Seems like it could conflict.

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. cdosys code
    By santosh_pawar in forum ASP Development
    Replies: 4
    Last Post: October 22nd, 2008, 05:07 AM
  2. Custom Code Tip
    By Lauramc in forum SQL Server Reporting Services Help
    Replies: 0
    Last Post: August 6th, 2008, 09:31 PM
  3. Slow Concat Code
    By AOG123 in forum Microsoft Access
    Replies: 30
    Last Post: May 8th, 2008, 03:10 PM
  4. Is this valid ASP/ADO Code
    By Wolffy in forum ASP Development
    Replies: 4
    Last Post: April 14th, 2008, 09:12 AM
  5. PHP code displays in browser
    By theChris in forum PHP Development
    Replies: 5
    Last Post: March 31st, 2008, 06:16 PM

Bookmarks

Posting Permissions

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

SEO by vBSEO