gc40 Posted August 21, 2007 Share Posted August 21, 2007 I am trying to access a database table field called "Category" from a database named 1. The output of everything else works great, however, I am trying to get an if statement working on the data that is output. Category has a numeric value of 1-3. if ($row->Category == '1') { echo ("Products"); } else if ($row->Catgeory == '2') { echo ("World"); } else if ($row->Catgeory == '3') { echo ("lol"); } Can someone tell me what I am doing wrong? If Category field value = 1, then output Products, if the category field in the database has a value of 2, then output world, etc etc. Quote Link to comment Share on other sites More sharing options...
pranav_kavi Posted August 21, 2007 Share Posted August 21, 2007 have ur chkd ur column name-'Category' i.e whethr it s 'category' or 'Category'??? i think u can includ the code for db query. Quote Link to comment Share on other sites More sharing options...
gc40 Posted August 21, 2007 Author Share Posted August 21, 2007 It is Category. I am using the output for other database fields. All outputs work fine, its just the Category field. If I type: echo ("</td>"."<td>".$row->Title."</td>"."<td>".$row->Category."</td>"); and the Category for that "id" number is equal to 3, then 3 would be output as plain text. However, I want to do an array of some sort or an if statement. Quote Link to comment Share on other sites More sharing options...
kr3m3r Posted August 21, 2007 Share Posted August 21, 2007 First, you have a few spelling mistakes which may be contributing to your problems. Secondly, are any of the if statements working? Have you tested them? Quote Link to comment Share on other sites More sharing options...
pranav_kavi Posted August 21, 2007 Share Posted August 21, 2007 wat s the databse type for column 'Category'? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted August 21, 2007 Share Posted August 21, 2007 do this just before the if add this echo "<pre>";print_r($row);die; whats displayed Quote Link to comment Share on other sites More sharing options...
gc40 Posted August 21, 2007 Author Share Posted August 21, 2007 stdClass Object ( [id] => 1 [Meta_Description] => meta describtion about cbfi [Meta_Keywords] => Keywords,lol,haha,rolled,pwned, haha [Title] => CBFI Title [subTitle] => Subtitle [Content] => Lorem [Theme_Image] => 0 [Category] => 2 ) Quote Link to comment Share on other sites More sharing options...
MadTechie Posted August 21, 2007 Share Posted August 21, 2007 ok remove that line, and do this var_dump($row->Category); if ($row->Category == 1) { echo "test 1"; } Quote Link to comment Share on other sites More sharing options...
gc40 Posted August 21, 2007 Author Share Posted August 21, 2007 That someone works, however, I am getting this infront of the output: string(1) "2" test 1 Quote Link to comment Share on other sites More sharing options...
gc40 Posted August 21, 2007 Author Share Posted August 21, 2007 I removed the var_dump command and it worked great. Thanks mate. Quote Link to comment Share on other sites More sharing options...
pranav_kavi Posted August 21, 2007 Share Posted August 21, 2007 so twas it..instead of a normal numeric comparision,the string comparision had failed the condition. Quote Link to comment Share on other sites More sharing options...
gc40 Posted August 21, 2007 Author Share Posted August 21, 2007 so twas it..instead of a normal numeric comparision,the string comparision had failed the condition. What are you trying to say? In ENGLISH Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.