?
Solved

Condition statement to change wording in div block

Posted on 2009-12-30
60
Medium Priority
?
294 Views
Last Modified: 2012-05-08
I have a query that works great and took a while to work with.  Now I need to place a coditional either inside the div block or around it to have the wording "answered the Question" change to what I want depending on what tables is being pulled at that time.  I hope that makes since. I will be adding two or three more tables from the database once I have this working.

Let me know if you need anymore explanation.
<?php
                		$user = $_SESSION['username'];
                		$grabContribs = "SELECT answers.user, answers.answer, answers.qID, user_question.question, answers.date, user_question.id AS uID, user_question.make, user_question.model
							FROM answers
							LEFT JOIN user_question ON answers.qID = user_question.id
							WHERE answers.user = '$user'
							UNION
							SELECT how_to.user, how_to.howto, how_to.id AS hID, how_to.question, how_to.date, NULL, how_to.make, how_to.model
							FROM how_to
							WHERE how_to.user = '$user'
							ORDER BY date DESC";
                        $contribsGrabbed = mysql_query($grabContribs) or die("Grab did not work because: " . mysql_error());
                        	while($c = mysql_fetch_array($contribsGrabbed)) {
                    ?>
                    <div class="repository">
                    	<span style="color: #076bdc"><?= $c['user'] ?></span> <?= ($c['qID'] ? "answered the Question" : "posted the How To") ?> "<span class="question-link"><a href="/view-question.php?qID=<?= $c['uID'] ?>"><?= $c['question'] ?></a></span>"<br/>[<span class="question-control"><a href="/category-questions.php?make=<?= $c['make'] ?>model=<?= $c['model'] ?>"><?= $c['make'] ?> <?= $c['model'] ?></a></span>] [<span class="question-control"><a href="/recategorize.php?qID=<?= $c['id'] ?>">Recategorize</a></span>] <?= (!empty($c['answer'])) ? ("[<span class='question-control'><a href='/edit-question.php?qID={$q['id']}'>Edit</a></span>]") : ("") ?><?= (!empty($c['updated'])) ? ("<div class='posting-left'>Answered: " . date('F, j Y', strtotime($c['updated'])) . " " . date('g:i a', strtotime($c['updated'])) . "</div>") : ("") ?><div class="spacer"></div>
                    </div>
                    <?php
                    		}
                    ?>

Open in new window

0
Comment
Question by:pingeyeg
  • 31
  • 27
  • 2
60 Comments
 
LVL 14

Expert Comment

by:shru_0409
ID: 26145615
can u make very simple?? i m not clear of your requiremnt..
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26145689
I need to place a conditional statement like an if...else statement either inside the div surrounding the wording I want to change based on the condition I spoke of above, but not sure what the condition should be based on.  I want the wording to change based on which table in the database is being pulled at that moment.
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26145729
Hello pingeyeg,

Do a try without the test to see the value and you will be able to build better your conditional statement.



replace :
<?= ($c['qID'] ? "answered the Question" : "posted the How To") ?> 
by :
<? $c['qID'] ?>

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 14

Expert Comment

by:shru_0409
ID: 26145780
create a temp flag and change value as per condition than identification will make simple.

like case flag='Y' then <your condition> when flag='N' then <condition> else <nothing> end;
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26145800
leakim971: Yes that outputs the question id from the answers table.

shru_0409: I'm not sure I fully understand what you mean by temp flags.  What are those?
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26145837
So what do you want to do with this id ? Your test could be improved if need but it's structure is good :

<? (test result):"answered the Question":"posted the How To" ?>

You just need to define "test result" as you want based on $c['qID'] if I understand
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26145877
Well, that's my issue.  I'm not sure what to base the test result on in order to get this going.  I was throwing that aID just to see if that would work.  What are your thoughts as to the best way?
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26145907
>What are your thoughts as to the best way?
You're the only person to know if you don't post any data or screenshot :))

