User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 429,791 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,821 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 14812 | Replies: 22
Reply
Join Date: Jun 2004
Posts: 2
Reputation: .faajbuhr is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
.faajbuhr .faajbuhr is offline Offline
Newbie Poster

Re: Clean Previous Next Script for MySQL results

  #11  
Jun 6th, 2004
i've tried the first script above.... but what i get ouputted is:



Pages3) [1]
Notice: Undefined variable: PHP_SELF in c:\inetpub\wwwroot\montblanc\berichtenAdmin.php on line 151
2
Notice: Undefined variable: PHP_SELF in c:\inetpub\wwwroot\montblanc\berichtenAdmin.php on line 151
3
Notice: Undefined variable: PHP_SELF in c:\inetpub\wwwroot\montblanc\berichtenAdmin.php on line 163
>>
Notice: Undefined variable: PHP_SELF in c:\inetpub\wwwroot\montblanc\berichtenAdmin.php on line 164
Last >>



does anyone have a clue why he tells me that php_self is undefined?

tia
Reply With Quote  
Join Date: Mar 2004
Location: In a house
Posts: 94
Reputation: Ragnarok is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
Ragnarok Ragnarok is offline Offline
Junior Poster in Training

Re: Clean Previous Next Script for MySQL results

  #12  
Jun 6th, 2004
I have tryed to do this a few times but somehow I always manage to mess it up
Reply With Quote  
Join Date: Feb 2003
Location: London, England
Posts: 281
Reputation: Roberdin will become famous soon enough Roberdin will become famous soon enough 
Rep Power: 7
Solved Threads: 6
Colleague
Roberdin Roberdin is offline Offline
Supreme Evil Overlord

Re: Clean Previous Next Script for MySQL results

  #13  
Jun 6th, 2004
Try replacing $PHP_SELF with $_SERVER['php_self']
Reply With Quote  
Join Date: Jun 2004
Posts: 2
Reputation: .faajbuhr is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
.faajbuhr .faajbuhr is offline Offline
Newbie Poster

Re: Clean Previous Next Script for MySQL results

  #14  
Jun 6th, 2004
Originally Posted by Roberdin
Try replacing $PHP_SELF with $_SERVER['php_self']

id did that... the errors were gone, BUT....
when i clicked page 2 or 3, ... there was no reaction.... the same page kept displaying.... :s
Reply With Quote  
Join Date: May 2004
Location: berg en terblijt
Posts: 10
Reputation: Patrickske is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
Patrickske's Avatar
Patrickske Patrickske is offline Offline
Newbie Poster

Re: Clean Previous Next Script for MySQL results

  #15  
Jun 10th, 2004
Originally Posted by cscgal
I don't know PHP for anything but the following is code for one row ...

So now, perhaps use code like the following? Keep in mind I'm NOT a php programmer.

 echo "<table><tr>";
 while ($row = mysql_fetch_array($result)) 
  {
 echo "<td><a HREF=images/ingame/".$row['big']." TARGET=_blank><img src=images/ingame/thumbs/".$row['thumb']." border=0 alt=".$row['big']."></a></td>"; // display your results as you see fit here.
 if (($row % 3) == 0)
   { echo "</tr><tr>"; }
  }
 </tr></table>
 

Keep also in mind that you need to add "empty" cells if you want to display images in a table of 3x4.
I you have a total of 10 records, and the table has 3 rows, 4 columns, then the last row of the table has only 2 columns in it. You need to add <td></td> (or <td>&nbsp;</td>) cells to fill up the row.

I've made an example at http://quaedackers.homeip.net/testsite/table_format.php

As you can see I use 2 nested loops. 1 for the rows, and 1 for the columns. By checking if the row-object (or array) contains any data (it must NOT be false) then you can write the data in the cell. If the object equals false, then you need to write an empty cell.

[php]
echo "<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n";

for($row=0; $row<$rowCount; $row++){ // create the rows in a nice loop
echo "<tr>";
for($col=0; $col<$colCount; $col++){ // create the columns in a nice nested loop
echo "<td width=\"30\" align=\"center\">";
if($db_row = mysql_fetch_object($result))
// fetch the results in an object and thest if there is data.
// (if there is no data, $db_row will be 'false')
{
echo htmlentities($db_row->some_field); // There is data, display it!
}
else
{
echo "&nbsp;"; // There was no data. Write a &nbsp; to create an 'empty' cell
}
echo "</td>"; // close the cell
}
echo "</tr>\n"; // close the row
}

echo "</table>\n"; // close the table
[/php]

/ Patrick
Reply With Quote  
Join Date: Feb 2005
Posts: 1
Reputation: heatmizer20 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
heatmizer20 heatmizer20 is offline Offline
Newbie Poster

