Hey i have a tms and it uses the end; tag to sepperate the differnt parts, like display cat, display tut .. but if i use that it deletes all the html below where it is included so is there a way i can remove it without all the other segments merging into 1 /
Sepperating segments
Started by Bl4ck-Vip3r, Mar 09 2007 02:33 PM
3 replies to this topic
#1
Posted 09 March 2007 - 02:33 PM
#2
Posted 09 March 2007 - 04:36 PM
You'll probably have to show us an example of what you are talking about, as I for one cannot visualize how this whole thing works.
#3
Posted 09 March 2007 - 04:53 PM
<?php
//Getting the file db.php which includes our database settings.
define( 'DB_PATH' , "./" );
require DB_PATH."db.php";
//Setting up a variable to request the category which is in the URL
$request_cat = $_REQUEST['category'];
//Displaying an actual tutorial
if (isset($id)) {
// Updating the views, and grabbing a tutorial based on what id it has.
$update = mysql_query("UPDATE $mysql_table SET views = views + 1
WHERE id='$id'");
$result = mysql_query("SELECT * FROM $mysql_table
WHERE id='$id'");
while($row = mysql_fetch_array($result)){
// Template for the tutorial
echo "
<div align='left' ><strong>
<a href='tutorials.php?category=".$row['category']."&id=".$row['id']."
'>".$row['title']."</a>
</strong>
</div></td>
<td width='125'><div align='right'>
[ Views: ".$row['views']." ]</div>
</td>
</tr>
</td>
</tr>
<tr>
<td>
<center>
<div id = 'Dash'></div>
</center>
</td>
</tr>
<tr>
<td><div align='left'>".$row['content']."</div></td>
</tr>
<tr>
<td>
<center>
<div id = 'Dash'></div>
</center>
<div align='left'>
<tr>
<td width=><div align='left'>Added: ".$row['date']."</div>
</td>
<td><div align='right'>Author:
<a href='mailto:".$row['email']."'
>".$row['author']."</a> </div></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td><div align='left'>Category:
<a href='tutorials.php?category=".$row['category']."
>".$row['category']."</a> </div></td>
</tr>
</td>
</tr>
"; // End of template of tutorial
} // End of grabbing data
exit;// Stopping anything below from interfearing with this sectiom
} // End of Displaying an actual tutorial
?>
<?php
//Displaying tutorials in a cateogry.
if ($category == $request_cat) {
//Grabbing information from the database.
$result = mysql_query("SELECT * from $mysql_table
where category = '$category' ORDER BY ID DESC");
while($row = mysql_fetch_array($result)) {
//Template for the tutorials in a category.
echo "
<table width='350' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td width='100' align='center' valign='middle'><div align='center'>
<a href='tutorials.php?category=".$row['category']."&id=".$row['id']."'>
<img src='".$row['avatar']."' alt='".$row['title']."' title='".$row['title']."'
width='75' height='75' border='0'></a>
</div></td>
<td width='300'>
<table width='100%' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td>
<div align='left'><strong>".$row['title']."</strong></div></td>
</tr>
<tr>
<td>
<div align='left'><font size '7'> ".$row['description']." </font></div></td>
</tr>
<tr>
<td>
<table width='100%' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td><div align='left'>Added: ".$row['date']."</div></td>
<td width='100'><div align='right'>Views: ".$row['views']."</div></td>
</tr>
</table></td>
</tr>
<tr>
<td><table width='100%' border='0' cellspacing='0' cellpadding='0'>
<tr>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table><br>
"; // End of Template for the tutorials in a category.
} // End of grabbing information from database.
} // End of Displaying tutorials in a cateogry.
// Main Tutorial page. This is where all your categories will be listed.
if (!$category) {
//This makes a list of all the cateogries that are in the database! No need to make the links yourself!
$result = mysql_query("SELECT DISTINCT category from $mysql_table ");
while($row = mysql_fetch_array($result)) {
// Showing all the categories
echo "
<a href='tutorials.php?category=".$row['category']."'
>".$row['category']."</a><br>
"; // End of showing all the categories
} // End of grabbing unique categories in database
}// End of main tutorial page
?>
This is the code and it is php included into a template which is the html look of the site... the bit where it shows the catagories work fine and the bit where it shows tuts in a catagory is fine but when its showing an actual tutorial it cuts of the footer of the html template and if i delete the exit; it merges all the php bits togeather on the tutorial page and if i just include the footer into the php in an echo it is missaligned. so i was wondering weather there is a way to delete the exit; but still make it function as normal?
Or use like a goto tag because what it seems is happening is its reading the code and the code says if the cat id is set show tuts in that cat.... and if tutid is set show that tutorial. But. if the exit is deleted it merges them so if the catid and tut id are set (which is true because it will have listed the the tuts of a certain cat eg ?cat=php ..... then when a tut is clicked it becomes ?catid=php&tutid=3 so both the functions are true and so show.
is there now fail safe like if tutid is set dnt show the catagory if any of this makes sence sorry for not organizing it and paragraphing im in a rush.
#4
Posted 09 March 2007 - 07:59 PM
Simply change the logic of it, and make the entire thing an if/elseif/else block.
For instance, change this line.
To.
And this line.
To.
Unless I'm mis-reading your code and what you are wanting to do, that should do it.
And by the way, don't use the $_REQUEST superglobal, its just opening you up to some un-reliable data. Plus, you shouldn't rely on automatic variables being passed from the $_GET superglobal. You need to use the actual array to access the data, otherwise you are opening yourself up to attacks, bugs, data conflict, server setting conflicts, and the like. Plus its just plain ignorant...
For instance, change this line.
if ($category == $request_cat) {
To.
elseif ($category == $request_cat) {
And this line.
if (!$category) {
To.
else{
Unless I'm mis-reading your code and what you are wanting to do, that should do it.
And by the way, don't use the $_REQUEST superglobal, its just opening you up to some un-reliable data. Plus, you shouldn't rely on automatic variables being passed from the $_GET superglobal. You need to use the actual array to access the data, otherwise you are opening yourself up to attacks, bugs, data conflict, server setting conflicts, and the like. Plus its just plain ignorant...
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