Why do you want to display "answered the Question"
and another time "posted the How To" ?
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26145934
Here is a screenshot of what is going on.  Hope that helps.  You will notice all have the wording "answered the Question", but not all are answers.  Two are How To's.
Screen-shot-2009-12-30-at-10.18..png
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26145977
OK. I think you may be improve your query to count/return number of answer.
So if the count return 0 you know what to do

Use

Something like :


SELECT questions.*, COUNT(answers.id) 'nb_answers' FROM questions LEFT JOIN answers ON questions.id = answers.id_question

Open in new window

0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26146009
What does nb_answers mean?
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26146073
nb_answers is the name for COUNT(answers.id) to get it (number of answers) in your PHP code
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26146099
So nb_answers is the alias for COUNT(answers.id)?
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26146183
Yes Sir
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26146214
I changed my query up to reflect what you put in, but the second COUNT method doesn't seem to be counting:
SELECT answers.user, answers.answer, answers.qID, user_question.question, answers.date, user_question.id AS uID, user_question.make, user_question.model, COUNT(qID) 'nb_answers'
							FROM answers
							LEFT JOIN user_question ON answers.qID = user_question.id
							WHERE answers.user = '$user'
							UNION
							SELECT how_to.user, how_to.howto, how_to.id AS hID, how_to.question, how_to.date, NULL, how_to.make, how_to.model, COUNT(id) 'nb_howtos'
							FROM how_to
							WHERE how_to.user = '$user'
							ORDER BY date DESC

Open in new window

0
 
LVL 83

Expert Comment

by:leakim971
ID: 26146254
Forget something in my example query : GROUP BY

SELECT questions.*, COUNT(answers.id) 'nb_answers' FROM questions LEFT JOIN answers ON questions.id = answers.id_question GROUP BY questions.*

So Try :


SELECT answers.user, answers.answer, answers.qID, user_question.question, answers.date, user_question.id AS uID, user_question.make, user_question.model, COUNT(qID) 'nb_answers'
                                                        FROM answers
                                                        LEFT JOIN user_question ON answers.qID = user_question.id
                                                        WHERE answers.user = '$user'
                                                        GROUP BY answers.user, answers.answer, answers.qID, user_question.question, answers.date, user_question.id AS uID, user_question.make, user_question.model
                                                        UNION
                                                        SELECT how_to.user, how_to.howto, how_to.id AS hID, how_to.question, how_to.date, NULL, how_to.make, how_to.model, COUNT(id) 'nb_howtos'
                                                        FROM how_to
                                                        WHERE how_to.user = '$user'
                                                        GROUP BY how_to.user, how_to.howto, how_to.id AS hID, how_to.question, how_to.date, NULL, how_to.make, how_to.model
                                                        ORDER BY date DESC

Open in new window

0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26146288
That gives me the error:

Grab did not work because: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS uID, user_question.make, user_question.model UNION SELECT how_t' at line 5
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26146335
Check your query, this is not the current one :

Error say :
AS uID, user_question.make, user_question.model UNION SELECT how_t

We have
AS uID, user_question.make, user_question.model <-------- ? ---------> UNION SELECT how_t

0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26146372
This is what you have in your original query.  I don't see anything between user_question.model and UNION SELECT
WHERE answers.user = '$user'
GROUP BY answers.user, answers.answer, answers.qID, user_question.question, answers.date, user_question.id AS uID, user_question.make, user_question.model
UNION

Open in new window

0
 
LVL 83

Expert Comment

