Jump to content

unrelated methods affecting each other?

- - - - -

  • Please log in to reply
No replies to this topic

#1
zeroradius

zeroradius

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,406 posts
So i have a class used for handaling all my database needs. I have sevral method "sets" each set consisting of a geter and a setter method but none of the sets call each other. The class was working fine until i edited a method called getById. I added a while loop to it and it broke ..... a totaly unrelated method. Even if i don't call the getByid method it breaks....... but only on the page i had planed on using the getById method, it works fine on any other view.

Here is the error i get when i have the while loop inside the getById method:

Quote

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

here is the method "set" that is breaking

/*
getCell:
******************************************************************************
| Purpose: Selects a single cell from a table based on the id
|
| Notes: 
******************************************************************************
*/
 private function setGetCell($table, $cell, $id)
 {
  $query = "Select " . $cell . " from " . $table . " Where id=" . $id;
 
  $run = mysql_query($query)or die($this->error);
 
  $var = mysql_result($run,0);
 
  return $var;
 }
 public function getCell($table, $cell, $id)
 {
  $var = $this->setGetCell($table, $cell, $id);
 
  return $var;
 }
/*
******************************************************************************
*/
 


Here is the getById "set" as it origanly was which dosent break anything
/*
getById:
******************************************************************************
| Purpose: Selects a single row from a table based on the id
|
| Notes: 
|   - possible paramaters are Desc and Asc
******************************************************************************
*/
 private function setGetById($table, $id)
 {
  $query = "Select * from " . $table . " Where id=" . $id;
  $run = mysql_query($query)or die($this->error);
 
  $var = mysql_fetch_array($run);
 
  return $var;
 }
 public function getById($table, $id)
 {
  $var = $this->setGetById($table,$id);
 
  return $var;
 }
/*
******************************************************************************
*/



and here is the method how i want it to be but is breaking the other method
/*
getById:
******************************************************************************
| Purpose: Selects a single row from a table based on the id
|
| Notes: 
|   - possible paramaters are Desc and Asc
******************************************************************************
*/
 private function setGetById($table, $id)
 {
  $query = "Select * from " . $table . " Where id=" . $id;
  $run = mysql_query($query)or die($this->error);
 
  //$var = mysql_fetch_array($run);
 
    $i=0;
  while($getter = mysql_fetch_array($run))
  {
   $var[$i] = $getter;
   $i = $i+1;
  }
 
  return $var;
 }
 public function getById($table, $id)
 {
  $var = $this->setGetById($table,$id);
 
  return $var;
 }
/*
******************************************************************************
*/


Heres the view:
 <div id="body" class="main"><!-- Main content is contained in this area -->
        <!-- InstanceBeginEditable name="body" -->
        <h1>
         <u>
              <?php echo $news[3]; ?>
            </u>
        </h1>
        <h4>
   By:  <?php echo $db->getCell("users", "u_name", $news[5]); ?> <br />
            Published:  <?php echo $time->getDate($news[4]); ?>
            At:  <?php echo $time->getTime($news[4]); ?><br />
        </h4> 
 
        <img src="http://forum.codecall.net/images/<?php echo $news[1]; ?>" border="0"align="left" />
 
        <?php echo $news[2]; ?> 
 
 
        <!-- InstanceEndEditable -->
  </div>
    <!-- InstanceBeginEditable name="optionalContent" -->
    <!-- any extra divs should go in this area -->
 <div id="guestbook" class="main">
 <?php
 
  // Retrieve all coments for the specified news article.
  foreach($db->getBySpecId("news_comments", $_REQUEST[n_id], "article_id", "Desc") as $comment)
 {
  /*$i=0;
  foreach($db->getById("users_assets", $comment[1]) as $user)
  {
   echo $user[0];
  }*/
?>
        <table class="responce">
            <tr>
                <td colspan="2">
                <br /><b> Re:<?php echo $news[3]; // Title of news article ?></b>
                </td>
            </tr>
            <tr>
                <td rowspan="3" class="responceUserBar">
                    <center>
                        <br />
                        <b><?php echo $db->getCell("users", "u_name", $comment[1]);  //Name of person leaving a coment ?></b>
                        <br />
                        <img src="http://i196.photobucket.com/albums/aa63/Kelvoron/isikAv.jpg" border="0" />
                        <br /><br />
                        thumbs
                        <br />
                    </center>
                </td>
                <td class="responceBody">
                    <?php echo $comment[4]; // users comment ?>
                </td>
            </tr>
            <tr>
                <td class="responceEditBar">
                    Edit | Delete
                </td>
            </tr>
            <tr>
                <td class="responceBody">
                    <center>
                    <img src="http://i196.photobucket.com/albums/aa63/Kelvoron/azraelSig.jpg" border="0" />
                    </center>
                </td>
            </tr>
        </table> 
<?php
 }
?>
 </div> 


And finaly the portion of the controller that takes care of this part of the site
  function newsArticle()
  {
   include_once("models/dbHandeler.class.php");
   include_once("models/timeManip.class.php");
   include_once("models/stringManip.class.php");
 
   $time = new TimeManip("gmt");
 
   $db = new DbHandeler("A Problem has occured, If this problem persist please notify an Admin");
 
   $string = new StringManip();
 
   $db->dbConnect();
 
   $news = $db->getById("news", $_REQUEST[n_id]);
 
 
   include("views/news_articleView.php");
  }

I'm not sure what i'm doing wrong, help would be apreciated.


EDIT: Never mind. Now that everything is layed out on one page i see where the two methods are related. Now I have to figure out why the while loop won't work but i can do that myself. Thanks anyway!
Posted Image




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users