OLM3CA Posted September 17, 2006 Share Posted September 17, 2006 Hello;I have a search form in my index.php, When the form submitted,I include search.php.The search results are shown ten by ten with paging like 1 2 3 4 ... but while paging results when I click on the other pages The page shows nothing returns to the page that no search keyword is entered.I think the problem is in other pages POST keyword is not taken by page ?[u]search.php[/u][code]$m = ($_REQUEST['m']); if ( ! $m) { $m = "0"; }$result = mysql_query("SELECT * FROM tablexWHERE area1 LIKE '%".$_POST['keyword']."%'AND status='1' order by linkid DESCLIMIT $m,10");$queri = mysql_query("SELECT * FROM tablex WHERE area1 LIKE '%".$_POST['keyword']."%' AND status='1'");$totalrow=mysql_num_rows($queri);if($_POST['keyword']) { while($r=mysql_fetch_array($result)) {$i=0; while ( $i < $totalrow ) { $a = $a + 1;echo "<a href='index.php?page=search&m=$i'>$a</a>";$i = $i + 10; } echo $r['name']; echo $r['web']; echo $r['number'];}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/ Share on other sites More sharing options...
onlyican Posted September 17, 2006 Share Posted September 17, 2006 You want to use the GET method to parse the dataThis parses the data in the address bar Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93493 Share on other sites More sharing options...
OLM3CA Posted September 17, 2006 Author Share Posted September 17, 2006 ok but what would I write to here :[code]echo "<a href='index.php?page=search&m=$i'>$a</a>";[/code]becouse its seems like index.php?kelime=... Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93518 Share on other sites More sharing options...
redarrow Posted September 17, 2006 Share Posted September 17, 2006 Please look at my code for paginton to see the diffrence between mine and yours and also look at the way the links are setup at the bottom good luck.[code]<?phpif(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 3; $from = (($page * $max_results) - $max_results); $query="select * from member_comments where date_added='".$record['date_added']."' and time_added='".$record['time_added']."' LIMIT $from, $max_results";$result=mysql_query($query);while($data=mysql_fetch_assoc($result)){$comment=$data['comment'];$comment=wordwrap($comment,63,"<br>",1);$title=$data['title'];$title = substr($title,0,45);?><html><title>blogs</title><body><table align="center" bordercolor="black" border="4" width="500" height="25"><td width="25%" align="center"><b><font color="red"><b>User comment</font></b><br></b></td><td align="center" valign="top"><b><font color="red">Title</font></b><br><b><? echo $title;?></b></td></table><table align="center" bordercolor="black" border="4" width="500" height="100"><td align="center" valign="top"><b><font color="red">Description</font></b><br><div align="left"><b><?echo $comment;?></b></div></td></table><table align="center" bordercolor="black" border="4" width="500" height="20"><td width="25%" align="center"><b>fff</b></td><td width="25%" align="center"><b><font color="red">Member</font></b><br><b><? echo $data['username'];?></b></td><td width="25%" align="center"></b><b><font color="red">Time</font></b><br><b><? echo $data['time_sent']; ?></b></td><td width="25%" align="center"><b><font color="red">Date</font></b><br><b><? echo $data['date_sent'];?></b></td></table><br><br><?}?><?php$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM member_comments where date_added='".$record['date_added']."' and time_added='".$record['time_added']."' "),0); $total_pages = ceil($total_results / $max_results); echo "<center><b>View More!</b><br>"; if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."??date_added=".$record['date_added']."&time_added=".$record['time_added']."&user_id=$user_id&page=$prev\"></a>"; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?date_added=".$record['date_added']."&time_added=".$record['time_added']."&user_id=$user_id&page=$i\">$i</a> "; } } if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."??date_added=".$record['date_added']."&time_added=".$record['time_added']."&user_id=$user_id&page=$next\"></a>";} }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93526 Share on other sites More sharing options...
OLM3CA Posted September 17, 2006 Author Share Posted September 17, 2006 Thank you verymuch redarrow but the problem is when I cannot get the searchterm in other pages.Your paging seems a little comlex for me.If you can convert it to my code I am so glad Blieve that I am dealing with this problem for too long. Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93557 Share on other sites More sharing options...
redarrow Posted September 17, 2006 Share Posted September 17, 2006 try this ok.[code]<?php$db=mysql_connect("localhost" , "xxx" , "xxxx");mysql_select_db("promotor",$db);if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 1; $from = (($page * $max_results) - $max_results); $query = mysql_query("SELECT * FROM tablex WHERE area1 LIKE '%".$_POST['keyword']."%' AND status='1' LIMIT $from, $max_results";$result=mysql_query($query);while($r=mysql_fetch_assoc($result)){echo $r['name'];echo $r['web'];echo $r['number'];$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM tablex "),0); $total_pages = ceil($total_results / $max_results); if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"></a>"; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; } } if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"></a>";} }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93568 Share on other sites More sharing options...
redarrow Posted September 17, 2006 Share Posted September 17, 2006 i just set this up to see all the members names 1 by one all you got to do is change the database information okfully tested.[code]<?php$db=mysql_connect("localhost" , "xxusernamexx" , "xxpasswordxx");mysql_select_db("database_name",$db);$name="java";if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 1; $from = (($page * $max_results) - $max_results); $query="SELECT * FROM members WHERE programming_lanuage LIKE '%".$name."%' LIMIT $from, $max_results";$result=mysql_query($query);while($record=mysql_fetch_assoc($result)){echo $record['name'];$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM members"),0); $total_pages = ceil($total_results / $max_results); if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"></a>"; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; } } if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"></a>";} }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93578 Share on other sites More sharing options...
OLM3CA Posted September 17, 2006 Author Share Posted September 17, 2006 Thank you very much for your replies I add a form for searching keyword but when I search a word page numbers appear but when I click on them returns back .[color=green]All my codes in :[/color][u][b]search.php[/b][/u][code]<?php// mysq connection // database connection$keyword= $_POST['keyword'];if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 1; $from = (($page * $max_results) - $max_results); $query="SELECT * FROM tablox WHERE keywords LIKE '%".$keyword."%' LIMIT $from, $max_results";$result=mysql_query($query);if(!$_POST['kelime']) {?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <table border="0" cellspacing="0" cellpadding="0"> <tr valign="middle"> <td align="left"> SEARCH <br> <input name="keyword" type="text" class="input"> </td> <td align="center" valign="bottom"><input type="submit" name="Submit" value="search"></td> </tr> </table> </form><?php } else {while($record=mysql_fetch_assoc($result)){echo $record['name'];$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM tablox"),0); $total_pages = ceil($total_results / $max_results); if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"></a>"; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; } } if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"></a>";} } }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93588 Share on other sites More sharing options...
redarrow Posted September 17, 2006 Share Posted September 17, 2006 see this bit is the bit that tells the code what information you want so put names there if names in the database ok.WHERE keywords look at my code and your see that i am searchining under the colum database name programming_lanuage get me.and i set the form to $name see know?if you have a colum called name in the database then all you goto do is change the where keyword to name ok.don it for you ok.now what this means you select tablox where col name from the database to see in this code [code]$query="SELECT * FROM tablox WHERE name LIKE '%".$keyword."%' LIMIT $from, $max_results";$result=mysql_query($query);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93591 Share on other sites More sharing options...
OLM3CA Posted September 17, 2006 Author Share Posted September 17, 2006 I just change the values to mines in example keywords column for programming_lanuage and the name variable that I set it in my search form.I changed nothing just I add a form is there something wrong with the form ? I have a name column in my database too. Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93595 Share on other sites More sharing options...
redarrow Posted September 17, 2006 Share Posted September 17, 2006 $query="SELECT* FROM tablox <<<datadase were usingWHERE name <<<<name is in the database but the colum you want to search for.LIKE '%".$keyword <<<keyword is set from the form to search the colum of name.."%'LIMIT$from,$max_results";$result=mysql_query($query);if your searchin from a form then you need to also tell the code what the name isyour is name so you need this '%"name"%' know you see the keyword it needs to be the same name as the database colum. Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93597 Share on other sites More sharing options...
redarrow Posted September 17, 2006 Share Posted September 17, 2006 so if you got a colum called name in the database and name in the form then this will work ok.$query="SELECT * FROM tablox WHERE name LIKE '%".$name."%' LIMIT $from, $max_results";$result=mysql_query($query);read this to understand like and keep the link it's a life saver ok.http://www.1keydata.com/sql/sqllike.html Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93604 Share on other sites More sharing options...
OLM3CA Posted September 17, 2006 Author Share Posted September 17, 2006 They are correct,the system is working but when ı click on the page links 1 2 3 4 5 etc... the form return back.I cannot see the other page results I see the links but I cannot see the result. I think there is something wrong with theif(!$_POST['keyword']) { } usage.Because When I click on the next link keyword automaticly dissapears and the query sets back to "no keyword entered". Do you understand me ? My english is not good enough Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93608 Share on other sites More sharing options...
redarrow Posted September 17, 2006 Share Posted September 17, 2006 so your telling me in your database colum you got a colum named keywordsi dont think so?this needs to be the same name as the database tablekeywordthis needs to be the name from the form to search with'%"$keyword"%' Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93609 Share on other sites More sharing options...
sasa Posted September 17, 2006 Share Posted September 17, 2006 change your form metod to GET and send keyword via url?page=$i&keyword=$keywordalso change $_POST['keyword'] to $_GET['keyword']btw what is $_POST['kelime'] , kelime ?? Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93610 Share on other sites More sharing options...
redarrow Posted September 17, 2006 Share Posted September 17, 2006 sasa the problam is that he does not understand the concept of like so he needs to set the first keyword to a database colum. Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93611 Share on other sites More sharing options...
OLM3CA Posted September 17, 2006 Author Share Posted September 17, 2006 I have a column called "name"$query="SELECT * FROM yyyy WHERE xxxx LIKE '%".$keyword."%' LIMIT $from, $max_results";yyyy is the table in database xxxx is the column that I search keyword I have a column in my database called "keywords"redarrow I will look at the codes once.sasa I will try Get method Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93625 Share on other sites More sharing options...
OLM3CA Posted September 17, 2006 Author Share Posted September 17, 2006 Please listen I have no problem with listing datas or problem in sql my problem is :When I search for a word for example "myword" there are 10 results shown in everypage there is 2 result THAT makes 5 pages. 1 2 3 4 5 When I click on 2nd its ok but when I want to click or mouse on the 3rd one I see that [color=green]" page=3&keyword= "[/color] empty? so When I click it searches to keyword = no keyword Do you understan me ? Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93637 Share on other sites More sharing options...
sasa Posted September 17, 2006 Share Posted September 17, 2006 can you post your modifed code Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93646 Share on other sites More sharing options...
OLM3CA Posted September 17, 2006 Author Share Posted September 17, 2006 [code]$keyword= $_GET['keyword']; echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev&keyword=$keyword\"></a>";echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i&keyword=$keyword\">$i</a> ";echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next&keyword=$keyword\"></a>";[/code]and form method changed to GET Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93654 Share on other sites More sharing options...
sasa Posted September 17, 2006 Share Posted September 17, 2006 i don't see any error in this codecan we see all Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93661 Share on other sites More sharing options...
OLM3CA Posted September 17, 2006 Author Share Posted September 17, 2006 search.php All codes[code]<?php//mysql db connections$kelime= $_GET['kelime'];if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 2; $from = (($page * $max_results) - $max_results); $query="SELECT * FROM linkler WHERE kelimeler LIKE '%".$kelime."%' LIMIT $from, $max_results";$result=mysql_query($query);?> <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <table border="0" cellspacing="0" cellpadding="0"> <tr valign="middle"> <td align="left"> SEARCH <br> <input name="kelime" type="text" class="input"> </td> <td align="center" valign="bottom"><input type="submit" name="Submit"></td> </tr> </table> </form><?php while($record=mysql_fetch_assoc($result)){echo "<br>";echo $record['name'];echo "<br>";echo $record['url'];echo "<br>";echo $record['kelimeler'];$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM linkler"),0); $total_pages = ceil($total_results / $max_results); if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev&keyword=$kelime\"></a>"; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i&keyword=$kelime\">$i</a> "; } } if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next&keyword=$kelime\"></a>";} } ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93664 Share on other sites More sharing options...
sasa Posted September 17, 2006 Share Posted September 17, 2006 i make litle modification of your code try[code]<?php//mysql db connections$kelime= $_GET['kelime'];if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 2; $from = (($page * $max_results) - $max_results); $query="SELECT * FROM linkler WHERE kelimeler LIKE '%".$kelime."%' LIMIT $from, $max_results";$result=mysql_query($query);?> <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <table border="0" cellspacing="0" cellpadding="0"> <tr valign="middle"> <td align="left"> SEARCH <br> <input name="kelime" type="text" class="input"> </td> <td align="center" valign="bottom"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </form><?php if ($_GET['kelime']){ while($record=mysql_fetch_assoc($result)){echo "<br>";echo $record['name'];echo "<br>";echo $record['url'];echo "<br>";echo $record['kelimeler'];echo '<hr />';}$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM linkler WHERE kelimeler LIKE '%".$kelime."%'"),0); $total_pages = ceil($total_results / $max_results); if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev&kelime=$kelime\">prev </a>"; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i&kelime=$kelime\">| $i</a> "; } } if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next&kelime=$kelime\">| next</a>";} } ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93679 Share on other sites More sharing options...
OLM3CA Posted September 17, 2006 Author Share Posted September 17, 2006 How can I thank you ? Thank you very much? thank you thank redarrow :) and thank you all for your help :) Quote Link to comment https://forums.phpfreaks.com/topic/21059-transfering-variable-to-other-pages/#findComment-93680 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.