by:leakim971
ID: 26146442
AS uID, user_question.make, user_question.model UNION SELECT how_t
VS
AS uID, user_question.make, user_question.model, COUNT(qID) 'nb_answers'
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26146636
That didn't make any difference.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26146878
Apparently you cannot place "AS" statements in a GROUP BY statement.  When I remove that, things showed up.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26146945
Am I not able to COUNT multiple SELECT statements?  When I place a COUNT at the end of the second SELECT statement it's ignored.
SELECT answers.user, answers.answer, answers.qID, user_question.question, answers.date, user_question.id AS uID, user_question.make, user_question.model, COUNT(answers.qID) 'nb_answers'
							FROM answers
							LEFT JOIN user_question ON answers.qID = user_question.id
							WHERE answers.user = '$user'
							GROUP BY answers.user, answers.answer, answers.qID, user_question.question, answers.date, user_question.id, user_question.make, user_question.model
							UNION
							SELECT how_to.user, how_to.howto, how_to.id AS hID, how_to.question, how_to.date, NULL, how_to.make, how_to.model, COUNT(how_to.id) 'nb_howtos'
							FROM how_to
							WHERE how_to.user = '$user'
							GROUP BY how_to.user, how_to.howto, how_to.id, how_to.question, how_to.date, NULL, how_to.make, how_to.model
							ORDER BY date DESC

Open in new window

0
 
LVL 83

Expert Comment

by:leakim971
ID: 26147139
You can remove AS between table field and its alias.
Try each query alone
As you know you must have same number of column (good to have same column name too but column from first query is generaly used)
Try both without the "ORDER BY date DESC" too.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26147167
When I remove the UNION and leave one SELECT or the other, my conditional works just fine and the correct information is displayed correctly, but the conditional will not change if the UNION is there.
<?php
                		$user = $_SESSION['username'];
                		$grabContribs = "SELECT answers.user, answers.answer, answers.qID, user_question.question, answers.date, user_question.id AS uID, user_question.make, user_question.model, COUNT(answers.qID) 'nb_answers'
							FROM answers
							LEFT JOIN user_question ON answers.qID = user_question.id
							WHERE answers.user = '$user'
							GROUP BY answers.user, answers.answer, answers.qID, user_question.question, answers.date, user_question.id, user_question.make, user_question.model
							UNION
							SELECT how_to.user, how_to.howto, how_to.id AS hID, how_to.question, how_to.date, NULL, how_to.make, how_to.model, COUNT(how_to.id) 'nb_howtos'
							FROM how_to
							WHERE how_to.user = '$user'
							GROUP BY how_to.user, how_to.howto, how_to.id, how_to.question, how_to.date, NULL, how_to.make, how_to.model
							ORDER BY date DESC";
                        $contribsGrabbed = mysql_query($grabContribs) or die("Grab did not work because: " . mysql_error());
                        	while($c = mysql_fetch_array($contribsGrabbed)) {
                        		echo $c['nb_answers'];
                    ?>
                    <div class="repository">
                    	<span style="color: #076bdc"><?= $c['user'] ?></span> 
                    	<?php 
                    		if($c['nb_answers'] > 0) {
                    			echo "answered the Question";
                    		} elseif($c['nb_howtos'] > 0) {
                    			echo "posted the How To";
                    		}
                    	?> "<span class="question-link"><a href="/view-question.php?qID=<?= $c['uID'] ?>"><?= $c['question'] ?></a></span>"<br/>[<span class="question-control"><a href="/category-questions.php?make=<?= $c['make'] ?>model=<?= $c['model'] ?>"><?= $c['make'] ?> <?= $c['model'] ?></a></span>] [<span class="question-control"><a href="/recategorize.php?qID=<?= $c['id'] ?>">Recategorize</a></span>] <?= (!empty($c['answer'])) ? ("[<span class='question-control'><a href='/edit-question.php?qID={$q['id']}'>Edit</a></span>]") : ("") ?><?= (!empty($c['updated'])) ? ("<div class='posting-left'>Answered: " . date('F, j Y', strtotime($c['updated'])) . " " . date('g:i a', strtotime($c['updated'])) . "</div>") : ("") ?><div class="spacer"></div>
                    </div>
                    <?php
                    		}
                    ?>

