Links to reorder data in a table in a webpage?

Post March 15th, 2008, 1:22 pm

I have a page that is just a connection to a database to pull up links to guide pages.


Here it is:


Code: [ Download ] [ Select ]
<?php include("../layout/connect.php");
$id = intval($_GET['id']);
if($id>=1){
$query = mysql_query('SELECT * FROM `html` WHERE `id`=' . $id . ' LIMIT 1');
}
if($id<1){
$query = mysql_query('SELECT * FROM `nav` WHERE `id`=' . $id . ' LIMIT 1');
}
$row = mysql_fetch_array( $query );?>
<?php include('../layout/1.php'); ?><?php if($id<1){ echo 'Basic HTML Guides'; } echo $row['title']; ?><?php include('../layout/2.php'); ?>
<h1><?php echo $row['title'];?><?php if($id>=1){ echo '<br />Author(s): ' . $row['user']; }?></h1>
<?php if($id<1){ include('html_menu.php'); } ?>
<?php if($id>=1){echo $row['content'];}?>
<?php include('../layout/3.php'); ?>
  1. <?php include("../layout/connect.php");
  2. $id = intval($_GET['id']);
  3. if($id>=1){
  4. $query = mysql_query('SELECT * FROM `html` WHERE `id`=' . $id . ' LIMIT 1');
  5. }
  6. if($id<1){
  7. $query = mysql_query('SELECT * FROM `nav` WHERE `id`=' . $id . ' LIMIT 1');
  8. }
  9. $row = mysql_fetch_array( $query );?>
  10. <?php include('../layout/1.php'); ?><?php if($id<1){ echo 'Basic HTML Guides'; } echo $row['title']; ?><?php include('../layout/2.php'); ?>
  11. <h1><?php echo $row['title'];?><?php if($id>=1){ echo '<br />Author(s): ' . $row['user']; }?></h1>
  12. <?php if($id<1){ include('html_menu.php'); } ?>
  13. <?php if($id>=1){echo $row['content'];}?>
  14. <?php include('../layout/3.php'); ?>


