Forums
This topic is locked
help with my first manual php'ing
Posted 12 Apr 2006 22:01:22
1
has voted
12 Apr 2006 22:01:22 Patrick Caruana posted:
hi - i am new to the whole concept of datadriven webpages - been using dreamweaver to do all the work for me <img src=../images/dmxzone/forum/icon_smile_tongue.gif border=0 align=middle> - i have read a tutorial on the sql syntax and on php and am now trying one of my first "custom" scripting <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle> There is probably a very obvious solution that i thought you php savvy people might be able to lend a hand in finding <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>the page basically takes all the records from a table and lists them in an html table - i am now trying to make my own "sort by" list box thingy at the top of the page using what i have learned in php. at the top of the page i have :
<?php require_once('../Connections/test.php'); ?> // dreamweaver's code
<?php //my code
if ($_POST) {
$sortby = " ORDER BY " . $_POST['SELECT'];
} else{
$sortby = "";
} //my code
basically i want to use the $sortby variable and insert that into dreamweaver's code as shown below:
$query_Recordset1 = "SELECT *, producttype.typename FROM products, producttype WHERE products.productTYPE=producttype.TypeID" . $sortby; <---- MY SORTBY VARIABLE
$Recordset1 = mysql_query($query_Recordset1, $test) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
the form used to get that variable is in the body of that same page and is:
<form method="post" action="editprod.php"> <----is the link of this page
<label>
<select name="select" size="1">
<option value="ProductPRICE">Price</option>
<option value="ProductMODEL">Model</option>
</select>
</label>
<label>
<input type="submit" value="Sort" />
</label>
</form>
so basically my logic here is that at the beginning of the page it checks to see whether or not that page has been loaded after the "sort" button having been pressed. IF it hasnt, it sets $sortby variable to nothing and therefore should not alter the sql query. If the page has been loaded as a result of the sort button in the form being pressed then it takes the value from the form ("select", adds the sql syntax ORDER BY and sets that to the $sortby variable therefore altering the query and the way the page loads <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
there is probably a more "proper" logic for doing this however this is literally my first php handcoding - only problem is that it doesnt work! for some reason when i load the same thing into a blank page not using sql and echo the $_POST['SELECT'] after pressing the button it doesnt print anything - that has to be where the error is coming from tho according to all the "forms & php" tutorials i think that is the right way of acquiring the data from the form - any help would be GREATLY appreciated
thanks,
patrick
Edited by - da_bomb on 12 Apr 2006 22:03:00
Replies
Replied 13 Apr 2006 00:36:20
13 Apr 2006 00:36:20 Patrick Caruana replied:
omg lol i sorted the error - it was a problem with the cases............ i had "SELECT" instead of "select" in the $_POST[SELECT] bit <img src=../images/dmxzone/forum/icon_smile_tongue.gif border=0 align=middle>