Open in new window

0
 
LVL 83

Expert Comment

by:leakim971
ID: 26147206
group by NULL...

SELECT a.user, a.answer, a.qID, uq.question, a.date, uq.id, uq.make, uq.model, COUNT(a.qID) 'nb' FROM answers a LEFT JOIN user_question uq ON a.qID = uq.id
WHERE a.user = '$user'
GROUP BY a.user, a.answer, a.qID, uq.question, a.date, uq.id, uq.make, uq.model
UNION
SELECT ht.user, ht.howto, ht.id AS hID, ht.question, ht.date, NULL 'id', ht.make, ht.model, COUNT(ht.id) 'nb' FROM how_to ht WHERE ht.user = '$user'
GROUP BY ht.user, ht.howto, ht.id, ht.question, ht.date, id, ht.make, ht.model
ORDER BY date DESC

Open in new window

0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26147344
I think you just lost me.  What do you mean by group by NULL...  ?
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26147664
Look you post ID:26146945
Line 10 : GROUP BY how_to.user, how_to.howto, how_to.id, how_to.question, how_to.date, NULL, how_to.make, how_to.model

how_to.date,
NULL,  <------------------------ Not good !
how_to.make
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26147674
I was told to use NULL and that's what made my query finally work.
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26147688
I understood that. See my correction on post ID:26147206
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26147711
When I place what you wrote: NULL 'id' I get the error message:

Grab did not work because: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''id', how_to.make, how_to.model ORDER BY date DESC' at line 10

When I remove the 'id' the error goes away.
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26147739
Good. Both with UNION should run fine now.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26147749
What???  I'm still in the same position I was in.  The conditional statement below the query does not work.  I need it to work.
<?php
                		$user = $_SESSION['username'];
                		$grabContribs = "SELECT answers.user, answers.answer, answers.qID, user_question.question, answers.date, user_question.id uID, user_question.make, user_question.model, COUNT(answers.qID) 'nb_answers'
							FROM answers
							LEFT JOIN user_question ON answers.qID = user_question.id
							WHERE answers.user = '$user'
							GROUP BY answers.user, answers.answer, answers.qID, user_question.question, answers.date, user_question.id, user_question.make, user_question.model
							UNION
							SELECT how_to.user, how_to.howto, how_to.id hID, how_to.question, how_to.date, NULL, how_to.make, how_to.model, COUNT(how_to.id) 'nb_howto'
							FROM how_to
							WHERE how_to.user = '$user'
							GROUP BY how_to.user, how_to.howto, how_to.id, how_to.question, how_to.date, NULL, how_to.make, how_to.model
							ORDER BY date DESC";
                        $contribsGrabbed = mysql_query($grabContribs) or die("Grab did not work because: " . mysql_error());
                        	while($c = mysql_fetch_array($contribsGrabbed)) {
                    ?>
                    <div class="repository">
                    	<span style="color: #076bdc"><?= $c['user'] ?></span> 
                    	<?php 
                    		if($c['nb_answers'] > 0) {
                    			echo "answered the Question";
                    		} elseif($c['nb_howto'] > 0) {
                    			echo "posted the How To";
                    		}
                    	?> "<span class="question-link"><a href="/view-question.php?qID=<?= $c['uID'] ?>"><?= $c['question'] ?></a></span>"<br/>[<span class="question-control"><a href="/category-questions.php?make=<?= $c['make'] ?>model=<?= $c['model'] ?>"><?= $c['make'] ?> <?= $c['model'] ?></a></span>] [<span class="question-control"><a href="/recategorize.php?qID=<?= $c['id'] ?>">Recategorize</a></span>] <?= (!empty($c['answer'])) ? ("[<span class='question-control'><a href='/edit-question.php?qID={$q['id']}'>Edit</a></span>]") : ("") ?><?= (!empty($c['updated'])) ? ("<div class='posting-left'>Answered: " . date('F, j Y', strtotime($c['updated'])) . " " . date('g:i a', strtotime($c['updated'])) . "</div>") : ("") ?><div class="spacer"></div>
                    </div>
                    <?php
                    		}
                    ?>