I want to have a few buttons/links (doesn't matter) that changes the order they are displayed in. So the user can pick any way to view the list of guides. Like in alphabetical order, descending order, etc.

The above code actually has nothing to do with it, just tells it when to display it. The below is what you need to look at :

Code: [ Download ] [ Select ]
<h1>Basic HTML Guides</h1>
<div class="content">
<?php
$getdata = mysql_query("SELECT * FROM nav ORDER BY title");

while($r=mysql_fetch_array($getdata)){ //while there are rows in the table
extract($r); //remove the $r so its just $variable

echo '<ul class="select">
<li><a href="' . $url . '"><b>' . $title . '</b></a> (Level: <strong>' . $level . '</strong>)</li>
<li>' . $details . '</li>
<li>Author: <strong>' . $user . '</strong></li>
</ul>';

}
?>
  1. <h1>Basic HTML Guides</h1>
  2. <div class="content">
  3. <?php
  4. $getdata = mysql_query("SELECT * FROM nav ORDER BY title");
  5. while($r=mysql_fetch_array($getdata)){ //while there are rows in the table
  6. extract($r); //remove the $r so its just $variable
  7. echo '<ul class="select">
  8. <li><a href="' . $url . '"><b>' . $title . '</b></a> (Level: <strong>' . $level . '</strong>)</li>
  9. <li>' . $details . '</li>
  10. <li>Author: <strong>' . $user . '</strong></li>
  11. </ul>';
  12. }
  13. ?>


This is what orders it in the first place
Code: [ Download ] [ Select ]
$getdata = mysql_query("SELECT * FROM nav ORDER BY title");


It orders it by title name in alphabetic order, So I want a few links for users to be able to change it. Is there any way this can be done?
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post March 15th, 2008, 1:22 pm

  • Bogey
  • Disturbed
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 7128
  • Loc: Ozzuland
  • Status: Offline

Post March 15th, 2008, 3:52 pm

I don't know about anyone else, but here is the way I would go about it...

Code: [ Download ] [ Select ]
Order by:</br >
<a href="?order=title">Order by title</a>
<a href="?order=author">Order by author</a>
<a href="?order=level">Order by level</a>

<?php
if($_GET['order'] == "title") {
echo '<h1>Basic HTML Guides</h1>';
echo '<div class="content">';

$getdata = mysql_query("SELECT * FROM nav ORDER BY title");

while($r=mysql_fetch_array($getdata)){ //while there are rows in the table
extract($r); //remove the $r so its just $variable

echo '<ul class="select">
<li><a href="' . $url . '"><b>' . $title . '</b></a> (Level: <strong>' . $level . '</strong>)</li>
<li>' . $details . '</li>
<li>Author: <strong>' . $user . '</strong></li>
</ul>';

}

}
if($_GET['order'] == "author") {
echo '<h1>Basic HTML Guides</h1>';
echo '<div class="content">';

$getdata = mysql_query("SELECT * FROM nav ORDER BY user");

while($r=mysql_fetch_array($getdata)){ //while there are rows in the table
extract($r); //remove the $r so its just $variable

echo '<ul class="select">
<li><a href="' . $url . '"><b>' . $title . '</b></a> (Level: <strong>' . $level . '</strong>)</li>
<li>' . $details . '</li>
<li>Author: <strong>' . $user . '</strong></li>
</ul>';

}
}
if($_GET['order'] == "level") {
echo ;<h1>Basic HTML Guides</h1>';
echo '<div class="content">';

$getdata = mysql_query("SELECT * FROM nav ORDER BY level");

while($r=mysql_fetch_array($getdata)){ //while there are rows in the table
extract($r); //remove the $r so its just $variable

echo '<ul class="select">
<li><a href="' . $url . '"><b>' . $title . '</b></a> (Level: <strong>' . $level . '</strong>)</li>
<li>' . $details . '</li>
<li>Author: <strong>' . $user . '</strong></li>
</ul>';

}
}
?>
  1. Order by:</br >
  2. <a href="?order=title">Order by title</a>
  3. <a href="?order=author">Order by author</a>
  4. <a href="?order=level">Order by level</a>
  5. <?php
  6. if($_GET['order'] == "title") {
  7. echo '<h1>Basic HTML Guides</h1>';
  8. echo '<div class="content">';
  9. $getdata = mysql_query("SELECT * FROM nav ORDER BY title");
  10. while($r=mysql_fetch_array($getdata)){ //while there are rows in the table
  11. extract($r); //remove the $r so its just $variable
  12. echo '<ul class="select">
  13. <li><a href="' . $url . '"><b>' . $title . '</b></a> (Level: <strong>' . $level . '</strong>)</li>
  14. <li>' . $details . '</li>
  15. <li>Author: <strong>' . $user . '</strong></li>
  16. </ul>';
  17. }
  18. }
  19. if($_GET['order'] == "author") {
  20. echo '<h1>Basic HTML Guides</h1>';
  21. echo '<div class="content">';
  22. $getdata = mysql_query("SELECT * FROM nav ORDER BY user");
  23. while($r=mysql_fetch_array($getdata)){ //while there are rows in the table
  24. extract($r); //remove the $r so its just $variable
  25. echo '<ul class="select">
  26. <li><a href="' . $url . '"><b>' . $title . '</b></a> (Level: <strong>' . $level . '</strong>)</li>
  27. <li>' . $details . '</li>
  28. <li>Author: <strong>' . $user . '</strong></li>
  29. </ul>';
  30. }
  31. }
  32. if($_GET['order'] == "level") {
  33. echo ;<h1>Basic HTML Guides</h1>';
  34. echo '<div class="content">';
  35. $getdata = mysql_query("SELECT * FROM nav ORDER BY level");
  36. while($r=mysql_fetch_array($getdata)){ //while there are rows in the table
  37. extract($r); //remove the $r so its just $variable
  38. echo '<ul class="select">
  39. <li><a href="' . $url . '"><b>' . $title . '</b></a> (Level: <strong>' . $level . '</strong>)</li>
  40. <li>' . $details . '</li>
  41. <li>Author: <strong>' . $user . '</strong></li>
  42. </ul>';
  43. }
  44. }
  45. ?>


Although that requires a lot of instances of the code. Most likely there is a better solution than this... :lol: I don't even know if this is a solution haha

Anyways, good luck with that...
Learn PHP | I got 10 PHP tutorials! Check them out!
Dreamtale - Farewell
Just a note... I've giving up on web development and that stuff... Just lost all interest in it.

Post March 15th, 2008, 4:09 pm

I'm pretty sure theres a way to do it without having repeated code. But obviously I wouldn't know.
  • Bogey
  • Disturbed
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 7128
  • Loc: Ozzuland
  • Status: Offline

Post March 15th, 2008, 4:32 pm

Here is the ordering for ASCENDING or DESCENDING or RANDOM...

PHP Code: [ Download ] [ Select ]
 "SELECT column_name FROM table_name ORDER BY column_name DESC";
 
"SELECT column_name FROM table_name ORDER BY column_name ASC";
 
"SELECT column_name FROM table_name ORDER BY RAND()";
  1.  "SELECT column_name FROM table_name ORDER BY column_name DESC";
  2.  
  3. "SELECT column_name FROM table_name ORDER BY column_name ASC";
  4.  
  5. "SELECT column_name FROM table_name ORDER BY RAND()";


Just so you know... ASCENDING order is the default.

I think you can use my solution but have only the SELECT scripts in there... something like...

Code: [ Download ] [ Select ]
Order by:</br >
<a href="?order=order1">Order by order1</a>
<a href="?order=order2">Order by order2</a>
<a href="?order=order3">Order by order3</a>

<?php
if($_GET['order'] == "order1") {
"SELECT column_name FROM table_name ORDER BY column_name DESC";
}
if($_GET['order'] == "order2") {
"SELECT column_name FROM table_name ORDER BY column_name ASC";
}
if($_GET['order'] == "order3") {
"SELECT column_name FROM table_name ORDER BY RAND()";
}
//and then your codes here...
?>
  1. Order by:</br >
  2. <a href="?order=order1">Order by order1</a>
  3. <a href="?order=order2">Order by order2</a>
  4. <a href="?order=order3">Order by order3</a>
  5. <?php
  6. if($_GET['order'] == "order1") {
  7. "SELECT column_name FROM table_name ORDER BY column_name DESC";
  8. }
  9. if($_GET['order'] == "order2") {
  10. "SELECT column_name FROM table_name ORDER BY column_name ASC";
  11. }
  12. if($_GET['order'] == "order3") {
  13. "SELECT column_name FROM table_name ORDER BY RAND()";
  14. }
  15. //and then your codes here...
  16. ?>


I'm not sure how this would work out though... Might be worth a try...
Learn PHP | I got 10 PHP tutorials! Check them out!
Dreamtale - Farewell
Just a note... I've giving up on web development and that stuff... Just lost all interest in it.

Post March 15th, 2008, 4:59 pm

I did this:

PHP Code: [ Download ] [ Select ]
<div class="content">
Order by:</br >
<a href="?order=1">Order A-Z</a>
<a href="?order=2">Order Z-A</a>
<a href="?order=3">Order by Author</a>
<?php
if($order<1){
$getdata = mysql_query("SELECT * FROM nav ORDER BY title ASC");
}
if($_GET['order'] == "1") {
$getdata = mysql_query("SELECT * FROM nav ORDER BY title ASC");
}
if($_GET['order'] == "2") {
$getdata = mysql_query("SELECT * FROM nav ORDER BY title DESC");
}
if($_GET['order'] == "3") {
$getdata = mysql_query("SELECT * FROM nav ORDER BY user");
}
 
while($r=mysql_fetch_array($getdata)){ //while there are rows in the table
extract($r); //remove the $r so its just $variable
 
echo '<ul class="select">
<li><a href="' . $url . '"><b>' . $title . '</b></a> (Level: <strong>' . $level . '</strong>)</li>
<li>' . $details . '</li>
<li>Author: <strong>' . $user . '</strong></li>
</ul>';
 
}
?>
  1. <div class="content">
  2. Order by:</br >
  3. <a href="?order=1">Order A-Z</a>
  4. <a href="?order=2">Order Z-A</a>
  5. <a href="?order=3">Order by Author</a>
  6. <?php
  7. if($order<1){
  8. $getdata = mysql_query("SELECT * FROM nav ORDER BY title ASC");
  9. }
  10. if($_GET['order'] == "1") {
  11. $getdata = mysql_query("SELECT * FROM nav ORDER BY title ASC");
  12. }
  13. if($_GET['order'] == "2") {
  14. $getdata = mysql_query("SELECT * FROM nav ORDER BY title DESC");
  15. }
  16. if($_GET['order'] == "3") {
  17. $getdata = mysql_query("SELECT * FROM nav ORDER BY user");
  18. }
  19.  
  20. while($r=mysql_fetch_array($getdata)){ //while there are rows in the table
  21. extract($r); //remove the $r so its just $variable
  22.  
  23. echo '<ul class="select">
  24. <li><a href="' . $url . '"><b>' . $title . '</b></a> (Level: <strong>' . $level . '</strong>)</li>
  25. <li>' . $details . '</li>
  26. <li>Author: <strong>' . $user . '</strong></li>
  27. </ul>';
  28.  
  29. }
  30. ?>


Would that work out great?
  • Bogey
  • Disturbed
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 7128
  • Loc: Ozzuland
  • Status: Offline

Post March 15th, 2008, 5:03 pm

I think it will... the only way to know is to actually try it ;)

