I have a dynamic page and a user can create or view posts. As of right now all of the posts show, I want to organize my posts by categories. But once the user goes to the page all of the posts will show at first. But at the top will be a box where you can select "show all" "Category 1" "Cat 2" "cat 3" or "cat 4". Show all will be automatically checked once the user enters the page, but if they click a different box it will only show those posts with that particular category. Is this the right way to do this? and does anyone have and example or coding tutorials I could use, I have a bad/small experience with php.
my code:
<?php
//if(isset($_GET['message'])){
//echo "<br/><b>".htmlspecialchars(strip_tags(stripslashes(trim($_GET['message']))))."!</b><br/>";
//}
if(!isset($_GET["eventId"])){
// $doQuery contains all rows which satisfied the query, but in our case it is only 1 row
// because we have no more than 1 page with same id
// mysql_fetch_array - a function which can be used to loop through rows in query result
// in this case we can use it without while loop because we need only 1 row
$result = mysql_fetch_array($doQuery);
echo "<h6>".$result["name"]."</h6><br/>";
?>
</div>
</div><!--title-->
</div>
<div id="content">
<div id="table">
<p>
<?php
if(isset($_SESSION['username'])){
echo "<a href=\"addEvent.php?page=$pageId\"><img class=\"button\" src=\"images/button1.png\"></a><br/><br/>";
}
$query = "select * from events where page_id=$pageId order by id desc";
$doQuery = mysql_query($query);
if(mysql_num_rows($doQuery)>0){
echo "<div id=\"post\">";
echo "<div id=\"head\"><h3></h3></div>";
echo "<br/>";
echo "<br/>";
while($result = mysql_fetch_array($doQuery)){
$query = "select Name, username from users where id=".$result["user_id"];
$doTempQuery = mysql_query($query);
$resultTemp = mysql_fetch_array($doTempQuery);
$name = $resultTemp["Name"];
$email = $resultTemp["username"];
if($email==$_SESSION['username']){
echo "<div id=\"single\">";
echo "</div>";
echo "<br/>";
echo "<br/>";
echo "<div id=\"element\">";
echo "<div id=\"inner\">";
echo "<div id=\"edit\"><a href=\"deleteEvent.php?event_id=".$result["id"]."&pageId=$pageId\">Delete</a> | <a href=\"editEvent.php?event_id=".$result["id"]."&pageId=$pageId\">Edit</a></div>";
}
echo "<div id=\"words\"><h8>Created by:</h8>$name<br> <h8>Email:</h8>$email</div>"; //email
echo "<div id=\"first\">";
echo "<div id=\"what\"></div><div id=\"whatbox\">".$result["what"]."</div>";
echo "</div>";
echo "<div id=\"second\">";
echo "<div id=\"when\"></div><div id=\"whenbox\">".$result["when"]."</div>";
echo "</div>";
echo "<div id=\"third\">";
echo "<div id=\"where\"></div><div id=\"wherebox\">".$result["where"]."</div>";
echo "</div>";
echo "<div id=\"fourth\">";
echo "<div id=\"sponsor\"></div><div id=\"sponsorbox\">".$result["sponsored_by"]."</div>";
echo "</div>";
echo "<div id=\"fifth\">";
echo "<div id=\"details\"></div><div id=\"detailsbox\">".$result["details"]."</div>";
echo "</div>";
echo "<br/>";
echo "<br/>";
echo "</div>";
echo "</div>";
}
echo "</table>";
echo "</div>";
echo "<br/>";
echo "<br/>";
} else echo "No events yet.";
} else echo "No posts yet.";
?>and then start typing your HTML. If you have a small bit of PHP to add to a lot of HTML, escape the HTML momentarily<?php echo $var; ?>and echo it out. – mseancole Sep 12 '12 at 19:04