Open in new window

0
 
LVL 83

Expert Comment

by:leakim971
ID: 26147763
...
GROUP BY how_to.user, how_to.howto, how_to.id, how_to.question, how_to.date, how_to.make, how_to.model

Open in new window

0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26147780
Still getting the same output:
Screen-shot-2009-12-30-at-1.36.4.png
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26147791
please post full page.
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26147795
full code I mean...
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26147801

<?php
	session_start();
	
	include("includes/auth.php");
	include("includes/db.php");

	if($_POST['enterBtn']) {
		$username = $_POST['username'];
		$password = $_POST['password'];
		
		$grabLogin = "SELECT username, password
			FROM login
			WHERE password = aes_encrypt('$password', 'th3m@n0nth3m00n')";
		$loginGrabbed = mysql_query($grabLogin) or die("The grab did not work because: " . mysql_error());
		
			if(mysql_num_rows($loginGrabbed) > 0) {
				$_SESSION['username'] = $username;
				header("Location:" . $_SESSION['current_url']);
			} else {
				$badlogin = "Your login credentials do not match what is in our databse.  Please try again";
			}
	}
	
	if($_POST['loginBtn']) {
		$username = $_POST['username'];
		$password = $_POST['password'];
		
		$grabLogin = "SELECT username, password
			FROM login
			WHERE password = aes_encrypt('$password', 'th3m@n0nth3m00n')";
		$loginGrabbed = mysql_query($grabLogin) or die("The grab did not work because: " . mysql_error());
		
			if(mysql_num_rows($loginGrabbed) > 0) {
				$_SESSION['username'] = $username;
				header("Location:" . $_SESSION['current_url']);
			} else {
				$badlogin = "Your login credentials do not match what is in our databse.  Please try again";
			}
	}
	
	if($_POST['search']) {
    	$question = $_POST['search'];
    	$destination = "/view-questions.php?question=$question";
    	
    	header("Location:" . $destination);
    }
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><?= (isset($_GET['qID'])) ? (" - " . $question['question']) : ("Welcome to ") ?>Autocahoots</title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
	<meta name="description" content="<?= htmlentities(stripslashes($question['answer'])) ?>" />
	<!--[if IE 7]>
	<link type="text/css" href="/styles/ie-style.css" rel="stylesheet" />
	<![endif]-->
	<link type="text/css" href="/styles/autocahoots-style.css" rel="stylesheet" />
	<link type="text/css" href="/styles/jquery.treeview.css" rel="stylesheet" />
	<script type="text/javascript" src="/scripts/jquery-1.3.2.js"></script>
	<script type="text/javascript" src="/scripts/jquery.treeview.js"></script>
	<script type="text/javascript" src="/scripts/model-slide.js"></script>