Make sure you got a back-up :roll: Hope that solves your problem...

.. You don't need the following code...
PHP Code: [ Download ] [ Select ]
if($order<1){
$getdata = mysql_query("SELECT * FROM nav ORDER BY title ASC");
}
 
  1. if($order<1){
  2. $getdata = mysql_query("SELECT * FROM nav ORDER BY title ASC");
  3. }
  4.  


I mean you need the $getdata... but you don't need that if statement... it would complicate things.
Learn PHP | I got 10 PHP tutorials! Check them out!
Dreamtale - Farewell
Just a note... I've giving up on web development and that stuff... Just lost all interest in it.

Post March 15th, 2008, 5:05 pm

It works well.

One last question, Is there a way to tell it to only show info from a table with one of the cells lets say called "type" and tell it to only show data with the type "htmlguides" or whatever?


---------------------------
I do need it because if they don't put an order= it won't connect to the database.

Also for the reordering thing, I heard that this way is better:

Code: [ Download ] [ Select ]
if(isset($_GET['order']) && isset($_GET['cat'])) { // for security or whatever you can add in like if isset($_GET['order']) && $_GET['order'] == 'ASC' || $_GET['order'] == 'DESC' and same for cats.

$order = $_GET['order']
$cat = $_GET['cat']

query... order by $cat . $order
}
  1. if(isset($_GET['order']) && isset($_GET['cat'])) { // for security or whatever you can add in like if isset($_GET['order']) && $_GET['order'] == 'ASC' || $_GET['order'] == 'DESC' and same for cats.
  2. $order = $_GET['order']
  3. $cat = $_GET['cat']
  4. query... order by $cat . $order
  5. }


