object - proceeding to next id from model php -


hi i'll post code in question first ask question(s).

function printuseractiveads($curruser){         $activeuser = new users();         $useractiveads = new userads();          echo         '             <h4>currently active ads:</h4>             <table class="useractiveads">                 <tr><td>title</td><td></td><td>price</td><td></td><td>description</td><td></td><td>delete</td></tr>         ';          $numads = $useractiveads->getnumberofadsbyuserid($curruser);         if($numads > 0){             for($i = 0; $i < $numads; $i++){                 $id = $useractiveads->getadidbyuserid($curruser);                 echo                 '                     <tr>                         <td>'.$useractiveads->getadtitlebyid($id).'</td><td></td>                         <td>'.$useractiveads->getadpricebyid($id).'</td><td></td>                         <td>'.truncatedescription($useractiveads->getaddescriptionbyid($id),100).'</td><td></td>                         <td>                             <form action="" method="post">                                 <input type="submit" name="delete" id="delete" class="button" value="delete" />                             </form>                         </td>                     </tr>                 ';                     }         }else{             echo             '                 <tr><td colspan="7"><span class="prompt">currently no active ads</span></td></tr>             ';         } 

model (userads)

//ad model     class userads {         private $id;         private $title;         private $price;         private $location;         private $category;         private $subcategory;         private $description;          //default constructor         function _constructor(){             $this->id = null;             $this->title = null;             $this->price = null;             $this->location = null;             $this->category = null;             $this->subcategory = null;             $this->description = null;         }          //set ad details         function setaddetails($adid,$adtitle, $adprice, $adlocation, $adcategory, $adsubcategory, $addescription){             $this->id = $adid;             $this->title = $adtitle;             $this->price = $adprice;             $this->location = $adlocation;             $this->category = $adcategory;             $this->subcategory = $adsubcategory;             $this->description = $addescription;         }          //get number of ads user using user id         function getnumberofadsbyuserid($userid){             $numberofads = mysql_query("select * ads user_id='$userid'") or die(mysql_error());             return $numads = mysql_num_rows($numberofads);         }          //get ad id user id         function getadidbyuserid($userid){             $queryadid = mysql_query("select id ads user_id='$userid'") or die(mysql_error());             $data = mysql_fetch_assoc($queryadid);             return $this->id = $data['id'];         } 

ok specific piece of code in quesiont getadidbyuserid. doesn't iterate on ids associated specific user. bassically wanted take ads asssociated particular user , display in table. when run code above correct number of ads associated user table displays first id associated user. think maybe should increment id issue there user has ads id 1,2,3,7, , 17. ideas of how go this? can see printactiveads function created 2 objects, other question have have delete them @ end of function or shouldn't worry them because removed once function done (local scope).

thanks in advance.

so figured out issue. missing set statements , basic statements. did mysql_fetch_array($query) after did query, , set each row equal userad property , when did echo called set


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -