php not displaying what I want... ;) (SOLVED!)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DelPazzo
Forum Newbie
Posts: 23
Joined: Thu Dec 30, 2010 3:49 am

php not displaying what I want... ;) (SOLVED!)

Post by DelPazzo »

Hi,

I'm quite new to php as I programmed in asp before.

I now have a problem where I cannot see what is wrong:
am using a mssql db with adodb connection

Code: Select all

$recordSet = &$conn->Execute('SELECT max(uebkunden.id) as id, translat.rechid, uebkunden.name FROM translat INNER JOIN uebkunden ON translat.kunde = uebkunden.id WHERE (translat.rechid <> 0) AND (translat.rechn = 1) AND (translat.druck = 0) group by uebkunden.id, uebkunden.name, translat.rechid order by rechid');
if (!empty($recordSet)) {
         if (!$recordSet) {
                  Echo ' <tr><td>No invoice to print</td></tr>';
         } else {
         echo '<tr><td><form name="marken" method="post"> ';
         Echo ' <select size="1" name="kunde" onChange="document.marken.submit();">';
         Echo ' <option value="">---Auswahl---</option> ';
         while (!$recordSet->EOF) {
                //maid = rs("id")
                //mbez = rs("name")
                //rechidi = rs("rechid")
                Echo ' <option value="'.$recordSet->fields['id'].'" ';
                Echo ' >'.$recordSet->fields['name'].' '.$recordSet->fields['rechid'].'</option> ';
                $recordSet->MoveNext();
         }
         }
         echo ' </select></td></tr>';
} else {
         Echo ' <tr><td>No invoice to print</td></tr>';
}  
($recordSet is the sql query.)

what should it do: if recordSet is empty then display the invoice-phrase, else a dropdown menue. The problem is that I always get a dropdown menue either empty or filled.

so I guess that recordSet is always recognized as not empty. How can I check if it's empty or not? (and please do not, like php users in German forums, refer to manual or google.)
Last edited by DelPazzo on Sat Jan 01, 2011 9:10 am, edited 5 times in total.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: php not displaying what I want... ;)

Post by Darhazer »

Run var_dump($recordSet) and see what it contains. Maybe this is a resource identificator and not the entire recordset ;)
DelPazzo
Forum Newbie
Posts: 23
Joined: Thu Dec 30, 2010 3:49 am

Re: php not displaying what I want... ;)

Post by DelPazzo »

vardump gives this:

object(variant)#2 (0) { }
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: php not displaying what I want... ;)

Post by Darhazer »

DelPazzo wrote:vardump gives this:

object(variant)#2 (0) { }
well, here is the problem - it's an object. Add a method to the object to return if it's empty or not.
DelPazzo
Forum Newbie
Posts: 23
Joined: Thu Dec 30, 2010 3:49 am

Re: php not displaying what I want... ;)

Post by DelPazzo »

thanks for the hint to the object... I've been trying to find a way to add a method, but to no avail... I'm getting frustrated... :(
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: php not displaying what I want... ;)

Post by Darhazer »

oh, sorry, just noticed that $recordset is adodb object :(

Use the RecordCount() method :)
Replace

Code: Select all

if (!empty($recordSet)) {
with

Code: Select all

if ($recordSet->RecordCount() ) {
DelPazzo
Forum Newbie
Posts: 23
Joined: Thu Dec 30, 2010 3:49 am

Re: php not displaying what I want... ;)

Post by DelPazzo »

same result... :(

i also tried echo count($recordSet);
and always get 1. even if there should be no result for the sql query...

edit: i added the sql row in the 1st post to the php script. maybe that would help find the problem, although I don't think so.
DelPazzo
Forum Newbie
Posts: 23
Joined: Thu Dec 30, 2010 3:49 am

Re: php not displaying what I want... ;)

Post by DelPazzo »

ok was just trying every possible change for the line that gets the error and now get a new error:

Uncaught exception 'com_exception' with message '<b>Source:</b> ADODB.Field<br/><b>Description:</b> either BOF or EOF is True, or ...

with this code.

Code: Select all

$a = $recordSet->fields['name'];
if (trim($a->value) !="") {
echo 'hallo';
}
unfortunately google throws no real help when searching for "either bof or eof..." is there a way to get around this error or capture it before it happens or if it happens, instead of throwing the error, have it echo "hallo"
DelPazzo
Forum Newbie
Posts: 23
Joined: Thu Dec 30, 2010 3:49 am

Re: php not displaying what I want... ;) (SOLVED!)

Post by DelPazzo »

thx to coding help in another thread I posted I now could solve this issue.

here is the result:

Code: Select all

try {
         $recordSet = &$conn->Execute('SELECT max(uebkunden.id) as id, translat.rechid, uebkunden.name FROM translat INNER JOIN uebkunden ON translat.kunde = uebkunden.id WHERE (translat.rechid <> 0) AND (translat.rechn = 1) AND (translat.druck = 0) group by uebkunden.id, uebkunden.name, translat.rechid order by rechid');
         $a = $recordSet->fields['name'];
         if (trim($a->value) !="") {
                  echo '<tr><td><form name="marken" method="post"> ';
                  Echo ' <select size="1" name="kunde" onChange="document.marken.submit();">';
                  Echo ' <option value="">---Auswahl---</option> ';
                  while (!$recordSet->EOF) {
                         Echo ' <option value="'.$recordSet->fields['id'].'" ';
                         Echo ' >'.$recordSet->fields['name'].' '.$recordSet->fields['rechid'].'</option> ';
                         $recordSet->MoveNext();
                  }
         echo ' </select></td></tr>';
         }
}
catch (Exception $e) {
echo ' <tr><td>Keine Rechnung vorgemerkt</td></tr>';
}
Post Reply