Jump to content


Photo

Pagation with mySQL results


  • Please log in to reply
54 replies to this topic

#1 Vandalised

Vandalised

    Jedi In Training

  • Members
  • PipPip
  • 307 posts
  • Gender:Male
  • Location:UK
  • Interests:Most sports, football, cricket, hockey, tennis, golf. Web design, graphic design (photoshop) Socialising with friends, going to clubs, bars, concerts.

Posted 15 July 2006 - 03:26 PM

Hey all!

I'm trying to do Pagation with mySQL results for my site, what I want is to list tutorials like on zulumonkey.org and P2L I assume the list of tutorials comes from a database? So how would I go about making a database with the relevant information? :) I'm sure this is something really easy to do, but I'm no expert. :) Thanks in advance.

Regards.!
:D
Rich

#2 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 15 July 2006 - 03:36 PM

Ok :D

Sorry for blowing you off via PM but its always better to post here :) Wider spectrum of support :)

Your question kinda covers a wide area....from creating the database to what field types to use etc etc.

*theatrical sign* ;)

Ok....

Creating a mysql database in cpanel

Managing your database with phpmyadmin

Inseting data: http://www.infinite-...-mysql-database

If those dont help, what you need to lookup is inserting data into a mysql database using INSERT & mysql_query.

Sorry for the crap ass reply, just busy with other things atm :) (ok, playing tce lol!)

#3 Vandalised

Vandalised

    Jedi In Training

  • Members
  • PipPip
  • 307 posts
  • Gender:Male
  • Location:UK
  • Interests:Most sports, football, cricket, hockey, tennis, golf. Web design, graphic design (photoshop) Socialising with friends, going to clubs, bars, concerts.

Posted 15 July 2006 - 03:54 PM

Hey again .Matt!

No problem! I figure your right (wider spectrum of support).

I'll try and elabrate a tiny bit more, thanks for the advice by the way. What I want is a page numbering system, like P2L use to show there tutorials on more than 1 page, like about 10 tutorials will be displayed on the first page then 10 more on the second page. I know I need to use a database I know how to create and connect to a database etc. But what I do not know is how to get them tutorials to show on the pages.

#4 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 15 July 2006 - 04:11 PM

AHA, ok right....lol.
I hope i'm achually right this time :)


Well, i believe there was a carbon copy of this question asked just a few hours ago and my response will be the same to you as it was then.

Paginaton

You can look through those, look at the comments and get a good idea of how they work, or you can wait a couple of hours for when i got time and i can post back with one :)

Up to you :D

*Ive probally misunderstood again, lol*

This link is best btw: http://www.phpfreaks...orials/43/0.php

Edited by .Matt, 15 July 2006 - 04:12 PM.


#5 Vandalised

Vandalised

    Jedi In Training

  • Members
  • PipPip
  • 307 posts
  • Gender:Male
  • Location:UK
  • Interests:Most sports, football, cricket, hockey, tennis, golf. Web design, graphic design (photoshop) Socialising with friends, going to clubs, bars, concerts.

Posted 15 July 2006 - 04:26 PM

Hey hey! (Again)

I'm starting to hit my head off the keyboard LOL! It's actually so hard to explain, well its most likley really easy to but I've been so busy these past days, I'm tired and I need my bed. I'm so sorry I'm crap at explaing this, but its getting closer! All the tutorials I've looked through and the ones on that link you give me are all about "Now, let’s write a little script which will take ALL of our records and print them on a single page." Making the script to show the records, but I know how to do that bit. What I need to know it how to make the records, the records I want to show, is a list of tutorials like P2L show a list of tutorial using Pagation, it takes data from a database yeah? I hope that helps :) :) Atleast I have been able to keep my grammer and spelling up to standard! (I think)

Regards.!
:D
Rich

#6 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 15 July 2006 - 04:35 PM

AHHHH, ok. lol.

So you want to know how to make....say...a form that will insert data INTO the database so you can display it after?

(it could just be me being thick if im wrong again :) )

#7 Vandalised

