zero-perfoliate
zero-perfoliate

Author Topic: Changing color of text generated in tables from ms sql...  (Read 855 times)

Offline Miss_Rebelx

  • PHP Helpers
  • ***
  • Posts: 33
  • Karma: +0/-0
  • Must... Not... VB.NET.
Re: Changing color of text generated in tables from ms sql...
« Reply #15 on: September 21, 2010, 09:08:11 AM »
Yeah, I find that that timer starts the moment you click "reply". And if you get the error and click back and try to wait the 200 seconds before posting again, it will tell you "you already posted this reply"... so you have to go back to the thread itself, click reply, WAIT 200 and then post. (So I've troubleshooted myself anyways)

Quote
Maybe it causes an issue because if there is no pending lease status the viewPendingLease shows nothing for that unit, it doesn't even show the unit at all... so when you call it, the ones that have no pending lease do not show up.

I did not think of this before, sorry! Is there a way to display the units even though viewPendingLease does not show them if no pending lease is present?

I am a bit tired I admit, so I didn't quite catch what you're saying. Do you mean that in the database, in your table viewPendingLease, there are no entries that aren't "Pending" in the StatusName field?
Not quite sure what you mean.

Either way, run the SQL query from your code in PHPMyAdmin to see what results you're getting if you think it's the PHP that's the problem. Otherwise, your SQL query isn't doing what you want.
Learning, and helping learn.
By the way, you missed a ;.

Offline Soulreaver418

  • PHP Workers
  • **
  • Posts: 12
  • Karma: +0/-0
Re: Changing color of text generated in tables from ms sql...
« Reply #16 on: September 21, 2010, 09:20:03 AM »
Basically, everything is working fine except that the untis which do not have a current pending lease status do not show up at all now.

I am wondering if that is because the table viewPendingLease only shows units that have a pending lease, the ones that do not are not displayed in that table.

The unit table shows all units that we have in our database, which we need, the viewPendingLease table only shows the units that have a future pending lease.

So now It works as I want except that the units with no future pending lease aren't displayed at all now so we don't see a full listing of all of our units.

I really do appreciate all you have done with this code, you are a lifesaver!

Offline Miss_Rebelx

  • PHP Helpers
  • ***
  • Posts: 33
  • Karma: +0/-0
  • Must... Not... VB.NET.
Re: Changing color of text generated in tables from ms sql...
« Reply #17 on: September 21, 2010, 09:58:18 AM »
So just to clarify, I'm getting confused over two statements:

Quote
Yes, viewPendingLease is the table and the column that holds the data I am after is called StatusName, all it does is show the word Pending or nothing at all if that property has no pending future lease.

Quote
The unit table shows all units that we have in our database, which we need, the viewPendingLease table only shows the units that have a future pending lease.


So, does the viewPendingLease table have rows at all for those properties that do not have a futur pending lease? or does it have a row, but that particular field (StatusName) is blank? (or even, all fields are blank except for Unit_ID?)?

This makes a difference in how to approach the problem.

Learning, and helping learn.
By the way, you missed a ;.

Offline Soulreaver418

  • PHP Workers
  • **
  • Posts: 12
  • Karma: +0/-0
Re: Changing color of text generated in tables from ms sql...
« Reply #18 on: September 21, 2010, 10:07:32 AM »
If there is no pending lease it does not display any information about the unit at all. Just the units that have a pending lease show up in that table.

Sorry to be such a pain in the you know what, should have clarified this from the beginning.  :-[

Offline Miss_Rebelx

  • PHP Helpers
  • ***
  • Posts: 33
  • Karma: +0/-0
  • Must... Not... VB.NET.
Re: Changing color of text generated in tables from ms sql...
« Reply #19 on: September 21, 2010, 11:22:42 AM »
I did some playing around on my (test) server to figure out what I think is going on, try this:

Code: [Select]
<?php 

//connect to a DSN "" 
$conn odbc_connect('','',''); 

if (
$conn

//the SQL statement that will query the database 
$query "Select unit.Unit_ID, unit.PropertyUnitID, unit.Street, unit.Status, viewPendingLease.StatusName as \"Future Booked\" from unit LEFT JOIN viewPendingLease ON unit.Unit_ID = viewPendingLease.Unit_ID";

//perform the query 
$result=odbc_exec($conn$query); 
echo 
"<table border=\"2\"><tr>"

//print field name 
$colName odbc_num_fields($result); 
for (
$j=1$j<= $colName$j++) 

echo 
"<th>"
echo 
odbc_field_name ($result$j ); 
echo 
"</th>"


//fetch tha data from the database 
while(odbc_fetch_row($result)) 

echo 
"<tr>"
for(
$i=1;$i<=odbc_num_fields($result);$i++) 

$resultfield odbc_result($result,$i); 
echo 
"<td class='$resultfield'>";
if (
$i == 5)
{
 if (
$resultfield == 'Pending')
 {
echo 
"Yes";
 }
 else
 {
echo 
"No";
 }
}
else
{
 else
 {
     echo 
"No";
 }
}
else
{
 echo 
$resultfield;
}
echo 
"</td>";

echo 
"</tr>"
}
echo 
"</table >"

//close the connection 
odbc_close ($conn); 

else{
 echo 
"odbc not connected"
}
?>

Learning, and helping learn.
By the way, you missed a ;.

Offline Soulreaver418

  • PHP Workers
  • **
  • Posts: 12
  • Karma: +0/-0
Re: Changing color of text generated in tables from ms sql...
« Reply #20 on: September 21, 2010, 11:33:02 AM »
Parse error: syntax error, unexpected T_ELSE in sqlscript.php on line 91

is what I am getting.

Offline Miss_Rebelx

  • PHP Helpers
  • ***
  • Posts: 33
  • Karma: +0/-0
  • Must... Not... VB.NET.
Re: Changing color of text generated in tables from ms sql...
« Reply #21 on: September 21, 2010, 11:35:34 AM »
Arg, ignore previous reply: there's no edit button that I can see try this one:

(All I changed was the SQL statement, from INNER JOIN to LEFT JOIN)

Code: [Select]
<?php 

//connect to a DSN "" 
$conn odbc_connect('','',''); 

if (
$conn

//the SQL statement that will query the database 
$query "Select unit.Unit_ID, unit.PropertyUnitID, unit.Street, unit.Status, viewPendingLease.StatusName as \"Future Booked\" from unit LEFT JOIN viewPendingLease ON unit.Unit_ID = viewPendingLease.Unit_ID";

//perform the query 
$result=odbc_exec($conn$query); 
echo 
"<table border=\"2\"><tr>"

//print field name 
$colName odbc_num_fields($result); 
for (
$j=1$j<= $colName$j++) 

echo 
"<th>"
echo 
odbc_field_name ($result$j ); 
echo 
"</th>"


//fetch tha data from the database 
while(odbc_fetch_row($result)) 

echo 
"<tr>"
for(
$i=1;$i<=odbc_num_fields($result);$i++) 

$resultfield odbc_result($result,$i); 
echo 
"<td class='$resultfield'>";
if (
$i == 5)
{
 if (
$resultfield == 'Pending')
 {
echo 
"Yes";
 }
 else
 {
echo 
"No";
 }
}
else
{
 echo 
$resultfield;
}
echo 
"</td>";

echo 
"</tr>"
}
echo 
"</table >"

//close the connection 
odbc_close ($conn); 

else{
 echo 
"odbc not connected"
}
?>

Learning, and helping learn.
By the way, you missed a ;.

Offline Soulreaver418

  • PHP Workers
  • **
  • Posts: 12
  • Karma: +0/-0
Re: Changing color of text generated in tables from ms sql...
« Reply #22 on: September 21, 2010, 11:42:26 AM »
...  ;D  ;D

if I could come through this monitor and give you a hug I would!!!

Truly amazing, you have been such a big help I am at a loss for words. Thank you so much, everything displays perfectly now.

I only hope to fully understand code enough to one day accomplish tasks such as this by myself.

I owe you one, that's for sure!

 

zero-perfoliate