Jump to content

Select data from mysql database based on get variables.


Alex1646

Recommended Posts

Not sure why this isnt working.

<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script>
<script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);</script>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


<LINK REL=StyleSheet HREF="inc/dyn_style.css" TYPE="text/css" MEDIA=screen />
<?php

?>
<?php include('logic.inc'); mysqlConnect(); ?>
<script type="text/javascript" src="bbeditor/ed.js"></script>
<link rel="stylesheet" type="text/css" href="dyn_style.css" />
<title>
Social
</title>
<script type="text/javascript">
function changeTitle(title) 
{
 document.title = title; 
}
</script>

</head>

<body>
<?php
$inc = 'new_story.php';
$view = 'Newest ';
$by = 'added';
$where = " ";
$where2 = " ";
$order = "ASC"; 
$gen = "All";
$rat = 'All';
$blerg = "";
$sort = 'newest';
//----------------------------------------------------------------------
if(isset($_GET['sub']))
{
$sort = $_GET['sort'];
switch($sort)
{
case "Most Popular";
$by = 'views';
$view = 'Most Popular ';	
$order = 'DESC';
break;
case "Most Reviewed";
$view= 'Most Reviewed  ';
$by = 'reviews';
$order = 'DESC';
break;
case "Newest";
$by = 'added';
$view = 'Newest';
$order = 'ASC';
break;
}

$genre = mysql_real_escape_string($_GET['cat']);
$rating = mysql_real_escape_string($_GET['rat']);
if($gen ==  'All')
{
$where = " ";
$blerg = "";
}
else
{
$where = "WHERE cat='$gen'";
}
if ($rat == "All")
{
$where2 = ' ';
$blerg = 'AND';

}
else 
{
$where2 = $blerg ."
rating = '$rat'
";	
}
}
//----------------------------------------------------------------------


?>
<?php serch(); ?>
<form action="story.php" method="get">
<label id='inline'> Order By: </label>
<select name='sort'>
<option selected='yes' label='Currently Selected' > <?php echo $view;  ?> </option>
<option> Newest   </option>
<option> Most Popular</option>
<option>  Most Reviewed </option>
</select>
<input type='hidden' value='spec_view' name='p' />
<label id='inline'> Genre/Catagory:  </label>
<select name='gen'>
<option selected='yes' label = 'Selected Genre - <?php echo $gen; ?>'> <?php echo $gen; ?> </option>
<option> All </option>
<option> Fantasy </option>
<option> Adventure </option>
<option> Science Fiction</option>
<option> Drama</option>
<option> Fable </option>
<option> Horror</option>
<option> Humor</option>
<option> Realistic Fiction </option>
<option> Tall Tale</option>
<option> Mystery  </option>
<option> Mythology  </option>
<option> Poetry  </option>
<option> Shorty Story </option>
<option> Romance </option>

</select>
<label id='inline'> Rating: </label>
<select name='rat'>
<option selected='yes' label = "Selected Genre - <?php echo $rat; ?>"> <?php echo $gen; ?> </option>  
<option> All </option>
<option> C </option>
<option> C13 </option>
<option> YA </option>
<option> A </option>

</select>

<input type='submit' value='Go!'  name = 'go' />
</form>
<?php

$query = "
SELECT * FROM story_info
ORDER BY $by $order 
$where
$where2
";	
echo $query;
$select = mysql_query($query) or die(mysql_error());

while($rows = mysql_fetch_assoc($select))
{
$viewsdb = $rows['views'];
$titledb = $rows['title'];
$userdb = $rows['user'];
$catdb = $rows['cat'];
$ratdb = $rows['rating'];
$id_db = $rows['story_id'];
$sumdb = shorten($rows['sum']);
echo "<h3><a href='?p=page&id=$id_db'> $titledb </a>   </h3>";
echo "<div id='fun_info'>";
echo "$sumdb <br />";
echo "By <a href='?p=profile&user=$userdb'> $userdb </a> <br /> ";
echo "$viewsdb Views | Rated: $ratdb | Catagory: <a href='?p=cat_view&gen=$catdb'> $catdb </a>  </div>";
}
?>
</div>

</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.