[SOLVED] pagementation to jump menu

This is a discussion on "[SOLVED] pagementation to jump menu" within the PHP Forum section. This forum, and the thread "[SOLVED] pagementation to jump menu are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jan 21st, 2008, 17:52
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,281
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
[SOLVED] pagementation to jump menu

i am building my developers site, and i have decided to use the blog i have built, but i want to adjust it a little, this is my pagementation page

PHP: Select all

 <?php include 'config.php'

$conn mysql_connect($dbhost$dbuser$dbpass) or die ('Error connecting to mysql'); 
mysql_select_db$dbname$conn ); 

$perPage 5// number to display on per page 

// Start by counting the number of posts 

$res mysql_query ("SELECT count(*) AS num FROM form") or die (mysql_error() . 'dying hurts'); 

$num mysql_fetch_assoc($res); 
$num $num['num']; 

mysql_free_result($res); 

// now work out how many pages there are, check if page has been sent via GET 

$numPages ceil($num $perPage); 

// Check to make sure pagenum will be 1 or greater, less than numpages and an actual number 
$pageNum  = (!empty($_GET['id']) &&  
             
is_numeric($_GET['id']) &&  
             
$_GET['id'] > 1)  
              
             ? (
$_GET['id'] < $numPages ?  ($_GET['id']) : $numPages) : 1// Set to 1 if not set or something dodgy 

// Okay, now we run the query and set the limits LIMIT xx, yy (x= start from , y= limit) 

$sql "SELECT * FROM form ORDER BY date DESC LIMIT " . ($pageNum 1) * $perPage ", $perPage"
$res mysql_query($sql$conn) or die(mysql_error()); 

while (
$row mysql_fetch_object($res)) {          
echo 
'<hr></hr>';
print  
$row->title ;
echo 
nl2br("\n");      
print 
strftime('%d %B %Y'$row->date); 
echo 
nl2br("\n");
echo 
nl2br("\n"); 
print 
$row->blog_mes;   



// Some paginananananananation 

echo '<div>'
for (
$i 1$i <= $numPages$i++) 

    if (
$pageNum != $i
    echo 
'<a href="index.php?id='$i'">'$i'</a> '
    else  
    echo 
'<b>'$i'</b>'

echo 
'</div>'

?>
that displays numbers like so

1 2 3 4 5 etc

what i would like to do is to sort it by date ( month and year ), then input the month and year into a jump menu like so

jan 08
feb 08
mar 08
apr 08
may 08
june 08 etc,

then next year it will change to

jan 09
feb 09
mar 09 etc,

i still want to display the pagementation at the bottom ( as it is )

but a jump menu that will update itself whenever i post a new blog for that month, so if i miss a month, that month would not be included in the jump menu list

its just so i can always have links to each month posted ( easy access )

does anyone know enough about this to help please,

thanks
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)
Reply With Quote

  #2 (permalink)  
Old Jan 22nd, 2008, 20:26
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,281
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
Re: pagementation to jump menu

ok, seems like no-one is able to answer this for me, but i have managed to do this so far

PHP: Select all

 <?php include 'main.php';?>
       <?php $conn=mysql_connect("localhost","root","") or die(mysql_error());
      
mysql_select_db("saltyblog") or die(mysql_error());

      
$result=mysql_query(" SELECT * FROM form");
      
$option="date";

      while(
$row=mysql_fetch_array($result))

      {
      
$option .= "<option";
      if (
$_POST['form']==$row['date']) {$option.= " selected='selected'";}
      
$option .= ">" $row['date'] . "</option>";
      }
      
?>

      <form method="post">

      <select>

      <?php echo $option?>
.
      </select><input type="submit" /></form>
a couple of problems though

first: Notice: Undefined index: form in C:\Program Files\EasyPHP 2.0b1\www\blog\index.php on line 204

second: it is displaying the date like so - 1201036656 ( needs also to be adjusted to show it by month and year - later )

can you help ?, attached is the image

cheers


__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)

Last edited by saltedm8; Feb 15th, 2008 at 12:20.
Reply With Quote
  #3 (permalink)  
Old Jan 22nd, 2008, 20:37
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,772
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: pagementation to jump menu

What is line 204?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #4 (permalink)  
Old Jan 22nd, 2008, 20:41
JustinStudios's Avatar
SuperMember

SuperMember
Join Date: Mar 2007
Location: USA
Posts: 406
Blog Entries: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to JustinStudios
Re: pagementation to jump menu

Ok, looks like the problem you are having is sorting by and formatting date stamps. I'd recommend using this link php Dates to learn how to format the long number into a more readable date. Wherever you store the content, that is where you need to store the date as well. I'm assuming that you are using a MySQL database and I'd recommend adding a date column. You can then Sort by Date to get it to align them in that order. The drop down would be a simple select button with the options generated in a while loop (while there is a date, print it) and that should solve those issues.

If you need more info, or need some code let me know and I'll see what I can do.
Reply With Quote
  #5 (permalink)  
Old Jan 22nd, 2008, 20:46
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,281
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
Re: pagementation to jump menu

Quote:
Originally Posted by alexgeek View Post
What is line 204?
PHP: Select all

