Jump to content

Display View


nucleardoctor

Recommended Posts

Can anyone show me how I can get a display view working so above all of the informatin but below the banner, theres a drop down box and it will say like Name, Station, MFG Date.. ect. and when someone selects one of those, and clicks on a Go button next to the drop down box, it will display everything according to what you selected in order.  So if I selected Station, then it will show everything with Station 231 first, then after all of them it will show Station 232, or if I do name, it will display all of the names in an aplhabetical order?  Im unsure how to do this... thanks.

 

<html>
<head>
<title>
<?
include "admin_panel_title.php";?>
</title>
</head>
<body bgcolor="#000000" text="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#FF3333" vlink="#FF3333" alink="#FF3333">
<center>
<img src="/newadmin/Administration_Panel_Banner.png"><br>
<h3>Turnout Gear Helmets View</h3>

<?

//include "http://delranfire.org/members/connect.phtml";
include "connect.phtml";

$db="delranfire_org";
$query="select * from togearhelmet order by name desc";

//echo $query;

/* ----------------------------------------------------------------------------------------------------------------------------------------- */
/*
   This is the part I added in.  Javascript isn't able to connect to a MySQL database, so you have to add the delete portion inside the PHP.
   First off, on the first line (the conditional IF statement), I added 2 pieces, first is the ID number of the row you want to delete,
   second is an action command.  Both are passed in the querystring (hence the $_GET).  If either one is blank, then nothing is deleted.
   If the action command is set to the phrase 'del', then it actually deletes the row.

   To access it via the browser, all you would do is link to:  tgearhelmets.phtml?id=1&action=del (changing the ID value to whatever).

   If you have any questions or it doesn't work like you wanted, just IM me or email me (jpontani@gmail.com) if I'm not on AIM.
*/

if(isset($_GET['id']) && isset($_GET['action'])) {  // make sure both parameters exist and have a value before trying to act on them
$tempResult = mysql_db_query($db, "SELECT * FROM togearhelmet WHERE id=" . mysql_escape_string($_GET['id']), $connection);
if(mysql_num_rows($tempResult) > 0) {  // make sure that the item you want to delete is still in the database
	if($_GET['action'] == "del") {  // if the action command is anything else, it will not delete the item
		mysql_db_query($db, "DELETE FROM togearhelmet WHERE id=" . mysql_escape_string($_GET['id']), $connection);
	}
}
}

/* ----------------------------------------------------------------------------------------------------------------------------------------- */



$rows=mysql_db_query($db,$query,$connection) or die("Error in query:$query. " .mysql_error());



?>

<script language=javascript>




/* ----------------------------------------------------------------------------------------------------------------------------------------- */
// I also changed this function around.  Your original was mixing up Javascript and PHP to try to delete the entry.  This way it only 
// uses the PHP side to delete the entry, and all the Javascript is doing is redirecting to the delete action of the page.
function deleteEntry(entry) {
location.href = "tgearhelmets.phtml?id=" + entry + "&action=del";
}
/* ----------------------------------------------------------------------------------------------------------------------------------------- */




function deleteEntryOld(entry)
{

var moo = '\"DELETE FROM togearhelmet WHERE id=\'' + entry + '\'\"';

<?
$qu = "?><script language=javascript>document.write(moo)</script><?";

mysql_query($qu);
?>

var sURL = unescape(window.location.pathname);
window.location.href = sURL;

}

</script> </font>

                              <table width="98%" border="0" cellspacing="0" cellpadding="0" align=center>

