Jump to content


Photo

Transfering variable to other pages


  • Please log in to reply
23 replies to this topic

#1 OLM3CA

OLM3CA
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts
  • LocationCyprus

Posted 17 September 2006 - 02:02 PM

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 ?

search.php

$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'];
}

AMD rather than Intel , PHP rahter than ASP

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 17 September 2006 - 02:16 PM

You want to use the GET method to parse the data

This parses the data in the address bar
Tell me the problem, I will try tell you the solution

#3 OLM3CA

OLM3CA
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts
  • LocationCyprus

Posted 17 September 2006 - 02:59 PM

ok but what would I write to here :

echo "<a href='index.php?page=search&m=$i'>$a</a>";

becouse its seems like index.php?kelime=...
AMD rather than Intel , PHP rahter than ASP

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 September 2006 - 03:10 PM

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.

<?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>";
} 
 }
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 OLM3CA

OLM3CA
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts
  • LocationCyprus

Posted 17 September 2006 - 04:35 PM

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.
AMD rather than Intel , PHP rahter than ASP

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 September 2006 - 05:04 PM

try this ok.
<?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>";

} 

 }
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 September 2006 - 05:35 PM

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.

<?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>";

} 

 }
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#8 OLM3CA

OLM3CA
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts
  • LocationCyprus

Posted 17 September 2006 - 05:53 PM

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 .
All my codes in :

search.php
<?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>";

} 

 } }
?>

AMD rather than Intel , PHP rahter than ASP

#9 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 September 2006 - 05:57 PM

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

$query="SELECT * FROM tablox WHERE name LIKE '%".$keyword."%' LIMIT $from, $max_results";

$result=mysql_query($query);


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#10 OLM3CA

OLM3CA
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts
  • LocationCyprus

Posted 17 September 2006 - 06:06 PM

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.
AMD rather than Intel , PHP rahter than ASP

#11 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 September 2006 - 06:08 PM

$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.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#12 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 September 2006 - 06:13 PM


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....ql/sqllike.html
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#13 OLM3CA

OLM3CA
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts
  • LocationCyprus

Posted 17 September 2006 - 06:19 PM

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
AMD rather than Intel , PHP rahter than ASP

#14 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 September 2006 - 06:22 PM

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"%'
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#15 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 17 September 2006 - 06:25 PM

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 ??

#16 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 September 2006 - 06:28 PM

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.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#17 OLM3CA

OLM3CA
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts
  • LocationCyprus

Posted 17 September 2006 - 07:01 PM

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
AMD rather than Intel , PHP rahter than ASP

#18 OLM3CA

OLM3CA
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts
  • LocationCyprus

Posted 17 September 2006 - 07:31 PM

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  " page=3&keyword= "      empty? so When I click it searches to keyword = no keyword    Do you understan me ?
AMD rather than Intel , PHP rahter than ASP

#19 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 17 September 2006 - 07:50 PM

can you post your modifed code

#20 OLM3CA

OLM3CA
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts
  • LocationCyprus

Posted 17 September 2006 - 07:57 PM

$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>";

and form method changed to GET
AMD rather than Intel , PHP rahter than ASP




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users