But I have no idea what to do with it.
  • Bogey
  • Disturbed
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 7128
  • Loc: Ozzuland
  • Status: Offline

Post March 15th, 2008, 5:22 pm

Mr Steadfast wrote:
...
I do need it because if they don't put an order= it won't connect to the database.

I don't think you need the "if" statement for the very first one... just live it how it is by default.
Code: [ Download ] [ Select ]
$getdata = mysql_query("SELECT * FROM nav ORDER BY title ASC");


So change...
Code: [ Download ] [ Select ]
if($order<1){
$getdata = mysql_query("SELECT * FROM nav ORDER BY title ASC");
}
  1. if($order<1){
  2. $getdata = mysql_query("SELECT * FROM nav ORDER BY title ASC");
  3. }

to that... might be helpful... Although I don't really understand what you mean by that...
Mr Steadfast wrote:
Also for the reordering thing, I heard that this way is better:

Code: [ Download ] [ Select ]
if(isset($_GET['order']) && isset($_GET['cat'])) { // for security or whatever you can add in like if isset($_GET['order']) && $_GET['order'] == 'ASC' || $_GET['order'] == 'DESC' and same for cats.

$order = $_GET['order']
$cat = $_GET['cat']

query... order by $cat . $order
}
  1. if(isset($_GET['order']) && isset($_GET['cat'])) { // for security or whatever you can add in like if isset($_GET['order']) && $_GET['order'] == 'ASC' || $_GET['order'] == 'DESC' and same for cats.
  2. $order = $_GET['order']
  3. $cat = $_GET['cat']
  4. query... order by $cat . $order
  5. }