Vandalised

    Jedi In Training

  • Members
  • PipPip
  • 307 posts
  • Gender:Male
  • Location:UK
  • Interests:Most sports, football, cricket, hockey, tennis, golf. Web design, graphic design (photoshop) Socialising with friends, going to clubs, bars, concerts.

Posted 15 July 2006 - 04:40 PM

*Says a very tired hello*!

:D :) ;) I think thats it! :o !!!!!!! As long as the data that can be inserted is HTML like for example a table with a link (thats in the table) that links to a tutorial, then a short desciption about that tutorial. Please be right :) haha!! Thanks for helping this much anyway.

Regards.!
:)
Rich

#8 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 15 July 2006 - 05:01 PM

aha, ok, right, i wont lie....your a little confusing lol.

I'll give you a simple example which you can modify/research into....

<?php

$act = $_GET['act'];

$config = array(
			 'user' => 'username',
			 'pass' => 'password',
			 'DB' => 'database_name',
			 'host' => 'localhost'
			);
			
@mysql_connect($config['host'], $config['user'], $config['pass']) or die(mysql_error());
@mysql_select_db($config['DB']) or die(mysql_error());


if(isset($_POST['send']))
{
	  $name = addslashes(htmlspecialchars($_POST['name'])); 
	  $url = addslashes(htmlspecialchars($_POST['url'])); 
	  
	@mysql_query("INSERT INTO `table` (id, name, url) VALUES ('', $name, $url)") or die(mysql_error());
	
	echo 'The data was insert - yay!';
}
else
{
	  echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">
			<input type="text" name="name" value="tutorial name here" />
			<input type="text" name="url" value="tutorial url here" />
			<input type="submit" name="send" value="Go!" />
			</form><br />';
			
			echo '<a href="?act=view">View whats in the database!</a>';
}

if($act == "view")
{
	  $query = @mysql_query("SELECT * FROM `table` ORDER by id DESC") or die(mysql_error());
	  
	  while($row = mysql_fetch_array($query))
	  {
			echo $row['id'] .'<br />'. $row['name'] .'<br />'. $row['url'];
			echo '<br /><br />';
	  }
}
	  
  
?>

NOTE: this is without pagination. You can add that :)

Hopefully that gives you a little more understanding? Thatis how to insert and view mysql data, in a *very* crude and quick manor :)

Edited by .Matt, 15 July 2006 - 05:02 PM.


#9 Vandalised

Vandalised

    Jedi In Training

  • Members
  • PipPip
  • 307 posts
  • Gender:Male
  • Location:UK
  • Interests:Most sports, football, cricket, hockey, tennis, golf. Web design, graphic design (photoshop) Socialising with friends, going to clubs, bars, concerts.

Posted 16 July 2006 - 11:26 AM

Hey, thanks for the help. I do understand how that works yeah.

But it seems it's just one problem after another, I keep getting this error

"You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'i can insert tutorial, www.link.com/testest)' at line 1"

Which I take it means I have an older version of mySQL server, which means the code won't work. SO I bet there isn't much I can do about that is there? :) Thanks for getting me this far anyway bud ;)

Regards.!
:D
Rich

Edited by Rich69, 16 July 2006 - 11:27 AM.


#10 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 16 July 2006 - 11:30 AM

Try this...

<?php

$act = $_GET['act'];

$config = array(
			 'user' => 'username',
			 'pass' => 'password',
			 'DB' => 'database_name',
			 'host' => 'localhost'
			);
			
@mysql_connect($config['host'], $config['user'], $config['pass']) or die(mysql_error());
@mysql_select_db($config['DB']) or die(mysql_error());


if(isset($_POST['send']))
{
	  $name = addslashes(htmlspecialchars($_POST['name']));
	  $url = addslashes(htmlspecialchars($_POST['url']));
	  
	@mysql_query("INSERT INTO `table` (`id`, `name`, `url`) VALUES ('', $name, $url)") or die(mysql_error());
	
	echo 'The data was insert - yay!';
}
else
{
	  echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">
			<input type="text" name="name" value="tutorial name here" />
			<input type="text" name="url" value="tutorial url here" />
			<input type="submit" name="send" value="Go!" />
			</form><br />';
			
			echo '<a href="?act=view">View whats in the database!</a>';
}

