web designer Posted August 2, 2006 Share Posted August 2, 2006 [color=brown]Hello :)I have two files.. form.php - query.php[b]form.php[/b][/color][code] <form action="http://localhost/queries/query.php" method="post" name="form"> Searching for players which play these games... <br /> <br /> <input name="football" type="checkbox" value="x">Football <br /> <input name="basketball" type="checkbox" value="x">Basketball <br /> <br /> <input name="reset" type="reset" value="Reset"/> <input name="submit" type="submit" value="Submit"/> </form>[/code][color=brown][b]query.php[/b][/color][code]<?php$page=$_GET["page"];if(!isset($page)){ $page=1; $pageNo = $page +1;}$pageNo = $page;echo "Page Number: <b>$pageNo</b>";$page=$page-1;//connecting to my database.. and for sure it's working..(hidden for now)//....//....//....$football = $_POST['football'];$basketball = $_POST['basketball'];$preQuery="select * from Macrofossiles where (football = '$football') || (basketball= '$basketball')";$preResult=mysql_query($preQuery,$server) or die("Could not execute preQuery...");$numRows=mysql_num_rows($preResult);$numPages=$numRows/1;$query = "select * from Macrofossiles where (football = '$football') || (basketball= '$basketball') limit $page, 1"; $result = mysql_query($query,$server) or die("Could not execute query..."); while($row = mysql_fetch_array($result)){ echo '<table bordercolor="#CC7722" align="center">' . "<tr><td>Player Number:</td><td>{$row['Player_No']}</td></tr>" . "<tr><td>Hockey:</td><td>{$row['Hockey']}</td></tr>" . "<tr><td>Volleyball:</td><td>{$row['volleyball']}</td></tr>" . "<tr><td>Tennis:</td><td>{$row['tennis']}</td></tr>" . "<tr><td>Football:</td><td>{$row['football']}</td></tr>" . "<tr><td>Basketball:</td><td>{$row['Basketball']}</td></tr>" . "</table>";} echo "<b>Page:</b>  "; $num=1; for($i=1;$i<$numPages;$i++) { if($num==$pageNo) { $font="<b>"; $unfont="</b>"; } else { $font=""; $unfont=""; } echo "<a href='query.php?page=$num'>$font $num $unfont</a> "; $num = $num + 1; } mysql_close($server); ?>[/code][color=brown][b]Database:[/b]| Player_No | Hockey | Volleyball | Tennis | Football | basketball || 1 | x | x | | x | || 2 | | x | x | | x || 3 | x | | x | x | || 4 | | x | x | | x || 5 | x | x | | x | x || 6 | x | x | | x | || 7 | | x | x | | x || 8 | x | | x | x | || 9 | | x | x | | x | . . . etcI hope someone can help..Oops.. I didn't tell you guys what is the problem I'm sufferring from in these codes..here is it.. when I check the two checkboxes... and click submit.. the query.php open and everything seems okey.. the results are perfect.. and exact.. but !! .. when I click page number 2 or 3 or any number after the first click, everything is changed !! .. it geves me the result of this query "select * from Macrofossiles where (football = '') || (basketball= '')" I mean it gives me the result when football is empty and basketball is empty.. that means this query-->"select * from Macrofossiles" all the resutls will show up .. :(it seems to me that I need to write sessions.. but how that will ! .. what should I write and where in my code !!any help ! ::) :D[/color] Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 2, 2006 Share Posted August 2, 2006 SO your using sessions?Do you have session_start();on line 1 of your code? Quote Link to comment Share on other sites More sharing options...
web designer Posted August 2, 2006 Author Share Posted August 2, 2006 [color=brown]I just started adding the session stuff.. ;Dnow.. I have this code in both files.. the form and the query.. [b]<?phpsession_start();..............................etc[/b]but I got an error.. in my two files.. Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Documents and Settings\Work Station\Desktop\wamp\www\WebSite\forms\form1.php:[b]9[/b]) in C:\Documents and Settings\Work Station\Desktop\wamp\www\WebSite\forms\form1.php on line [b]61[/b]on line 9 there is a usual meta tagon line 61 there is session_start();so ! what is the problem !![/color] Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 2, 2006 Share Posted August 2, 2006 session_start() needs to be on line 1Before <html>As it sends html headersand should only be on line 1, not duplicated Quote Link to comment Share on other sites More sharing options...
web designer Posted August 2, 2006 Author Share Posted August 2, 2006 [color=brown]Oh I really appreciate your help.. thanks alot.. now.. what about the [u]variables[/u] !! ?[b]can I do this:[/b]form.php[/color][code]...etc<input name="<?php $ostracodes='ostracodes'; ?>" type="checkbox" value="x">Ostracodes<input name="<?php $indetermine='indetermine'; ?>" type="checkbox" value="x">Indetermine...etc</form><?php$_SESSION['ostracodes'] = $ostracodes;$_SESSION['indetermine'] = $indetermine;?>[/code] Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 2, 2006 Share Posted August 2, 2006 wha, no<input type='checkbox' name='Ostracodes' value='x'>Ostracodesthenif($_POST["Ostracodes"] == "x"){$_SESSION["ostracodes"] = "x";} Quote Link to comment Share on other sites More sharing options...
web designer Posted August 2, 2006 Author Share Posted August 2, 2006 [color=brown]Okay :)I wrote in my form.php[/color][code]............etc<input name="ostracodes" type="checkbox" value="x">Ostracodes<br /><input name="indéterminé" type="checkbox" value="x">Indéterminé<br /><br /><input name="reset" type="reset" value="Reset"/><input name="submit" type="submit" value="Submit"/> </form><?phpif($_POST['ostracodes'] == 'x') $_SESSION['ostracodes'] = x;if($_POST['indetermine'] == 'x') $_SESSION['indetermine'] = x;?>............etc[/code][color=brown]now ! .. in my query.phpshould I do this:[/color][code]<?php............etc$ostracodes = $_SESSION['ostracodes'];$indetermine = $_SESSION['indetermine'];$preQuery="select * from Macrofossiles where (ostracodes = '$ostracodes') || (indetermine = '$indetermine')";............etc?>[/code] Quote Link to comment Share on other sites More sharing options...
web designer Posted August 2, 2006 Author Share Posted August 2, 2006 [color=brown][b]I figured out that I should write these[/b][/color][code]<?phpif($_POST['ostracodes'] == 'x') $_SESSION['ostracodes'] = x;if($_POST['indetermine'] == 'x') $_SESSION['indetermine'] = x;?>[/code][color=brown][b]in my query.php not my form.php[/b][/color]I wrote them in this way:[code]<?phpif(isset ($_POST['ostracodes'])) {$_SESSION['ostracodes'] = x;} if(isset ($_POST['indetermine'])) {$_SESSION['indetermine'] = x;}?>[/code] Quote Link to comment Share on other sites More sharing options...
web designer Posted August 2, 2006 Author Share Posted August 2, 2006 [color=brown]but still ! .. should I write these lines of code in my query.php ??[/color][code]<?php............etc$ostracodes = $_SESSION['ostracodes'];$indetermine = $_SESSION['indetermine'];$preQuery="select * from Macrofossiles where (ostracodes = '$ostracodes') || (indetermine = '$indetermine')";............etc?>[/code] Quote Link to comment Share on other sites More sharing options...
web designer Posted August 3, 2006 Author Share Posted August 3, 2006 [color=brown]as I'm taking info from my database and showing it in many pages..is it right to do this.. for passing variables to the another page ?[/color][code]<?php$num=1; for($i=1;$i<$numPages;$i++){ if($num==$pageNo) { $font="<b>"; $unfont="</b>"; } else { $font=""; $unfont=""; }echo "<a href='query1.php?page=$num&tennis=$_SESSION['tennis']&basketball=$_SESSION['basketball']'>$font $num $unfont</a> "; $num = $num + 1;} ?>[/code][color=brown]My question is mostly for this part ( sessions )[/color][code]<?phpecho "<a href='query1.php?page=$num&tennis=$_SESSION['tennis']&basketball=$_SESSION['basketball']'>$font $num $unfont</a> ";?>[/code] Quote Link to comment Share on other sites More sharing options...
web designer Posted August 3, 2006 Author Share Posted August 3, 2006 [color=brown]Oh :( I think what I have written above is wrong :-\please can any one help ? :-[I don't know why is the session not working !! [/color] Quote Link to comment Share on other sites More sharing options...
dottedquad Posted August 3, 2006 Share Posted August 3, 2006 [quote author=web designer link=topic=102700.msg408968#msg408968 date=1154621544][color=brown]Oh :( I think what I have written above is wrong :-\please can any one help ? :-[I don't know why is the session not working !! [/color] [/quote]try reading the sessions in the FAQ: http://www.phpfreaks.com/forums/index.php/topic,31047.0.html Quote Link to comment Share on other sites More sharing options...
HeyRay2 Posted August 3, 2006 Share Posted August 3, 2006 If you set your variables in a session, you don't need to pass them in a URL as well.Instead of trying to get your variable from $_POST, then assigning them to $_SESSION, followed by moving them to $_GET, just change your search form to use the $_GET method and keep it that way, like so:[b]form.php[/b][code=php:0]<form action="http://localhost/queries/query.php" method="GET" name="form"> Searching for players which play these games... <br /> <br /> <input name="football" type="checkbox" value="x">Football <br /> <input name="basketball" type="checkbox" value="x">Basketball <br /> <br /> <input name="reset" type="reset" value="Reset"/> <input name="submit" type="submit" value="Submit"/> </form>[/code][b]query.php[/b][code=php:0]<?php$page=$_GET["page"];if(!isset($page)){ $page=1; $pageNo = $page +1;}$pageNo = $page;echo "Page Number: <b>$pageNo</b>";$page=$page-1;//connecting to my database.. and for sure it's working..(hidden for now)//....//....//....$football = $_GET['football'];$basketball = $_GET['basketball'];// YOUR QUERIES AND RESULT PRINTING......// YOUR URL TO THE NEXT PAGE OF RESULTSecho "<a href='query.php?page=$pageNo&football=$football&basketball=$basketball'>$font $num $unfont</a> ";// YOUR MySQL SESSION CLOSING, ETC.........?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.