Forums
This topic is locked
variable compairson issue
Posted 18 May 2002 17:16:46
1
has voted
18 May 2002 17:16:46 Ken Carter posted:
I have been fighting with a bit of code that I'm working with that is driving me crazy here. Any insight that someone might offer would be welcomned.I have a database table that I am pulling data from to build a page. The fields are pulling up just fine. so I was adding a bit of code that will take one of these fields and explode it into an array so that I can search it to find items for populating radio buttons and displaying images.
This code works (without the database):
<?php
$color="20/40";
#$avilcolors=array()
$avilcolors=explode("/",$color);
$colorsavail=count($availcolors);
Echo "Color Selections:<br>";
if(in_array("20",$avilcolors)) echo "Gray Granite<br>";
if(in_array("30",$avilcolors)) echo "Brownstone<br>";
if(in_array("40",$avilcolors)) echo "Mission White<br>";
?>
this has worked in many test runs where $color contained any number of different values includeing null. It works perfect everytime.
The following however yields no information at all. It doesn't provide an error message either which leads me to believe that the code is executing fine but I have a problem with my variable compairison. I've also included a sniplette of code from above the fragment that displays the field fromt he datatbase just fine.
<td align="default" width="238 px">
// This Works! //
<?php echo $stones->Fields("sdesc"?><br>
Colors:
// This does nothing! //
<?php
$colors=$stones->Fields("color"
$avilcolors=explode("/",$colors);
if(in_array("20",$avilcolors)) echo "Gray Granite<br>";
if(in_array("30",$avilcolors)) echo "Brownstone<br>";
if(in_array("40",$avilcolors)) echo "Mission White<br>";
?>
</td>
If anyone can provide a little insight to where I'm missing it I would really appreciated it.
Thanks in advance!
Ken...
Replies
Replied 20 May 2002 01:03:16
20 May 2002 01:03:16 Tim Green replied:
Ken,
I would suspect that the problem is down to the fact that the data is in the wrong format when it is retrieved from the table.... how is the data stored in the <b>color</b> column?
To ensure that the data you are retrieving is what you expect to be retrieving try putting:-
echo $stones->Fields("color"."<br>";
Just before:-
$colors=$stones->Fields("color"
To ensure that the data the in_array() functions are receiving is in fact the right information.....
Hope this helps..
Tim Green
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
I would suspect that the problem is down to the fact that the data is in the wrong format when it is retrieved from the table.... how is the data stored in the <b>color</b> column?
To ensure that the data you are retrieving is what you expect to be retrieving try putting:-
echo $stones->Fields("color"."<br>";
Just before:-
$colors=$stones->Fields("color"
To ensure that the data the in_array() functions are receiving is in fact the right information.....
Hope this helps..
Tim Green
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 20 May 2002 09:33:08
20 May 2002 09:33:08 Julio Taylor replied:
OH MY GOD!! 666 POSTS!
i hope this helps.
--J
P.S. i killed kenny
i hope this helps.
--J
P.S. i killed kenny
Replied 20 May 2002 13:04:02
20 May 2002 13:04:02 Ken Carter replied:
Interestingly enough I discovered that the detail page did not have this problem so I inserted the code into that page and whala! it worked! Kinda... The inital result was what I was hoping for however on clicking the back button and choosing different or same item from the repeat region page it resulted in the following error:
Fatal error: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition adorecordset_mysql of the object you are trying to operate on was loaded _before_ the session was started in /usr/local/psa/home/vhosts/goodnplentystore.com/httpdocs/gardenstones.php on line 44
So close I can taste it on this one.
I'm pretty sure you're right about the typing issue Tim I'll try your suggestion as a test but that will not work for the production version, I can't display this field because the information means nothing to a viewer only a coded reference to a color.
Thanks!
Ken...
Fatal error: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition adorecordset_mysql of the object you are trying to operate on was loaded _before_ the session was started in /usr/local/psa/home/vhosts/goodnplentystore.com/httpdocs/gardenstones.php on line 44
So close I can taste it on this one.
I'm pretty sure you're right about the typing issue Tim I'll try your suggestion as a test but that will not work for the production version, I can't display this field because the information means nothing to a viewer only a coded reference to a color.
Thanks!
Ken...