But I have no idea what to do with it.

I don't know what to do with that as well :lol:

But that I think of it... you would than have a huge URL that will/might confuse the script... example of the long url would be...

http://www.something.com/in.php?order=cat&order=asc

That would tell you what table to order and if it's ascending (asc) or descending (desc)... but if you want to do it that way, both of those "order"'s in the url can't be the same... so if you really want it to do it that way than the link would look something like...

<a href="?order=title&way=asc">Order titles A-Z</a>

and the php would be...
PHP Code: [ Download ] [ Select ]
if(($_GET['order'] == "title" && $_GET['way'] == "asc") {
$getdata = mysql_query("SELECT * FROM nav ORDER BY title ASC");
}
 
  1. if(($_GET['order'] == "title" && $_GET['way'] == "asc") {
  2. $getdata = mysql_query("SELECT * FROM nav ORDER BY title ASC");
  3. }
  4.  

So on and so forth... That would give a bit more "charge" of ordering the table but could get confusing. I don't see any security differences in it...
Learn PHP | I got 10 PHP tutorials! Check them out!
Dreamtale - Farewell
Just a note... I've giving up on web development and that stuff... Just lost all interest in it.

Post March 15th, 2008, 5:26 pm

It's good enough for me I just wanted to see if you knew what to do with it.

One last question, Is there a way to tell it to only show info from a table with one of the cells lets say called "type" and tell it to only show data with the type "htmlguides" or whatever?
  • Bogey
  • Disturbed
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 7128
  • Loc: Ozzuland
  • Status: Offline

Post March 15th, 2008, 5:30 pm

You mean something like the following?

Code: [ Download ] [ Select ]
$getdata = mysql_query("SELECT * FROM nav WHERE type=\"htmlguides\" ORDER BY title ASC");

I think that is how you do that... anyway... you use the WHERE thing :lol:
Learn PHP | I got 10 PHP tutorials! Check them out!
Dreamtale - Farewell
Just a note... I've giving up on web development and that stuff... Just lost all interest in it.

Post March 15th, 2008, 5:47 pm

Yea that's it, Thanks a lot for all your help!

Just wondering...

Is there a way I can make it searchable. So that someone enters a keyword and it only shows relevant guide links on that page.

Also...

How would I make pages like 10 links per page.
  • Bogey
  • Disturbed
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 7128
  • Loc: Ozzuland
  • Status: Offline

Post March 15th, 2008, 7:02 pm

Mr Steadfast wrote:
Is there a way I can make it searchable. So that someone enters a keyword and it only shows relevant guide links on that page.


That is fairly easy to do. I'll show you how here... You would need to give them the option to search in whichever table they want... something like below...

PHP Code: [ Download ] [ Select ]
<?php
$searchQuiry = $_POST['searchQuiry'];
$searchWhere = $_POST['searchWhere'];
$orderPref = $_POST['orderPref'];
 
if(empty($searchQuiry)) {
echo = 'Your search was empty. Nothing to search';
} else {
$getdata = mysql_query("SELECT * FROM nav WHERE $searchWhere=\"$searchQuiry\" ORDER BY $orderPref");
}
  1. <?php
  2. $searchQuiry = $_POST['searchQuiry'];
  3. $searchWhere = $_POST['searchWhere'];
  4. $orderPref = $_POST['orderPref'];
  5.  
  6. if(empty($searchQuiry)) {
  7. echo = 'Your search was empty. Nothing to search';
  8. } else {
  9. $getdata = mysql_query("SELECT * FROM nav WHERE $searchWhere=\"$searchQuiry\" ORDER BY $orderPref");
  10. }


Something similar to that. Of course the code there is faulty as I don't have a database and time to test it, but I'm sure you would be able to figure that out.

I may be wrong altogether, so if someone knows of the true way... fix me :)

Mr Steadfast wrote:
How would I make pages like 10 links per page.

You are talking about pagination. Just search the web for PHP Pagination and use one that is most suitable for you.

Hope that helped...

Mr Steadfast wrote:
Yea that's it, Thanks a lot for all your help!

Yeah, no problem. Glad I can help :D
Learn PHP | I got 10 PHP tutorials! Check them out!
Dreamtale - Farewell
Just a note... I've giving up on web development and that stuff... Just lost all interest in it.
  • Bogey
  • Disturbed
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 7128
  • Loc: Ozzuland
  • Status: Offline

Post March 15th, 2008, 7:36 pm

Ok, I did a bit of research on it and came up with this simple script for "pagination".

Code: [ Download ] [ Select ]
SELECT column FROM table LIMIT 10 OFFSET 10


So in your terms it would be...
Code: [ Download ] [ Select ]
$getdata = mysql_query("SELECT * FROM nav WHERE $searchWhere=\"$searchQuiry\" ORDER BY $orderPref LIMIT 10 OFFSET 10");


source

Hope that helps :P
Learn PHP | I got 10 PHP tutorials! Check them out!
Dreamtale - Farewell
Just a note... I've giving up on web development and that stuff... Just lost all interest in it.

Post March 15th, 2008, 8:09 pm

Bogey wrote:
Mr Steadfast wrote:
Is there a way I can make it searchable. So that someone enters a keyword and it only shows relevant guide links on that page.


That is fairly easy to do. I'll show you how here... You would need to give them the option to search in whichever table they want... something like below...

PHP Code: [ Download ] [ Select ]
<?php
$searchQuiry = $_POST['searchQuiry'];
$searchWhere = $_POST['searchWhere'];
$orderPref = $_POST['orderPref'];
 
if(empty($searchQuiry)) {
echo = 'Your search was empty. Nothing to search';
} else {
$getdata = mysql_query("SELECT * FROM nav WHERE $searchWhere=\"$searchQuiry\" ORDER BY $orderPref");
}
  1. <?php
  2. $searchQuiry = $_POST['searchQuiry'];
  3. $searchWhere = $_POST['searchWhere'];
  4. $orderPref = $_POST['orderPref'];
  5.  
  6. if(empty($searchQuiry)) {
  7. echo = 'Your search was empty. Nothing to search';
  8. } else {
  9. $getdata = mysql_query("SELECT * FROM nav WHERE $searchWhere=\"$searchQuiry\" ORDER BY $orderPref");
  10. }


Something similar to that. Of course the code there is faulty as I don't have a database and time to test it, but I'm sure you would be able to figure that out.

I may be wrong altogether, so if someone knows of the true way... fix me :)

