Rewriting if statements to function in php5

Discussion in 'PHP' started by soulburn, Oct 29, 2007.

  1. #1
    I switched hosting, so i went from php4 to php5. The newsystem used was an opensource from 2006 and i know its not the best coding. I have no time to rewrite the whole news system (with an admin part), so im trying to find ways to alter just enough to have it up and running, till 2008. Im trying to change the if statements but i don't get the fullnews to show (news.php?go=fullnews&newsid=xxx) What am i missing?

    thanks
    S.


    <? include "header.php";
    ################### NEWS CATEGORY ###################
    //if($go=="list") {
    if($_GET['go']=="list") {
    $sql="SELECT id FROM news_publish";
    $result=mysql_query($sql);
    $totalrecord = mysql_num_rows($result);
    
    $pagesize = 6;  // set how many record you want to display per page
    $Prev_Page = $pageid-1;
    $Next_Page = $pageid+1;
    $totalpage = (int) ($totalrecord / $pagesize);
    if (($totalrecord % $pagesize) != 0) {
     $totalpage += 1;
    }
    if (isset($pageid)) {
    
    $start = $pagesize * ($pageid - 1);
    }
    else {
    $pageid = 1;
    $start = 0;
    
    }
    ?>
    <!-- begin center -->
          <TD valign="top" style="PADDING-RIGHT: 15px; PADDING-LEFT: 15px; PADDING-BOTTOM: 15px; PADDING-TOP: 15px">
            <table width="100%" border="0" cellpadding="2" cellspacing="2" align="center">
    
    <?
    // Retrive data from db
    
    $sql="SELECT * FROM news_publish WHERE category='Articles' ORDER BY id DESC LIMIT $start, $pagesize";
    $result=mysql_query($sql);
    while($rows=mysql_fetch_array($result)){
    
    echo "
                            <tr>
                              <td>
                              <div class=\"newstitle\"><a href=\"news.php?go=fullnews&newsid=$rows[id]\">$rows[title]</a></div>
                              <div class=\"newsdate\">$rows[ldate]</div>";
                              if ($pub[pq]==1) {
                              echo "<a href=\"news.php?go=fullnews&newsid=$row[id]\"><img src=\"$urlpath/newsgfx/$rows[photo]\" alt=\"\" border=\"0\" width=\"100\" align=\"left\" vspace=\"5\" hspace=\"5\"></a>";
                              } else {
                              }
                              echo "
                              $rows[intro]
                              <br />
                              &nbsp;
                              </td>
                        </tr>";
                            }
                            ?>
            </table>
         <?php
                if($Next_Page==1){
                $Next_Page=$Next_Page+1;
                }
    
    if($Prev_Page >0)
    echo " <a href='$PHP_SELF?pageid=$Prev_Page'>PREVIOUS</a>&nbsp;&nbsp;&nbsp;";
    for ($i=1; $i<=$totalpage; $i++) {
      if ($i == $pageid) {
      echo  "<B>".$i . "</B>&nbsp;";
      }
      else {
       echo "[<a href=$PHP_SELF?pageid=$i>$i</a>]&nbsp;";
      }
    }
    
    if($pageid!=$totalpage){
    echo "&nbsp;&nbsp;&nbsp;<a href ='$PHP_SELF?pageid=$Next_Page'>NEXT</a>&nbsp;";
    }
    mysql_close();
    ?>
          </TD>
        </TR>
      </TABLE>
     <!-- end center -->
     
    <?
    }
    ################### FULLNEWS ###################
    //if($go=="fullnews") {
    if($_GET['go']=="fullnews") {
    $queryfull = "SELECT * FROM news_publish WHERE id='$newsid'";
    $qryfull = @mysql_query($queryfull,$connect) or die ("Wrong Query");
    $rowfull = mysql_fetch_array ($qryfull);
    $catfull = $rowfull[category];
    $isishort = nl2br($rowfull[intro]);
    $isifull = nl2br($rowfull[full]);
    ?>
    <!-- begin center -->
          <TD valign="top" style="PADDING-RIGHT: 15px; PADDING-LEFT: 15px; PADDING-BOTTOM: 15px; PADDING-TOP: 15px"> 
      <table width="95%" border="0" cellspacing="2" cellpadding="2">
        <tr>
          <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <?
                              echo "
                                      <tr>
                                    
                <td> <div class=\"newstitle\">$rowfull[title]</div>
                              <div class=\"newsdate\">$rowfull[ldate]</div>
                             </td>
                <td><div align=\"right\">
                              <a href=\"#\" onClick=\"MM_openBrWindow('print.php?go=fullnews&id=$rowfull[id]','addimage','scrollbars=yes,resizable=yes,width=800,height=550')\"><img src=\"$urlpath/images/print.gif\" border=\"0\" alt=\"Print View\" title=\"Print View\"></a>";
                              if ($allow_click==1){
                              $c=$rowfull[click];
                                $c++;
                                $d=$c;
                              @mysql_query("update news_publish set click='$d' where id=$newsid");
                              echo "&nbsp; $d views";
                              }
                              echo "
                              </div>
                              </td>
              </tr>
            </table></td>
        </tr>
        <tr>
          <td>";
              if ($rowfull[pq]==1) {
                              echo "<img src=\"$urlpath/newsgfx/$rowfull[photo]\" alt=\"\" border=\"0\"><br />";
                              } else {
                              }
                              echo "
                              $isishort<br /><br />
                              $isifull
                              <br />
                              &nbsp;
                              </td>
                        </tr>";
                            }
                            ?>
            </table>
    
    
    
    </TD>
        </TR>
      </TABLE>
     <!-- end center -->
     <? include "footer.php"; ?>
    
    PHP:
     
    soulburn, Oct 29, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Try setting these 2 lines on top of the code and see if you get any errors. I flew quick over your code but couldn't find anything. (It was a bit too long for my laziness. :p)

    
    error_reporting(E_ALL);
    ini_set('dosplay_errors', '1');
    
    PHP:
    Place this right after the first <? tag. Do you get any output at all?

    EDIT:

    I flew quick over it again, and it seems like it could be a register_globals issue (which is not PHP 5 related, by the way)

    Try setting these lines on top and see if it makes a difference.
    
    extract($_GET);
    extract($_POST);
    
    PHP:
     
    nico_swd, Oct 29, 2007 IP
  3. soulburn

    soulburn Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    wow u quick! I get a newslist with links, an error on the list

    Notice: Use of undefined constant pq - assumed 'pq' in /home/public_html/news.php on line 44

    But im not conerned bout that one, that i just need to take out.

    But the link gives me a blank fullnews page.

    btw.
    register_globals = Off. And it won't be turned on.


    thanks.
    S.
     
    soulburn, Oct 29, 2007 IP
  4. soulburn

    soulburn Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    oh!

    extract($_GET);extract($_POST);
    PHP:
    made it work!

    thank!
     
    soulburn, Oct 29, 2007 IP
  5. dadougalee

    dadougalee Peon

    Messages:
    589
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #5
    This may be a dumb question, but if globals are not registered, where did $newsid get initialized? You use it right away in the $_GET['fullnews'] if statement. If it never got initialized, this could be your problem.
     
    dadougalee, Oct 29, 2007 IP
  6. soulburn

    soulburn Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    not a dumb question at all because im a total newbie and i couldn't give you the answer even if you would torture me.
     
    soulburn, Oct 29, 2007 IP
  7. dadougalee

    dadougalee Peon

    Messages:
    589
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #7
    ok, well then you might want to look into that first. If that variable isn't initialized your piece of cose will then look like:

    $queryfull = "SELECT * FROM news_publish WHERE id=NULL";

    Which I think I can safely assume that this result will return <b>nothing</b>.
    Take a look at this more, and let me know what you find out.
     
    dadougalee, Oct 29, 2007 IP
  8. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #8
    nico_swd, Oct 29, 2007 IP