Jump to content

convy

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

convy's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Got it working with your script cheers! Changed the categories into basic links gonna have ratings etc as the drop down instead. Thanks for the help.
  2. Hi basically the category part of this script works but when i try the paginating part (next) it goes back to showing all of the categories so in other words i want it to stay on the same category when i click next. I tried passing the category through the url which ive kept in the code below and although the url does show the category im meant to be in, the code ignores it and shows the latest articles from all categories. I've been trying to figure this out for about 4 days and i dont really know where to even start since im completely new to php so thanks in advance for any help. Anyway heres the code: <select name="sort_category"> <option disabled selected>Sort by Category</option> <option value="General">General</option> <option value="Music">Music</option> <option value="Funny">Funny</option> </select> <input type="submit" /> </form> <br> <?php include('admin/conf.php'); include('admin/functions.php'); if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) { $startrow = 0; } else { $startrow = (int)$_GET['startrow']; } if (isset($_REQUEST['sort_category'])) { $select_category = $_REQUEST['sort_category']; $connection = mysql_connect($host, $user, $pass) or die ('Unable to connect!'); mysql_select_db($db) or die ('Unable to select database!'); $sql = "SELECT id, title, content, photo, timestamp FROM approved WHERE category='$select_category' ORDER BY timestamp DESC LIMIT $startrow,2"; $result = mysql_query($sql) or die ("Error in query: $query. " . mysql_error()); if (mysql_num_rows($result) > 0) { while($row = mysql_fetch_object($result)) { ?> <img src="http://trunham.info/pictures/ <?php echo $row->photo;?>" width="100" height="100" border="1" align="left" /> <font size="+2" class="style1"><a style="text-decoration:none" class="articletext" href="article.php?id= <?php echo $row->id; ?>" ><?php echo $row->title; ?></a></font><br><br> <font class="articletext2"><?php echo substr($row->content,0,100) ;?>...</font> <?PHP echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+2).'category='.($select_category).'">Next</a>'; $prev = $startrow - 2; if ($prev >= 0) echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.$prev.'">Previous</a>'; ?> I do have the closing curly brackets later on and after this i also have an else part which runs if no category is selected and this outputs the same results that im getting from the pagination but i took it out to see if it was the problem and the paginating still wasnt sticking to the category so i assume it isnt. Here it is anyway: <?php } else { echo 'Latest Articles:<br><br>'; $connection = mysql_connect($host, $user, $pass) or die ('Unable to connect!'); mysql_select_db($db) or die ('Unable to select database!'); $query = "SELECT id, title, content, photo, timestamp FROM approved ORDER BY timestamp DESC LIMIT 0, 5"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); if (mysql_num_rows($result) > 0) { while($row = mysql_fetch_object($result)) { ?> <img src="http://trunham.info/pictures/ <?php echo $row->photo;?>" width="100" height="100" border="1" align="left" /> <font size="+2" class="style1"><a style="text-decoration:none" class="articletext" href="article.php?id= <?php echo $row->id; ?>" ><?php echo $row->title; ?></a></font><br><br> <font class="articletext2"><?php echo substr($row->content,0,100) ;?>...</font> <?php } } } mysql_close($connection); ?> sorry if i haven't explained it very well. i dont really know what im doing
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.