Forum Moderators: coopster

Message Too Old, No Replies

php pagination

         

adamnichols45

4:33 pm on Dec 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi people just 1 slight problem hope some one can help! birdman has been helping me out loads with this script so thanks so far to him :)

so far on page one it takes word from text box and produces search on datebase for that word then produces correctly over the folling pages using pagination. question is i want it to now perform search onto words and display the 2 words. code is below. :_

$carrymake = (isset($_POST['carrymake']))? $_POST['carrymake'] : $_GET['carrymake'];

$carrymodal = (isset($_POST[carrymodal ]))? $_POST[carrymodal ] : $_GET[carrymodal ];

i want to know now how to include the second varible in this code here:-

// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.$prev.'&carrymake='.$carrymake.'"><<Previous</a>&nbsp;';
}

thanks for any help

Salsa

6:38 pm on Dec 21, 2004 (gmt 0)

10+ Year Member



echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.$prev.'&carrymake='.$carrymake.'&carrymodal='.$carrymodal.'"><<Previous</a>&nbsp;';

jatar_k

6:46 pm on Dec 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



and Welcome to WebmasterWorld adamnichols45

adamnichols45

7:12 pm on Dec 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you i feel welcome already what an excellent forum lots of people giving there help hopefully i can do as well in other forums! Thanks for the code which works - I also got help from birdman who is the most helpful person i think i have come accross on the internet in about 7 years surfing thanks so much best regards and a happy new year adam

adamnichols45

8:28 pm on Dec 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



just 1 thing im trying to change folks.

on page 1 there is two 2 select boxs

code im using to get varible for pagination is

// Get the search term into a variable.
// It could be $_GET or $_POST, so use a shorthand if/else
if (isset($_POST['myselect_1'])){
$carrymake = $_POST['myselect_1'];
$carrymodal = $_POST['myselect_2'];
} else {
$carrymake = $_GET['myselect_1'];
$carrymodal = $_GET['myselect_2'];
}

can someone tell me why im recieving an error

Notice: Undefined index: myselect_1 in C:\Inetpub\wwwroot\carpound\testpage\eg.php on line 25

what code shall i use

Salsa

2:51 am on Dec 22, 2004 (gmt 0)

10+ Year Member



If neither $_POST['myselect_1'] nor $_GET['myselect_1'] is set, you'll get that error when you try to use $_GET['myselect_1'] in your else statement. Try test echoing out the values to see if either of them is there:

echo "\$_POST['myselect_1'] = '$_POST['myselect_1']'<br>\n"; 
echo "\$_GET['myselect_1'] = '$_GET['myselect_1']'<br>\n";

adamnichols45

6:57 pm on Dec 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks i got this error sorted now i got a new one though lol i started a new topic maybe you can help please - topic is pagination problem thanks

adamnichols45

6:55 pm on Dec 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



can any one see what is wrong with this code please

error i get is
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in testpage/eg.php on line 33

code is below
first line is line 33

while($row = mysql_fetch_array($sql)){

print '
<table width="570" border="0" class=setb>
<tr>
<td valign="middle" rowspan="2" bgcolor=EDEDED width="50" class=blackb >'.$row['make'].'</td><td>'.$row['model'].'</td>
</tr>

</table>
';
}

jatar_k

7:37 pm on Dec 22, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I just spliced them together ;)

the trouble is your query is somehow invalid so mysql_fetch_array is dying

try adding this to your mysql_query line

$sql = mysql_query($queryvar) or die (mysql_error());

adamnichols45

8:30 pm on Dec 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks for the reply i sorted this now as well it was just a simple spelling mistake when i was referring to database elements silly me :) thanks guys

adamnichols45

10:04 pm on Dec 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



how would i go about introducing a conditional that display text "NO RECORDS" if there are no records to display and if there is just display them? cheers

coopster

10:12 pm on Dec 22, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I usually check the result set first for the number of returned rows. If it is greater than zero, I know I have information to display.
$sql = "SELECT ... "; 
$rows = mysql_query($sql);
if (mysql_num_rows [php.net]($rows) > 0) {
// process my result set
} else {
// no records to show
}

adamnichols45

10:14 pm on Dec 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



so do i include the script in the brackets then? im sorry im new to php so im not sure what goes where thanks for the help best regards..

coopster

6:05 pm on Dec 23, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The " // process my result set" part is where you would fetch your rows (your while loop).