<tr>

                                <td> <b><font face="Arial, Helvetica, sans-serif" size="1">Name</font></b></td>

                                <td> <b><font face="Arial, Helvetica, sans-serif" size="1">ID</font></b></td>

                                <td> <b><font face="Arial, Helvetica, sans-serif" size="1">Station</font></b></td>

                                <td> <b><font face="Arial, Helvetica, sans-serif" size="1">Type</font></b></td>

                                <td> <b><font face="Arial, Helvetica, sans-serif" size="1">Model</font></b></td>

                                <td> <b><font face="Arial, Helvetica, sans-serif" size="1">Color</font></b></td>

                                <td> <b><font face="Arial, Helvetica, sans-serif" size="1">Ear Flap</font></b></td>

                                <td> <b><font face="Arial, Helvetica, sans-serif" size="1">Liner</font></b></td>

                                <td> <b><font face="Arial, Helvetica, sans-serif" size="1">Chinstrap</font></b></td>

                    	  <td> <b><font face="Arial, Helvetica, sans-serif" size="1">Mfg. Date</font></b></td>

                                <tr>

                                <tr><td colspan=11><hr></td></tr>

                                <?

while($row=mysql_fetch_array($rows)){

?>


                                <td><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFFFF">

                                <?

                                $name="$row[name]";



                                echo $row["name"];?>



                                </font></td>

                                 <td><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFFFF">

                                <?echo $row["id"];?>

                                </font></td>

                                 <td><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFFFF">

                                <?echo $row["station"];?>

                                </font></td>

                                <td><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFFFF">

                                <?echo $row["htype"];?>

                                </font></td>

		        <td><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFFFF">

                                <?echo $row["hmodel"];?>

                                </font></td>

                                <td><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFFFF">

                                <?echo $row["hcolor"];?>

                                </font></td>

                                <td ><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFFFF">

                                <?echo $row["hflap"];?>

                                </font></td>

				  <td ><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFFFF">

                                <?echo $row["hliner"];?>

                                </font></td>

				  <td ><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFFFF">

                                <?echo $row["hstrap"];?>

                                </font></td>

				  <td ><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFFFF">

                                <?echo $row["hdatem"];?> - <?echo $row["hdated"];?> - <?echo $row["hdatey"];?>

                                 <tr><td colspan=11><hr></td></tr>

                                <?}?>


                              </table>

                              </td>

                          </tr>

                        </table>

                      </td>

                    </tr>

                  </table>

                </td>

              </tr>

            </table>
<center><a href="/newadmin/">Back to Administration Panel</a></center>
</body></html>
  <?
  mysql_close();
  ?>

Link to comment
Share on other sites

If I've got you correctly:

 

use GET or POST & SESSION to track the dropdown item, e.g.

 

If form has been posted, i.e.

 

<?
if ($_POST['themes']) {
        $_SESSION['theme']=POST['theme']
}
?>

 

the form itself has e.g.

 

<form action="/greetingscards.php" method="post" name = "themes" id="themes">
<table width="90%">
	<tr width="100%">Theme</tr>
	<tr>
		<td width="50px">
                             <select name="theme" id="theme1">
			<option value="all"<?php if($_SESSION['theme'] == "all") { echo ' selected="selected"'; } ?>>All</option>
			<option value="animal"<?php if($_SESSION['theme'] == "animal") { echo ' selected="selected"'; } ?>>Animal</option>
			<option value="floral"<?php if($_SESSION['theme'] == "floral") { echo ' selected="selected"'; } ?>>Floral</option>
			<option value="leisure"<?php if($_SESSION['theme'] == "leisure") { echo ' selected="selected"'; } ?>>Leisure</option>
			<option value="travel"<?php if($_SESSION['theme'] == "travel") { echo ' selected="selected"'; } ?>>Travel</option>
		   </select>
                       </td>
		<td><input type="submit" name="submit3" value="Find cards!" /></td>
	</tr>
</table>
</form>

 

(all that extra PHP just keeps the selection selected between pages)

 

Then your PHP code which sets the SQL simply has an IF stmt, e.g.

 

if ($_SESSION['themes'] = 'animal') {

  $query="blah blah order by xyz asc";

} elseif ($_SESSION['themes']='floral') {

  $query="blah order by abc asc";

}

 

Sorry I've written this off the top of my head but hope you get the basic idea. Basically put the dropdown selection into a session variable (assuming you want to keep it between pages, and don't forget the session_start() declaration at the top of each page), and then alter your SQL according to that variable value.

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.