Mr Steadfast wrote:
How would I make pages like 10 links per page.

You are talking about pagination. Just search the web for PHP Pagination and use one that is most suitable for you.

Hope that helped...

Mr Steadfast wrote:
Yea that's it, Thanks a lot for all your help!

Yeah, no problem. Glad I can help :D


Parse error: syntax error, unexpected '=' in F:\root\guides\html_menu.php on line 32

I'm not too sure what to do with it. Does it matter which page I put it on and where? Doesn't need a input box etc?
  • Bogey
  • Disturbed
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 7128
  • Loc: Ozzuland
  • Status: Offline

Post March 15th, 2008, 9:25 pm

Well, I thought you would make the form yourself but I guess I can create a rough copy of how one would look like.

Code: [ Download ] [ Select ]
<form action="formv.php" method="post">
<div>
Search by:
<select name="orderPref">
<option value="Title ASC">Title Ascending</option>
<option value="Title DESC">Title Descending</option>
<option> value="Author ASC">Author Ascending</option>
<option value="Author DESC">Author Descending</option>
</select><br />
Search for: <input type="text" name="searchQuiry" /><br />
WHERE do you want to search?<br />
<input type="radio" name="searchWhere" value="type">Type<br />
<input type="radio" name="searchWhere" value="other">Other<br />
<input type="radio" name="searchWhere" value="other2">Other2<br />
<input type="submit" name="submit" value="submit"> <input type="reset" name="reset" value="reset" />
</div>
</form>
  1. <form action="formv.php" method="post">
  2. <div>
  3. Search by:
  4. <select name="orderPref">
  5. <option value="Title ASC">Title Ascending</option>
  6. <option value="Title DESC">Title Descending</option>
  7. <option> value="Author ASC">Author Ascending</option>
  8. <option value="Author DESC">Author Descending</option>
  9. </select><br />
  10. Search for: <input type="text" name="searchQuiry" /><br />
  11. WHERE do you want to search?<br />
  12. <input type="radio" name="searchWhere" value="type">Type<br />
  13. <input type="radio" name="searchWhere" value="other">Other<br />
  14. <input type="radio" name="searchWhere" value="other2">Other2<br />
  15. <input type="submit" name="submit" value="submit"> <input type="reset" name="reset" value="reset" />
  16. </div>
  17. </form>