if ($_POST['form']==$row['date']) {$option.= " selected='selected'";} 

JustinStudios

urrm, i am still pretty new to php, i can only do the basics, but give me five minutes and i will give you a link to the blog file so you can see everything for yourself

( link to full file blog download )
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)

Last edited by saltedm8; Jan 22nd, 2008 at 20:55. Reason: added file download
Reply With Quote
  #6 (permalink)  
Old Jan 22nd, 2008, 20:52
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,772
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: pagementation to jump menu

Maybe this?
PHP: Select all

      if (isset($_POST['form']) && $_POST['form'] == $row['date']) {$option.= " selected='selected'";} 

Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #7 (permalink)  
Old Jan 22nd, 2008, 20:57
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,281
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
Re: pagementation to jump menu

wow, thanks, error is gone -

just got to work out the date issue, oh and the submit button is not working, - its not taking me to the blog page
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)

Last edited by saltedm8; Jan 22nd, 2008 at 21:02.
Reply With Quote
  #8 (permalink)  
Old Jan 22nd, 2008, 21:35
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,772
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: pagementation to jump menu

Check that you are telling to go to the right place in the form tag.
The date issue i think was explained above?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #9 (permalink)  
Old Jan 22nd, 2008, 23:36
JustinStudios's Avatar
SuperMember

SuperMember
Join Date: Mar 2007
Location: USA
Posts: 406
Blog Entries: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to JustinStudios
Re: pagementation to jump menu

Wow, I went to class and came back and found Alex fixed the bug, Yay Alex!

As far as the date goes the link above will take care of that. If you have any questions implementing it please post back. Also, I can't seem to download the blog file even in a download manager.
Reply With Quote
  #10 (permalink)  
Old Jan 23rd, 2008, 17:03
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,281
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
Re: pagementation to jump menu

alexgeek - everything i tried either created errors, or had no effect

JustinStudios - i have removed tnymce from the file, and have managed to add it as an attachment ( it was too big originally )
Attached Files
File Type: zip blog.zip (350.3 KB, 2 views)
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)
Reply With Quote
  #11 (permalink)  
Old Jan 23rd, 2008, 19:08
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,281
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
Re: pagementation to jump menu

i have tried everything to convert this date from unix, please help - all i would require is the month
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)
Reply With Quote
  #12 (permalink)  
Old Jan 23rd, 2008, 19:09
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,772
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: pagementation to jump menu

Is it a mysql timestamp or a php one?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #13 (permalink)  
Old Jan 23rd, 2008, 19:29
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,281
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
Re: pagementation to jump menu

date table
date VARCHAR(25) NOT NULL,

how i recovered it last time
print strftime('%d %B %Y', $row->date);
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)

Last edited by saltedm8; Jan 23rd, 2008 at 19:34.
Reply With Quote
  #14 (permalink)  
Old Jan 23rd, 2008, 22:05
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,772
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: pagementation to jump menu

Try:
PHP: Select all

date('F'$row->date); 

Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #15 (permalink)  
Old Jan 24th, 2008, 05:54
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,281
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
Re: pagementation to jump menu

nope, sorry not working
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)
Reply With Quote
  #16 (permalink)  
Old Jan 24th, 2008, 05:56
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,772
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: pagementation to jump menu

What happens?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #17 (permalink)  
Old Jan 24th, 2008, 06:01
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,281
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
Re: pagementation to jump menu

where did you want me to put it ? - i have tried all over, then i could tell you
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)

Last edited by saltedm8; Jan 24th, 2008 at 06:07.
Reply With Quote
  #18 (permalink)  
Old Jan 24th, 2008, 06:21
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,772
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: pagementation to jump menu

Replace this for my code:
PHP: Select all

print strftime('%d %B %Y'$row->date); 

Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #19 (permalink)  
Old Jan 24th, 2008, 17:19
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,281
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
Re: pagementation to jump menu

that code is what makes the date on each blog, it still is not changing in the drop down, still in unix

it was from here

PHP: Select all

<?php include 'config.php'

$conn mysql_connect($dbhost$dbuser$dbpass) or die ('Error connecting to mysql'); 
mysql_select_db$dbname$conn ); 

$perPage 5// number to display on per page 

// Start by counting the number of posts 

$res mysql_query ("SELECT count(*) AS num FROM form") or die (mysql_error() . 'dying hurts'); 

$num mysql_fetch_assoc($res); 
$num $num['num']; 

mysql_free_result($res); 

// now work out how many pages there are, check if page has been sent via GET 

$numPages ceil($num $perPage); 

// Check to make sure pagenum will be 1 or greater, less than numpages and an actual number 
$pageNum  = (!empty($_GET['id']) &&  
             
is_numeric($_GET['id']) &&  
             
$_GET['id'] > 1)  
              
             ? (
$_GET['id'] < $numPages ?  ($_GET['id']) : $numPages) : 1// Set to 1 if not set or something dodgy 

// Okay, now we run the query and set the limits LIMIT xx, yy (x= start from , y= limit) 

$sql "SELECT * FROM form ORDER BY date DESC LIMIT " . ($pageNum 1) *