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
Share on other sites

Not sure but maybe it is that you are using the same variable in both while loops ($title)? Like gevans mentioned we need more information... how does it not work, what should happen and what happens..  crystal ball is under maintenance atm.

Link to comment
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.