The formv.php (Form Validation) would be something like the following. The SQL quiry could be a bit wrong.
PHP Code: [ Download ] [ Select ]
<?php
$searchQuiry = $_POST['searchQuiry'];
$searchWhere = $_POST['searchWhere'];
$orderPref = $_POST['orderPref'];
 
if(empty($searchQuiry)) {
echo = 'Your search was empty. Nothing to search';
} else {
$getdata = mysql_query("SELECT * FROM nav WHERE $searchWhere='$searchQuiry' ORDER BY $orderPref LIMIT 10 OFFSET 10");
}
  1. <?php
  2. $searchQuiry = $_POST['searchQuiry'];
  3. $searchWhere = $_POST['searchWhere'];
  4. $orderPref = $_POST['orderPref'];
  5.  
  6. if(empty($searchQuiry)) {
  7. echo = 'Your search was empty. Nothing to search';
  8. } else {
  9. $getdata = mysql_query("SELECT * FROM nav WHERE $searchWhere='$searchQuiry' ORDER BY $orderPref LIMIT 10 OFFSET 10");
  10. }


Something like that... You might want to play around with it until you get it right and in working order :). I don't have a database with things in it to test it so I'm giving this to you raw :lol:

Hope that helped you out

Oh, and about that error... what is on line 32?
Learn PHP | I got 10 PHP tutorials! Check them out!
Dreamtale - Farewell
Just a note... I've giving up on web development and that stuff... Just lost all interest in it.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post March 15th, 2008, 9:25 pm

Post Information

  • Total Posts in this topic: 27 posts
  • Users browsing this forum: No registered users and 167 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© Unmelted Enterprises 1998-2009. Driven by phpBB © 2001-2009 phpBB Group.