PDA

View Full Version : [PHP] Selecting a Row with a specific column


Robert
07-08-03, 06:32 PM
Ok.. I'm new to Php and am learning everything.

My question is this:

I have a table setup with the following:

column|Question|Answer|Category|
row|Question1|Answer1|general
row|Question2|Answer2|dns

How can I make to dispaly ONLY rows that contain the word "general" in their Category Column?

Right now i'm using the following to display ALL questions with answers

<?php

//
$result = @mysql_query('SELECT Question, Answer, Category FROM Faq');
if (!$result) {
die('<p>Error performing query: ' . mysql_error() . '</p>');
}

//
while ( $row = mysql_fetch_array($result) ) {
echo('<p><b>' . $row['Question'] .
'<p></b>' . $row['Answer'] .
'<br><i>' . $row['Category'] . '</i><p>');

}

?>


Any/ALL Help is appreciated!

soapsud
07-08-03, 08:27 PM
your query would look like:

SELECT question, answer, category FROM table WHERE category = 'general'

may want to read up a bit on database normalization as well, as it sounds like the table could be split up:

http://www.databasejournal.com/sqletc/article.php/26861_1428511_4

generally speaking, 3rd normal form is considered decent database design.