•
•
•
•
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
![]() |
•
•
Join Date: Jun 2004
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
i've tried the first script above.... but what i get ouputted is:
Pages
3) [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
Pages
3) [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
•
•
Join Date: Feb 2003
Location: London, England
Posts: 281
Reputation:
Rep Power: 7
Solved Threads: 6
•
•
Join Date: May 2004
Location: berg en terblijt
Posts: 10
Reputation:
Rep Power: 5
Solved Threads: 0
•
•
•
•
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> </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 " "; // There was no data. Write a to create an 'empty' cell
}
echo "</td>"; // close the cell
}
echo "</tr>\n"; // close the row
}
echo "</table>\n"; // close the table
[/php]
/ Patrick
•
•
Join Date: Feb 2005
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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
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
•
•
Join Date: Apr 2005
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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:
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???
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???
•
•
Join Date: Apr 2005
Posts: 12
Reputation:
Rep Power: 4
Solved Threads: 0
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.
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
Other Threads in the PHP Forum
- Previous Thread: Query syntax not working
- Next Thread: Want to pass a string through URL...


Linear Mode