PHP and mySQL help

Discussion in 'OT Technology' started by GotVtec, Jul 30, 2003.

  1. GotVtec

    GotVtec 8th World Wonder

    Joined:
    Mar 14, 2000
    Messages:
    575
    Likes Received:
    0
    Location:
    Omaha, NE
    I have this script I am trying to right, but I can't figure out something.

    I am trying to make a news script that shows all of the headlines when you goto news.php and then each headline has a link to the full article depending on its id number in the database.

    I get an error you can see at http://www.usdphidelts.com/chapter/news.php , but if you pass the variable into the script, like at http://www.usdphidelts.com/chapter/news.php?id=3 , then everything works fine.

    Here is a snipet of my code, I think it has something to do with my if, else statement.

    PHP:
    if ($_GET["id"] == "$id")
                        {
                            
    // SQL Query
                            
    $sql mysql_query("SELECT * FROM sda_news WHERE id = $id");
                            
                            
    // Header rows
                            
    print ("<table cellpadding='2' cellspacing='1'  class='tbborder' summary='border' bgcolor='#FFFFFF'>");
                            
                            
    $alternate "2"// number of alternating rows
                            
    while ($row mysql_fetch_array($sql)) {
                            
    $date $row["date"]; //name of field
                            
    $title $row["headline"];
                            
    $email $row["email"];
                            
    $story $row["news"];
                            
    $id $row["id"];
                            
    $auth $row["written_by"];
                            
                            list(
    $year,$month,$day) = split('-',$date);
                            
    $date_2 mktime(12,0,0,$month,$day,$year);
                            
    $format_date date("m/d/y",$date_2);
                            
                            print (
    "\n
                            <!-- Info for Article# id -->
                            <tr class='clcategory'>
                                <td>
                                <table cellpadding='0' cellspacing='0' class='tbarticle' summary='article'>
                                <tr>
                                    <td class='txtbold'>
    $title</td>    
                                </tr>
                                </table>
                                </td>
                            </tr>
                            <tr class='clsecond'>
                                <td class='fsmall'>Posted on: 
    $format_date</td>
                            </tr>
                            <tr class='clfirst'>
                                <td>
                                <table cellpadding='0' cellspacing='0' class='tbarticle' summary='article'>
                                <tr class='txttop'>
                                    <td>
    $story</td>
                                </tr>
                                </table>
                                </td>
                            </tr>
                            <tr class='clsecondright'>
                                <td>Posted by: <a href='mailto:
    $email'>$auth</a></td>
                            </tr>"
    );
                            
                            }
                            
                            print (
    "\n</table>");
                            
                        }
                        
                        else {
                            
                        
    // SQL Query
                        
    $sql mysql_query("SELECT * FROM sda_news ORDER BY date");
                        
    $num_rows mysql_num_rows($sql);
                        
                        
    // Header rows
                        
    print ("<table cellpadding='0' cellspacing='1'  class='tbborder' summary='border' bgcolor='#FFFFFF'>
                        <tr class='clcategory'>
                        <td>
                        <table cellpadding='2' cellspacing='0' width='100%' class='tbarticle'>
                        <tr class='txtbold'>
                        <td colspan='2'>Recent Headlines from SDA</td>"
    );
                        
                        
    $alternate "2"// number of alternating rows
                        
    while ($row mysql_fetch_array($sql)) {
                        
    $date $row["date"]; //name of field
                        
    $title $row["headline"];
                        
    $email $row["email"];
                        
    $story $row["news"];
                        
    $id $row["id"];
                        
    $auth $row["written_by"];
                        
                        if (
    $alternate == "1") {
                        
    $class "clsecond";
                        
    $alternate "2";
                        }
                        
                        else {
                        
    $class "clfirst";
                        
    $alternate "1";
                        }
                        
                        list(
    $year,$month,$day) = split('-',$date);
                        
    $date_2 mktime(12,0,0,$month,$day,$year);
                        
    $format_date date("m/d/y",$date_2);
                        
                        print (
    "\n</tr>\n\n<!-- Info for News# $id -->
                        <tr class=
    $class>
                        <td><img src='../images/arrow.gif'>
    $format_date</td>
                        <td><a class='bodymail' href='news.php?id=
    $id'>$title</a></td>");
                        
                        }
                        
                        print (
    "</tr>
                        </table>
                        </td>
                        </tr>
                        </table>"
    );
                        
                        }
     
  2. Jericho

    Jericho Active Member

    Joined:
    Oct 21, 2002
    Messages:
    34,140
    Likes Received:
    0
    I'm not sure this is what you need but try switching your

    $_GET["id"] == "$id")

    to

    $_POST["id"] == "$id"
     
  3. GotVtec

    GotVtec 8th World Wonder

    Joined:
    Mar 14, 2000
    Messages:
    575
    Likes Received:
    0
    Location:
    Omaha, NE
    I figured it:
    PHP:
    if(isset($_GET["id"])){  
    // code
    }
     

Share This Page