Jump to content

if in a where


phpretard

Recommended Posts

Why doesn't tis work???

 


connect();

$page_title = mysql_query("select * from category where id='".intval($_GET['c'])."' ");
while($title = mysql_fetch_assoc($page_title))
{
if ($title['sub_cat'] == 0){
	echo"<div style=\"color:#A00201; font-style:italic; padding-top:5px;; font-size:22px; font-weight:bold;\">".$title['long_name']."<hr /></div>";
}else{
	$sub_title = mysql_query("select * from category_sub where cat_id='".$title['id']."' ") or die(mysql_error());
	while($stitle = mysql_fetch_assoc($sub_title));
		{
		echo"<div style=\"color:#A00201; font-style:italic; padding-top:5px;; font-size:22px; font-weight:bold;\">".$stitle['sub_name']."TEST<hr /></div>";
		}
	mysql_free_result($sub_title);		
	}
}

mysql_free_result($page_title);

 

Its driving me mad!!!

Link to comment
https://forums.phpfreaks.com/topic/168035-if-in-a-where/
Share on other sites

One loop is $title the other is $stitle

 

I have narrowed it down and this doesn't even work...

 

- I am checking a row in the DB for zero or one.

- if it's 0 it should display a div.

- else it should display the other div.

 

I am sure the tables are setup right because if I change:

 

$title['sub_cat'] == 0 - TO - $title['sub_cat'] == 1

 

It displays the TEST but not the other...

 


$page_title = mysql_query("select * from category where id='".intval($_GET['c'])."' ");
while($title = mysql_fetch_assoc($page_title))
{
if ($title['sub_cat'] == 0){ // ZERO CHECK
echo"<div>".$title['long_name']."</div>";

             }else{echo"<div>TEST</div>";}

}

mysql_free_result($page_title);

Link to comment
https://forums.phpfreaks.com/topic/168035-if-in-a-where/#findComment-886304
Share on other sites

What you could do is echo out the query (or queries) and try it/them from some SQL prog or SQL command line and see if the results are what you expect them to are. It smells like $title['sub_cat'] is not containing the information you think it is. Also you can var_dump variables to see what they hold inside.

Link to comment
https://forums.phpfreaks.com/topic/168035-if-in-a-where/#findComment-886309
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.