Re: Clean Previous Next Script for MySQL results

  #16  
Feb 12th, 2005
LOL. seems that im a little bit late to be responding to this thread, but i will try my luck anywhy.

i have this code reading my sql and posting results, but of course i have a problem with it. if anyone can help me it would be a great help.

1. the pages do not change. it is the same page over and over again.

2. after changing this line to "4" (i have 12 entries)
$limit = "4"; //limit of archived results per page.

it displays page 1-3, but it list all of the results on each page.

how do i break apart the results so that i have 4 items per page and different results on each page.

thanks.

JB
Reply With Quote  
Join Date: Apr 2005
Posts: 2
Reputation: Dustin is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Dustin Dustin is offline Offline
Newbie Poster

Help Re: Clean Previous Next Script for MySQL results

  #17  
Apr 28th, 2005
Really nice code!!

The problem is I get the value input from users and display the results. So the value changes depending on users' search criterias.

So after FIRST page, it doesn't matter which page I click on, I've got this message:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /usr/home/wwwnnn/public_html/test/search.php on line 12

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/home/wwwnnn/public_html/test/search.php on line 26
Pages: (0) << First << 1 [2] 3 4 5 >> Last >>

The $query is:

[PHP]$sql = "SELECT * FROM Resident WHERE LP BETWEEN ".$_POST['minPrice']." AND ".$_POST['MaxPrice']." AND BR = ".$_POST['br']." AND BTH = ".$_POST['bth']."";[/PHP]

Line 12 is:

[PHP]$total_results = mysql_num_rows($query);[/PHP]

Line 26 is:

[PHP]while ($row = mysql_fetch_array($result))[/PHP]

Can anyone please help me out with this???
Reply With Quote  
Join Date: Mar 2004
Posts: 732
Reputation: Phaelax is on a distinguished road 
Rep Power: 6
Solved Threads: 31
Phaelax Phaelax is offline Offline
Master Poster

Re: Clean Previous Next Script for MySQL results

  #18  
Apr 28th, 2005
There's a simple tutorial on "pagination" (results on multiple pages) on phpfreaks.com

Using LIMIT makes this thing easy I think. Though thats coming from a guy who hasn't tried it yet.
Reply With Quote  
Join Date: Apr 2005
Posts: 12
Reputation: robbyd is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
robbyd robbyd is offline Offline
Newbie Poster

Re: Clean Previous Next Script for MySQL results

  #19  
Apr 30th, 2005
oops double posted, check next post
Reply With Quote  
Join Date: Apr 2005
Posts: 12
Reputation: robbyd is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
robbyd robbyd is offline Offline
Newbie Poster

Re: Clean Previous Next Script for MySQL results

  #20  
Apr 30th, 2005
Ive done alot of stuff with 'pagination' and yes using LIMIT in your sql query is the best way to go about it. Theres basically two parts to make it work.

1. is the making the sql query match the page you're on
and
2. displaying the proper pages links, like the " << prev 1 2 3 4 next >> "

[PHP]
// first get the current page ( file.php?p=1 or 2 or what ever)
if(isset($_GET['p'])) $page = $_GET['p'];
else $page = 1;
// set how many entries you want per page (for example 20)
$display = 20;

// set the LIMIT for the sql query
$start = $page * $display - $display;

// then the query should look something like
$sql = "SELECT ... FROM table WHERE ... LIMIT $start, $display";

// The LIMIT should go at the very end of the query.
[/PHP]

so the first page will display entries starting at 0, showing 20 entries.
page 2 will start at entry #20 and display the next 20 and ect..


The second part is showing the 'next, prev' links

[PHP]
// first you need a query to find how many entries there are total in the database
// I use the count function for this
$sql = "SELECT COUNT(*) AS total FROM table_name";
$total = mysql_result(mysql_query($sql),0,'total');

// then break up the total into pages
$totalpages = $total / $display; // in this case $display = 20
// round up on pages
$totalpages = ceil($totalpages);



// if its not page 1, display a 'prev' link

if($page != 1) {
$prev = $page--;
echo '<a href="'. $PHP_SELF . '?p=' . $prev . '">prev</a>';
}

// set current page for loop
$current = 1;

// use while function to loop through each page and display link

while ($current <= $totalpages) {
if($current == $page) echo $currentpage;
else echo '<a href="'. $PHP_SELF . '?p=' . $currentpage . '">' . $currentpage . '</a>';
$current++;
}
// if current page is not the last page, display 'next' link

if($page != $totalpages) {
$next = $page++;
echo '<a href="'. $PHP_SELF . '?p=' . $next . '">next</a>';
}


[/PHP]


And thats all there is to it. If anyone has questions about this, let me know.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:21 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC