Forum Moderators: coopster

Message Too Old, No Replies

Problem with classes and dropdown lists

         

fintan

12:04 pm on May 5, 2005 (gmt 0)

10+ Year Member



Hi I'm fairly new to OOP. The class below works fine. The problem I have is there's a dropdown list in the middle of the loop. The dropdown list gets its data from another table in the database. Which goes through the same class. So I have a loop within a loop.

What I'm trying to do is

if($database_result1 = $database_result2){echo 'SELECTED';}

Here is the class.

class get_sql
{
var $sql;
var $rslt;
# var $_con;

function Sql($sql) {

if($sql!= ""){
$this->rslt = odbtp_query($sql) or die("Could not run $sql query");
$item = array();
while($item = odbtp_fetch_array($this->rslt)){
$this->itms[] = $item;
}
return $this->itms;
odbtp_free_query($this->rslt);
}
}

function CloseCon(){ // Closes the connection to the database
odbtp_close(); # $this->con
return true;
}

}// Class ends

This is how I initiated it.

$bb = new Get_Sql();
$rslts = $bb->Sql($rsBB);
foreach($rslts as $rslt){

HTML form goes here with database results $rslt["Subject"];

Dropdown list with second foreach goes here

}

Any pointers? Thanks

fintan.

Stormfx

3:35 pm on May 5, 2005 (gmt 0)

10+ Year Member



Well, there's really not enough code there for me to figure out what's going on. Can you post a bit more of code and perhaps enlighten me a bit more on your exact goal?

fintan

4:35 pm on May 5, 2005 (gmt 0)

10+ Year Member



Sorry all I want is to be able to do is echo out selected in a dropdown list if an id from one table matches that of the other. Might have over complicated it with the class.

<option value="1">id 1</option>
<option value="2" selected>id 2</option>

So id form the first table equals 2 and id form the second table equals 2 so echo selected. That's it.

fintan

2:54 pm on May 6, 2005 (gmt 0)

10+ Year Member



Got it thanks.