</head>
<body>
	<div class="wrapper">
		<div class="header">
			<a href="/"><img src="/images/logo.png" alt="Autocahoots" /></a>
				<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
					<div class="search-bar">
						<div class="search-text">
							<input type="image" src="/images/searchQbtn.png" />
								<div class="search">
									<input type="text" name="search" class="search-text" />
								</div>
						</div>
					</div>
				</form>
		</div>
		<div class="main-top"></div>
		<div class="main-mid">
			<div class="breadcrumb"><a href="/">Home</a> :: <b>My Activity</b></div>
			<div class="column-left">
				<h3 class="title">History of my contributions</h3>
                	<?php
                		$user = $_SESSION['username'];
                		$grabContribs = "SELECT answers.user, answers.answer, answers.qID, user_question.question, answers.date, user_question.id uID, user_question.make, user_question.model, COUNT(answers.qID) 'nb_answers'
							FROM answers
							LEFT JOIN user_question ON answers.qID = user_question.id
							WHERE answers.user = '$user'
							GROUP BY answers.user, answers.answer, answers.qID, user_question.question, answers.date, user_question.id, user_question.make, user_question.model
							UNION
							SELECT how_to.user, how_to.howto, how_to.id hID, how_to.question, how_to.date, NULL, how_to.make, how_to.model, COUNT(how_to.id) 'nb_howto'
							FROM how_to
							WHERE how_to.user = '$user'
							GROUP BY how_to.user, how_to.howto, how_to.id, how_to.question, how_to.date, how_to.make, how_to.model
							ORDER BY date DESC";
                        $contribsGrabbed = mysql_query($grabContribs) or die("Grab did not work because: " . mysql_error());
                        	while($c = mysql_fetch_array($contribsGrabbed)) {
                    ?>
                    <div class="repository">
                    	<span style="color: #076bdc"><?= $c['user'] ?></span> 
                    	<?php 
                    		if($c['nb_answers'] > 0) {
                    			echo "answered the Question";
                    		} elseif($c['nb_howto'] > 0) {
                    			echo "posted the How To";
                    		}
                    	?> "<span class="question-link"><a href="/view-question.php?qID=<?= $c['uID'] ?>"><?= $c['question'] ?></a></span>"<br/>[<span class="question-control"><a href="/category-questions.php?make=<?= $c['make'] ?>model=<?= $c['model'] ?>"><?= $c['make'] ?> <?= $c['model'] ?></a></span>] [<span class="question-control"><a href="/recategorize.php?qID=<?= $c['id'] ?>">Recategorize</a></span>] <?= (!empty($c['answer'])) ? ("[<span class='question-control'><a href='/edit-question.php?qID={$q['id']}'>Edit</a></span>]") : ("") ?><?= (!empty($c['updated'])) ? ("<div class='posting-left'>Answered: " . date('F, j Y', strtotime($c['updated'])) . " " . date('g:i a', strtotime($c['updated'])) . "</div>") : ("") ?><div class="spacer"></div>
                    </div>
                    <?php
                    		}
                    ?>
			</div>
			<div class="column-right">
			<?php
				include ("includes/templates/member-area.php");
			?>
			</div>
			<div class="spacer"></div>
		</div>
		<div class="main-bot"></div>
	</div>
	<?php
		include("includes/templates/footer.php");
	?>
	</div>
</body>
</html>

Open in new window

0
 
LVL 83

Expert Comment

by:leakim971
ID: 26147803
Could your run the SQL script and post some results in code snippet too ?
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26147824
Here is the query:
SELECT answers.user, answers.answer, answers.qID, user_question.question, answers.date, user_question.id uID, user_question.make, user_question.model, COUNT( answers.qID )  'nb_answers'
FROM answers
LEFT JOIN user_question ON answers.qID = user_question.id
WHERE answers.user =  'pingeyeg'
GROUP BY answers.user, answers.answer, answers.qID, user_question.question, answers.date, user_question.id, user_question.make, user_question.model
UNION SELECT how_to.user, how_to.howto, how_to.id hID, how_to.question, how_to.date, NULL , how_to.make, how_to.model, COUNT( how_to.id )  'nb_howto'
FROM how_to
WHERE how_to.user =  'pingeyeg'
GROUP BY how_to.user, how_to.howto, how_to.id, how_to.question, how_to.date, how_to.make, how_to.model
ORDER BY DATE DESC 
LIMIT 0 , 30

Open in new window

0
 
LVL 83

Expert Comment

by:leakim971
ID: 26147830
Now you have a script which return number of answers and and howto.
You should use this number for your test.

<?= ($c['qID'] ? "answered the Question" : "posted the How To") ?>

become :