if($act == "view")
{
	  $query = @mysql_query("SELECT * FROM `table` ORDER by id DESC") or die(mysql_error());
	  
	  while($row = mysql_fetch_array($query))
	  {
			echo $row['id'] .'<br />'. $row['name'] .'<br />'. $row['url'];
			echo '<br /><br />';
	  }
}
	  
  
?>

Sorry i didnt text it last night. (notice the backticks on the mysql field names).

Edited by .Matt, 16 July 2006 - 11:33 AM.


#11 Vandalised

Vandalised

    Jedi In Training

  • Members
  • PipPip
  • 307 posts
  • Gender:Male
  • Location:UK
  • Interests:Most sports, football, cricket, hockey, tennis, golf. Web design, graphic design (photoshop) Socialising with friends, going to clubs, bars, concerts.

Posted 16 July 2006 - 11:54 AM

Try this...

<?php

$act = $_GET['act'];

$config = array(
			 'user' => 'username',
			 'pass' => 'password',
			 'DB' => 'database_name',
			 'host' => 'localhost'
			);
			
@mysql_connect($config['host'], $config['user'], $config['pass']) or die(mysql_error());
@mysql_select_db($config['DB']) or die(mysql_error());


if(isset($_POST['send']))
{
	  $name = addslashes(htmlspecialchars($_POST['name']));
	  $url = addslashes(htmlspecialchars($_POST['url']));
	  
	@mysql_query("INSERT INTO `table` (`id`, `name`, `url`) VALUES ('', $name, $url)") or die(mysql_error());
	
	echo 'The data was insert - yay!';
}
else
{
	  echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">
			<input type="text" name="name" value="tutorial name here" />
			<input type="text" name="url" value="tutorial url here" />
			<input type="submit" name="send" value="Go!" />
			</form><br />';
			
			echo '<a href="?act=view">View whats in the database!</a>';
}

if($act == "view")
{
	  $query = @mysql_query("SELECT * FROM `table` ORDER by id DESC") or die(mysql_error());
	  
	  while($row = mysql_fetch_array($query))
	  {
			echo $row['id'] .'<br />'. $row['name'] .'<br />'. $row['url'];
			echo '<br /><br />';
	  }
}
	  
  
?>

Sorry i didnt text it last night. (notice the backticks on the mysql field names).



Yep, but sadly I keep getting the same error for some reason :)

#12 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 16 July 2006 - 12:27 PM

You tried the changed version? in the last post?

ok...hm...try...

<?php

$act = $_GET['act'];

$config = array(
			 'user' => 'username',
			 'pass' => 'password',
			 'DB' => 'database_name',
			 'host' => 'localhost'
			);
			
@mysql_connect($config['host'], $config['user'], $config['pass']) or die(mysql_error());
@mysql_select_db($config['DB']) or die(mysql_error());


if(isset($_POST['send']))
{
	  $name = addslashes(htmlspecialchars($_POST['name']));
	  $url = addslashes(htmlspecialchars($_POST['url']));
	  
	@mysql_query("INSERT INTO `table` (`id`, `name`, `url`) VALUES ('', '$name', '$url')") or die(mysql_error());
	
	echo 'The data was insert - yay!';
}
else
{
	  echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">
			<input type="text" name="name" value="tutorial name here" />
			<input type="text" name="url" value="tutorial url here" />
			<input type="submit" name="send" value="Go!" />
			</form><br />';
			
			echo '<a href="?act=view">View whats in the database!</a>';
}

if($act == "view")
{
	  $query = @mysql_query("SELECT * FROM `table` ORDER by id DESC") or die(mysql_error());
	  
	  while($row = mysql_fetch_array($query))
	  {
			echo $row['id'] .'<br />'. $row['name'] .'<br />'. $row['url'];
			echo '<br /><br />';
	  }
}
	  
  
?>


#13 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 16 July 2006 - 12:30 PM

