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. Link to comment https://forums.phpfreaks.com/topic/65934-solved-problem-with-if-statement/ 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. Link to comment https://forums.phpfreaks.com/topic/65934-solved-problem-with-if-statement/#findComment-329602 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. Link to comment https://forums.phpfreaks.com/topic/65934-solved-problem-with-if-statement/#findComment-329607 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? Link to comment https://forums.phpfreaks.com/topic/65934-solved-problem-with-if-statement/#findComment-329609 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'? Link to comment https://forums.phpfreaks.com/topic/65934-solved-problem-with-if-statement/#findComment-329610 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 Link to comment https://forums.phpfreaks.com/topic/65934-solved-problem-with-if-statement/#findComment-329611 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 ) Link to comment https://forums.phpfreaks.com/topic/65934-solved-problem-with-if-statement/#findComment-329613 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"; } Link to comment https://forums.phpfreaks.com/topic/65934-solved-problem-with-if-statement/#findComment-329617 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 Link to comment https://forums.phpfreaks.com/topic/65934-solved-problem-with-if-statement/#findComment-329621 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. Link to comment https://forums.phpfreaks.com/topic/65934-solved-problem-with-if-statement/#findComment-329622 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. Link to comment https://forums.phpfreaks.com/topic/65934-solved-problem-with-if-statement/#findComment-329624 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 Link to comment https://forums.phpfreaks.com/topic/65934-solved-problem-with-if-statement/#findComment-329626 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.