Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Help with counting records
Old 12-11-2005, 06:47 AM Help with counting records
Junior Talker

Posts: 3
Location: High Point NC
Trades: 0
Hello everyone,

I am a self-taught PHP newbie (via trial and error) and have a small ministry, which builds sites for other ministries.

I was hoping someone could help me tweak this script?

I finally got it to show the pages in 10 rows with links to and fro, but after the last full page of vehicles it keeps going to 'Next >>'. Apparently it doesn't know how many records there are.

I figured out using mysql_num_rows() will count the row #s, but how do I apply that to the links to 'put the brakes on' for the 'Next >>' link on the last page of records?

Another problem is that they are contantly adding and deleting vehicle inventory so the row #s would always be changing. Then I couldn't put a set value in ceil().

Is there anyway to set a wildcard with ceil() or something similar like this?

PHP Code:
*/ In the Main Section */

$result mysql_query("SELECT * FROM inventory");
$num_rows mysql_num_rows($result);
$num_rows $lastpage;
 
*/ 
Then add this to the Next Link Section */

if (
$lastpage=stop) {
echo 
" ";

** The $$price in the script below is actually: & # 3 6 ; $price w/o spaces.

PHP Code:
<?
if (isset($_GET['start']))
{
$start $_GET['start'];
} else {
$start 0;
}
$dbuser "user"
$dbserver "localhost"
$dbpass "pass"
$dbname "name"
mysql_connect($dbserver$dbuser$dbpass)
or die (
"UNABLE TO CONNECT TO DATABASE");
mysql_select_db($dbname)
or die (
"UNABLE TO SELECT DATABASE");
$sql "SELECT * FROM inventory ORDER BY ref ASC LIMIT $start , 10";
$result mysql_query($sql) or die(mysql_error());
if (
$myrowsel mysql_fetch_array($result)) {
do
{
$id=$myrowsel['id'];
$ref=$myrowsel['ref'];
$year=$myrowsel['year'];
$make=$myrowsel['make'];
$model=$myrowsel['model'];
$price=$myrowsel['price'];
switch (
$shade)
{
case 
'row_lite':
$shade 'row_drk';
break;
case 
'row_drk':
$shade 'row_lite';
break;
default:
$shade 'row_lite';
break;
}
echo 
" <tr>
<td valign=top class=
$shade>
<table width=100% cellspacing=0 cellpadding=3>
<tr>
<td width=75 align=center valign=middle><img src=list/
$ref.jpg alt='Image not available' width=75 height=56></td>
<td width=100 nowrap class=reg>Ref#&nbsp;
$ref</td>
<td width=250 nowrap class=reg>
$year&nbsp;$make&nbsp;$model</td>
<td width=70 nowrap class=reg>$
$price</td>
<td width=100%>&nbsp;</td>
</tr>
</table>
</td>
</tr>
"
;
}
while (
$myrowsel mysql_fetch_array($result));
}
?>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width=100% valign=top colspan=2>
<table width=100% cellspacing=0 cellpadding=3>
<tr>
<td width=10>&nbsp;</td>
<td width=50%>
<?
if (isset($_GET['start']))
{
$start $_GET['start'];
} else {
$start 0;
}
for(
$i $start$i $start 10$i--) {
if (
$i == $start 9) {
echo 
"<a class=lnk href=list.php?start=".($i-1).">« Previous page</a>";
}
}
?>
</td>
<td width=50% align=right>
<?
if (isset($_GET['start']))
{
$start $_GET['start'];
} else {
$start 0;
}
for(
$i $start$i $start 10$i++) {
if (
$i == $start 9) {
echo 
"<a class=lnk href=list.php?start=".($i+1).">Next page »</a>";
}
}
?>
Thanks,
xsfssg

Last edited by xsfssg; 12-11-2005 at 10:45 AM..
xsfssg is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-11-2005, 12:32 PM
eburza's Avatar
Super Talker

Posts: 122
Name: Antonio Magdic
Location: Zagreb, Croatia
Trades: 0
here ... dont understand this ??

PHP Code:
$num_rows mysql_num_rows($result);
$num_rows $lastpage
__________________

Please login or register to view this content. Registration is FREE
eburza is offline
Reply With Quote
View Public Profile Visit eburza's homepage!
 
Old 12-11-2005, 02:52 PM Sorry about the confusion..
Junior Talker

Posts: 3
Location: High Point NC
Trades: 0
Eburza,

Was just throwing an idea of what I think I would need to do.

The $num_rows = mysql_num_rows($result);$num_rows = $lastpage; was added to kinda draw a ficticious picture of my thoughts.
xsfssg is offline
Reply With Quote
View Public Profile
 
Old 12-12-2005, 12:27 AM
Ultra Talker

Posts: 253
Trades: 0
you can always look for record count via phpmyadmin if its just for personal use.
takita is offline
Reply With Quote
View Public Profile
 
Old 12-12-2005, 04:01 PM
Experienced Talker

Posts: 36
Trades: 0
mysql_num_rows() returns the number of rows found in that result set. If you are using limit in your select queries, then the number that functions returns will never be greater than your limit number.

You need to use the MySQL function count() in a second query or use SQL_CALC_FOUND_ROWS. See the MySQL manual for more information on both.
tress is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help with counting records
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.21931 seconds with 12 queries