It's not because you have an older version, it's because you have an error in your syntax :)
Since SELECT statements rarely cause that problem, i'm giong to assume it's the INSERT statement that has the problem.
@mysql_query("INSERT INTO `table` (id, name, url) VALUES ('', '".mysql_real_escape_string($name)."', '".mysql_real_escape_string($url)."')") or die(mysql_error());
To hell with backticks ;) i added quotes around the values along with mysql_real_escape_string() :D

Edited by rc69, 16 July 2006 - 12:31 PM.


#14 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 16 July 2006 - 12:32 PM

To hell with backticks :D i added quotes around the values along with mysql_real_escape_string() :D


Thats what i did in the previous post ;) (without mysql_real_escape_string).

btw: Am i now officially the only person who adds backticks? lol. It seems you and coolaid don't.... :)

Edited by .Matt, 16 July 2006 - 12:33 PM.


#15 Vandalised

Vandalised

    Jedi In Training

  • Members
  • PipPip
  • 307 posts
  • Gender:Male
  • Location:UK
  • Interests:Most sports, football, cricket, hockey, tennis, golf. Web design, graphic design (photoshop) Socialising with friends, going to clubs, bars, concerts.

Posted 16 July 2006 - 12:32 PM

Hey, yeah I tryed that one, and I just tried this one.... and .... it WORKED! ;) :D Thanks Matt bud :) Cheers for all the help.

Regards.!
:D
Rich

#16 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 16 July 2006 - 12:41 PM

No, you just beat me to it. I loaded the page before you posted, and it took me 3 minutes to finally hit the submit button ;)

And yes, i think you're the only one who follows proper syntax there. I use it in my DBMS just for compatability's sake, but for my own code, i just don't feel like reaching up and hitting the backtick key :)

#17 Vandalised

Vandalised

    Jedi In Training

  • Members
  • PipPip
  • 307 posts
  • Gender:Male
  • Location:UK
  • Interests:Most sports, football, cricket, hockey, tennis, golf. Web design, graphic design (photoshop) Socialising with friends, going to clubs, bars, concerts.

Posted 16 July 2006 - 01:28 PM

Ok I think im going to give up... In the long run none of this has give me what I want, I can't do it and I don't understand, I've been tryong for 2 days now and im really pissed off, some body put me out of my miseray and make me a pagination code, including database as an example.

I WANT TO SHOW TUTORIALS LIKE PIXEL2LIFE AND ZULUMONKEY WITH THE TUTORIAL AND DESCRIPTION IN A PRETTY TABLE HOW CAN I DO THIS??????

#18 Vandalised

Vandalised

    Jedi In Training

  • Members
  • PipPip
  • 307 posts
  • Gender:Male
  • Location:UK
  • Interests:Most sports, football, cricket, hockey, tennis, golf. Web design, graphic design (photoshop) Socialising with friends, going to clubs, bars, concerts.

Posted 16 July 2006 - 01:32 PM

Ok Im adding an image Posted Image

see the red circles... the way the results are in them box's thats what i want, with the page numbering system.

#19 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 16 July 2006 - 01:37 PM

oh for christ sake lol.

The first few links that i gave you were tutorials on pagination....(which is the numbering etc etc etc!)

http://www.phpfreaks...orials/43/0.php

First i thought thats what you want, then i thought you want to know how to insert the data, NOW we are back to pagination again?!?!

#20 Vandalised

Vandalised

    Jedi In Training

  • Members
  • PipPip
  • 307 posts
  • Gender:Male
  • Location:UK
  • Interests:Most sports, football, cricket, hockey, tennis, golf. Web design, graphic design (photoshop) Socialising with friends, going to clubs, bars, concerts.

Posted 16 July 2006 - 01:39 PM

oh for christ sake lol.

The first few links that i gave you were tutorials on pagination....(which is the numbering etc etc etc!)

http://www.phpfreaks...orials/43/0.php

First i thought thats what you want, then i thought you want to know how to insert the data, NOW we are back to pagination again?!?!



Yes, yes it seems like it doesn't it :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users