Jump to content

astani

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Everything posted by astani

  1. It works you are the best. I tried it the second way without the onclick.
  2. Thanks I'll give it a try and see what happens.
  3. I tried this code and I get results and the links but I don't get the result on clicking individual links; <?php $alph_array = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","R","T","S","U","V","X","Y","Z" ); foreach($alph_array as $var) { echo "<a href='".$var."'>".$var."</a> "; } for($u = 0; $u < count($alph_array); $u++) { if (($title[0]) == ($alph_array[$u])) { ?> <a name = "<? echo $alph_array[$u];?>" <? $sorted_titles = pg_query("SELECT * FROM projects WHERE title LIKE '$alph_array[$u]'%'");?> onClick =" <? echo (pg_fetch_array($sorted_titles)) ?>"></a><? } } ?>
  4. Thanks again I'll give it a try and see what happens.
  5. Your code works!! Thanks, now if I can just figure out how to display it alphabetized by project titles....
  6. One more thing, how would I make the output get displayed by the letters of the alphabet as links.. I have the array to display the alphabet thus far but I don't know how to proceed: <?php $alph_array = array("A" => "A", "B"=>"B", "C" => "C", "D" =>"D", "E"=>"E","F"=>"F", "G"=>"G", "H"=>"H", "I"=>"I","J"=>"J", "K"=>"K","L"=>"L","M"=>"M","N"=>"N","O"=>"O","P"=>"P","Q"=>"Q","R"=>"R","S"=>"S","T"=>"T","U"=>"U","V"=>"V","W"=>"W","X"=>"X","Y"=>"Y","Z"=>"Z" ); $alph_array; foreach ($alph_array as $value) { print_r("$value \n\n\n");} ?>
  7. I'll give it a try and let you know, thanks.
  8. Still not working the way it should. The only way it works is if I do a query before the if statement which it seems to defeat the purpose. I am using php 4.3.9 on the server. <html> //html dropdown with submit form (button) connects to php page below it: <form action ="" name = "sorting"> <select name ="sorting"> <option value="0" input name="byname" >By Name</option> <option value="1" input name ="byowner">By Owner</option> </select> </form> <form id="sort1" action="sort1.php" method="post" name= "sort"> <input type="hidden" name="id1" value = "sub" /> <input name ="submit1" input type="submit" id="submit" value ="submit"/> </form> </html> <?php //conditional with queries based on dropdown choice by user if($form_input['submit1'] == 0) { $sort_query = pg_query("SELECT * FROM projects ORDER BY title"); } elseif($form_input['submit1'] == 1) { $sort_query = pg_query("SELECT * FROM projects ORDER BY username"); } //looping thru to get the records displayed while (($row = pg_fetch_array($sort_query)) && ($row != "")) { for ($i = 0; $i <= 1; $i++) { echo $row[$i] ?><br> <? ; //echo $row1[$i] //print "<pre>"; var_dump($projByTitle); print "</pre>"; } } ?>
  9. Thanks I will give it a try and let you know how it works.
  10. Here is the html code: <html> <form> <select name="Sort" > <option value="0" selected = "selected">By Name</option> <option value="1" >By Owner</option> </select> <form id="sort1" action="sort1.php" method="post" name= "sort"> <input type="hidden" name="id" value="<? echo '<OPTION value='.$value.'> '.$value.'' ?>" /> <input type="submit" id="submit" name="submit" value ="submit"/> </form> </html> That's not a valid name for a request. Look how many single quotes you have. You're giving it an HTML option input name. What are you trying to pass through? Could you post the code where you're trying to get your values from?
  11. This code gives me an error on the first line. I am trying to pass in an html option value from the html dropdown box. Help please... if ($_REQUEST['<'OPTION value=.$value.&gt] == "0") { $sort_query = pg_query("SELECT * FROM projects ORDER BY title"); $projByTitle = pg_fetch_array($sort_query); } else { $sort_query = pg_query("SELECT * FROM projects ORDER BY username"); $projByOwner = pg_fetch_array($sort_query); }
  12. How do I use an if statement to output different queries once I submit the chosen option? <select name="Sort"> <option value= "Title">By Title</option> <option value="Owner" selected="selected">By Owner</option> </select>
  13. My dropdown works fine I need a way to use an if statement and "selectedindex" in the dropdown to output different queries. Below is code for Dropdown followed by html submit form: //create php dropdown with two sort options $sortBy = array( 1=> "Project Name", 2=> "Owner", ); $category = str_replace(" ", " ", $sortBy); echo '<SELECT name=category>'; foreach ($sortBy as $key => $value) { echo '<OPTION value='.$value.'> '.$value.''; } echo '</select>'; ?> <?php //print "<pre>"; var_dump($projByTitle); print "</pre>"; ?> <!--create html form to execute queries on sort.php on clicking the submit button--> <form id="sort" action="sort1.php" method="post" name= "sort"> <input type="hidden" name="id" value="<? echo "$form_input[title]";?>" /> <input type="submit" id="submit" name="submit" value ="submit"/> <?
  14. My dropdown works fine I need a way to use an if statement and "selectedindex" in the dropdown to output different queries.
  15. I need some help please, how can I make my php dropdown output different results on submit? Is there a selectedindex value and how can I use it? <?php $sortBy = array( 1=> "Project Name", 2=> "Owner", ); $category = str_replace(" ", " ", $sortBy); echo '<SELECT name=category>'; foreach ($sortBy as $key => $value) { echo '<OPTION value='.$value.'> '.$value.''; } echo '</select>'; ?>
  16. Hi, I have a php planning (project) based site connected to a postgreSQL db working with Dreamweaver 8. I want to be able to sort the projects by project name or owner, by clicking on a dropdown and submitting. I still need an if statement somewhere to determine which queries will be called based on the dropdown selection. Help. Main page (projects page) - this is where I create the php dropdown and the html submit form to call the sort.php page with the queries: //create php dropdown with two sort options $sortBy = array( 1=> "Project Name", 2=> "Owner", ); $category = str_replace(" ", " ", $sortBy); echo '<SELECT name=category>'; foreach ($sortBy as $key => $value) { echo '<OPTION value='.$value.'> '.$value.''; } echo '</select>'; ?> <?php //print "<pre>"; var_dump($projByTitle); print "</pre>"; ?> <!--create html form to execute queries on sort.php on clicking the submit button--> [/color] <form id="sort" action="sort.php" method="post" name= "sort"> <input type="hidden" name="id" value="<? echo "$form_input[title]";?>" /> <input type="submit" id="submit" name="submit" value ="submit"/> <? ?> </form> <? ?> On clicking submit button I call this code on sort.php queries: <?php include "header.php"; if($_SERVER['REQUEST_METHOD'] == "POST"){$form_input = $_POST;}elseif($_SERVER['REQUEST_METHOD'] == "GET"){$form_input = $_GET;}else{exit;} $sort_query = pg_query("SELECT * FROM projects ORDER BY title"); $projByTitle = pg_fetch_array($sort_query); $sort_query1 = pg_query("SELECT * FROM projects ORDER BY username"); $projByOwner = pg_fetch_array($sort_query1); ?> <? while (($row = pg_fetch_array($sort_query)) && $row1 = pg_fetch_array($sort_query1)) { for ($i = 0; $i <= 1; $i++) { echo $row[$i] ?><br> <? ; echo $row1[$i] ?><br> <? ; //print "<pre>"; var_dump($projByTitle); print "</pre>"; } } ?> I am attaching the sort.php file. [attachment deleted by admin]
  17. astani

    php sorting

    Thanks for your help thus far, I will try option one and see how it goes.
  18. astani

    php sorting

    I am trying to sort and display results by project title or by owner (depending to what the user indicates in the dropdown).
  19. astani

    php sorting

    I was mixing in html and javascript I think, sorry for the confusion. I am a bit confused myself.
  20. Hi, I am a php newbe I have a Posgresql db and am trying to do a sort routine based on project titles or project owners. I have an html dropdown for this. I have an array that displays the letters of the alphabet and would like to be able to pick from the dropdown and populate the names of projects alphabetically or names of projects by creator. Here is what I have so far, the queries don't seem to work or maybe just not displaying, any help would be apreciated. <h4 align="left">Sort By: </h4> <form name="jump"> <p align="left"> <select name="menu"> <option value="URL"> Project Name</option> <option value="URL"> Owner</option> </select> <?php $sort_query = pg_query("SELECT * FROM projects ORDER BY title"); $projByTitle = pg_fetch_array($sort_query); $sort_query1 = pg_query("SELECT * FROM users ORDER BY username"); $projByOwner = pg_fetch_array($sort_query1); ?> <input type="button" name="<?php if (jump.menu.selectedIndex == "0") { echo "$projByTitle"; } else { echo "$projByOwner"; } ?> " method = "post" value="GO"> Thanks, Andy
  21. astani

    php sorting

    Hi, I am a php newbe I have a Posgresql db and am trying to do a sort routine based on project titles or project owners. I have an html dropdown for this. I have an array that displays the letters of the alphabet and would like to be able to pick from the dropdown and populate the names of projects alphabetically or names of projects by creator. Here is what I have so far, the queries don't seem to work or maybe just not displaying, any help would be apreciated. <h4 align="left">Sort By: </h4> <form name="jump"> <p align="left"> <select name="menu"> <option value="URL"> Project Name</option> <option value="URL"> Owner</option> </select> <?php $sort_query = pg_query("SELECT * FROM projects ORDER BY title"); $projByTitle = pg_fetch_array($sort_query); $sort_query1 = pg_query("SELECT * FROM users ORDER BY username"); $projByOwner = pg_fetch_array($sort_query1); ?> <input type="button" name="<?php if (jump.menu.selectedIndex == "0") { echo "$projByTitle"; } else { echo "$projByOwner"; } ?> " method = "post" value="GO">
×
×
  • 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.