UP Computer Science Interns' Blog

May 28, 2010

PHP-SQL Fail

Filed under: dcs_200719929 — shippou @ 5:42 pm

I made this code myself.

Note: polls table contains pid, topic, question, uid and isActive fields.


//retrieve all results
$results = $db->query("SELECT * FROM polls");

if ($db->error!=""){
echo "There was an error retrieving the polls. Please try again.";
return;
}

//print all the surveys
//note: only active polls must be listed.
?>
<table>
<tr><th>Topic</th><th>Question</th><th>Poster</th></tr>
<?php
while ($rows = $results->fetch_assoc()) {
$pid = $rows['pid'];
$topic = $rows['topic'];
$question = $rows['question'];
$poster = $rows['uid'];
$isActive = $rows['isActive'];

//override css for these links
if ($isActive==1) {
echo "<tr>
<td><a href=’print_survey.php?pid={$rows[‘pid’]}’ style=’color:blue; text-decoration: underline’>{$topic}</a></td>

<td>{$question}</td>
<td>{$poster}</td>
</tr>";
}

}
?>

Advertisements

Blog at WordPress.com.

%d bloggers like this: