Jump to content

Archived

This topic is now archived and is closed to further replies.

OLM3CA

Transfering variable to other pages

Recommended Posts

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 tablex
WHERE area1 LIKE '%".$_POST['keyword']."%'
AND status='1' order by linkid DESC
LIMIT $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]

Share this post


Link to post
Share on other sites
You want to use the GET method to parse the data

This parses the data in the address bar

Share this post


Link to post
Share on other sites
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=...

Share this post


Link to post
Share on other sites
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]
<?php

if(!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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
i just set this up to see all the members names 1 by one all you got to do is change the database information ok

fully 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]

Share this post


Link to post
Share on other sites
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">&nbsp;</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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
$query
=
"
SELECT
*
FROM
tablox <<<datadase were using
WHERE
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 is
your is name so you need this '%"name"%' know you see the keyword it needs to be the same name as the database colum.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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 the
if(!$_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

Share this post


Link to post
Share on other sites
so your telling me in your database colum you got a colum named

keywords

i dont think so?

this needs to be the same name as the database table
keyword

this needs to be the name from the form to search with
'%"$keyword"%'

Share this post


Link to post
Share on other sites
change your form metod to GET and send keyword via url
?page=$i&keyword=$keyword
also change $_POST['keyword'] to $_GET['keyword']
btw what is $_POST['kelime'] , kelime ??

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
[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

Share this post


Link to post
Share on other sites
i don't see any error in this code
can we see all

Share this post


Link to post
Share on other sites
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">&nbsp;</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]

Share this post


Link to post
Share on other sites
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">&nbsp;</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]

Share this post


Link to post
Share on other sites
How can I thank you ? Thank you very much? thank you thank  redarrow :)
and thank you all for your help :)

Share this post


Link to post
Share on other sites

×

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.