Pagation with mySQL results
#1
Posted 15 July 2006 - 03:26 PM
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.!
Rich
#2
Posted 15 July 2006 - 03:36 PM
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
Posted 15 July 2006 - 03:54 PM
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
Posted 15 July 2006 - 04:11 PM
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
*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
Posted 15 July 2006 - 04:26 PM
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.!
Rich
#6
Posted 15 July 2006 - 04:35 PM
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
Posted 15 July 2006 - 04:40 PM
I think thats it! !!!!!!! 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
Posted 15 July 2006 - 05:01 PM
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
Posted 16 July 2006 - 11:26 AM
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.!
Rich
Edited by Rich69, 16 July 2006 - 11:27 AM.
#10
Posted 16 July 2006 - 11:30 AM
<?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
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
Posted 16 July 2006 - 12:27 PM
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
Posted 16 July 2006 - 12:30 PM
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()
Edited by rc69, 16 July 2006 - 12:31 PM.
#14
Posted 16 July 2006 - 12:32 PM
To hell with backticks i added quotes around the values along with mysql_real_escape_string()
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
Posted 16 July 2006 - 12:32 PM
Regards.!
Rich
#16
Posted 16 July 2006 - 12:41 PM
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
Posted 16 July 2006 - 01:28 PM
I WANT TO SHOW TUTORIALS LIKE PIXEL2LIFE AND ZULUMONKEY WITH THE TUTORIAL AND DESCRIPTION IN A PRETTY TABLE HOW CAN I DO THIS??????
#18
Posted 16 July 2006 - 01:32 PM
see the red circles... the way the results are in them box's thats what i want, with the page numbering system.
#19
Posted 16 July 2006 - 01:37 PM
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
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