<?= ($c['nb_answers'] <> "0") ? "answered the Question" : "posted the How To") ?>
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26147838
Here is the result:
user	answer	qID	question	date	uID	make	model	nb_answers
pingeyeg	I am now answering this question.	65	This is a test to see how things are working for t...	2009-12-29 11:04:11	65	Chevrolet	 	1
pingeyeg	This is a test and only a test.  Being very descri...	87	Posting a How To test to work on the My Activity p...	2009-12-28 12:15:44	NULL	Acura	Acura Vigor	1
pingeyeg	This is a test to check on the multi-input how to'...	31	I am testing to see how things are working.	2009-10-05 14:20:44	NULL	BMW	BMW X-Series	1

Open in new window

0
 
LVL 83

Expert Comment

by:leakim971
ID: 26147840
>Here is the query:
Not the query but the results.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26147875
You posted too soon  :)
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26147888
Also, here is the conditional statement I'm using in case you didn't see it in my post above.
if($c['nb_answers'] > 0) {
     echo "answered the Question";
} elseif($c['nb_howto'] > 0) {
     echo "posted the How To";
}

Open in new window

0
 
LVL 83

Expert Comment

by:leakim971
ID: 26147903
Look ID:26147830
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26147919
How do I look for that ID on this site?
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26147929
Hmmm... Use the search function of your browser.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26147935
No good.  How did you find it?
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26147948
Oh, are you referring to you previous post on this thread:

"Now you have a script which return number of answers and and howto.
You should use this number for your test.

<?= ($c['qID'] ? "answered the Question" : "posted the How To") ?>

become :

<?= ($c['nb_answers'] <> "0") ? "answered the Question" : "posted the How To") ?>"
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26147949
Each post have a number at their right top
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26147960
>Oh, are you referring to you previous post on this thread:
Oh yes my friend !
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26147972
Problem is the following doesn't change the wording:
<?php 
     if($c['nb_answers'] <> 0) {
          echo "answered the Question";
     } else {
          echo "posted the How To";
     }
?>

Open in new window

0
 
LVL 83

Expert Comment

by:leakim971
ID: 26147975
Why do you want to use that ?
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26147978
Also, I will be adding to my query based on the amount of tables will be output to this page.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26147989
I need the output to change pending what table it's being called from.

For instance, if I am calling from 3 tables, I want to change the wording to reflect that:

"answered the Question"
"posted the How To"
"answered the Beyond Question"
etc...
0
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 26148012
>Also, I will be adding to my query based on the amount of tables will be output to this page.
Next stage.

We want to see "answered the Question" or "posted the How To"

So modify your script. I think I understand what you really want. No need of COUNT and GROUP.

Use :

     if($c['type'] == 'A') {
          echo "answered the Question";
     } else {
          echo "posted the How To";
     }

Or in the HTML :

<?= ($c['type'] == 'A')) ? "answered the Question" : "posted the How To") ?>"
$grabContribs = "SELECT answers.user, answers.answer, answers.qID, user_question.question, answers.date, user_question.id uID, user_question.make, user_question.model, 'A' 'type'
							FROM answers
							LEFT JOIN user_question ON answers.qID = user_question.id
							WHERE answers.user = '$user'
user_question.make, user_question.model
							UNION
							SELECT how_to.user, how_to.howto, how_to.id hID, how_to.question, how_to.date, NULL, how_to.make, how_to.model, 'H' 'type'
							FROM how_to
							WHERE how_to.user = '$user'
							ORDER BY date DESC";

Open in new window

0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26148101
Hey, hey, now we're getting somewhere.  Problem is, the way it's coded makes the following happen:

Type
typeA
typeB
typeB

Also, you need to reverse your code from 'type' 'A' to 'A' 'type'

This way the column name becomes type instead of A.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 26148106
Which isn't a big deal unless that was your intention.  Regardless, it works and thanks for your help on this!

I had no idea you could do that.
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26148169
You're welcome! Thanks for the points! Have fun!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question