MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old April 20th, 2003, 10:22 AM
nation-x nation-x is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 4 nation-x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 27 sec
Reputation Power: 0
Dynamic MySQL Paging Class example problems

I followed the tutorial an built my own class and was getting erros so I tried just running the example as was presented and I get the following errors.

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/nationx/public_html/nxLinks/class.recnav.php on line 65

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/nationx/public_html/nxLinks/class.recnav.php on line 95

Warning: ereg_replace() [function.ereg-replace]: REG_EMPTY in /home/nationx/public_html/nxLinks/class.recnav.php on line 122
Id Description Price
tr td width='10%' height='21' align='center' font face='verdana' size='1' color='darkblue' b No records found /b /font /td td width='80%' height='21' font face='verdana' size='1' color='black' | | /font /td td width='10%' height='21' font face='verdana' size='1' color='red' $ | | /font /td /tr

What's up with that and how can I fix it? I am new to php.

Reply With Quote
  #2  
Old April 22nd, 2003, 12:45 AM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via ICQ to avit
What is your query? It could be that the error is in your SQL syntax. Try inserting:

echo $yourquery;

before the call to RecNav, so you can see what's actually being requested.

Reply With Quote
  #3  
Old October 27th, 2003, 07:18 PM
billybongchong billybongchong is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: AU
Posts: 5 billybongchong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 53 sec
Reputation Power: 0
I am getting the same Error line65,68

This is a great script but I cannot get it to work.... I have not editied it from the tutorial... and it still wiil not display properly.. Any Ideas

My display page is....


<html>


<head>


<title> Recordset Paging Example </title>


</head>


<body bgcolor="#FFFFFF">


<?php
require("class.recnav.php");



global $HTTP_GET_VARS;


$page = $HTTP_GET_VARS["page"];


$headerTemplate = "<h1>Joes Bookshop</h1>";


$headerTemplate .= "<table width='300' border='1' bordercolor='maroon' cellspacing='0' cellpadding='0'>";


$headerTemplate .= "<tr>";


$headerTemplate .= "<td width='15%' height='20' bgcolor='maroon' align='center'>";


$headerTemplate .= " <font face='verdana' size='1' color='lightyellow'>";


$headerTemplate .= " ID";


$headerTemplate .= " </font>";


$headerTemplate .= "</td>";


$headerTemplate .= "<td width='85%' height='20' bgcolor='maroon' align='center'>";


$headerTemplate .= " <font face='verdana' size='1' color='lightyellow'>";


$headerTemplate .= " Book Title";


$headerTemplate .= " </font>";


$headerTemplate .= "</td>";


$headerTemplate .= "</tr>";





$bodyTemplate = "<tr>";


$bodyTemplate .= "<td width='15%' bgcolor='lightblue' align='center'>";


$bodyTemplate .= " <font face='verdana' size='1' color='darkblue'>";


$bodyTemplate .= " <| row0 |>";


$bodyTemplate .= " </font>";


$bodyTemplate .= "</td>";


$bodyTemplate .= "<td width='85%' bgcolor='lightyellow' height='50'>";


$bodyTemplate .= " <p style='margin-left:10'>";


$bodyTemplate .= " <a href='prod.php?prodId=<| row0 |>'>";


$bodyTemplate .= " <font face='verdana' size='1' color='red'>";


$bodyTemplate .= " <b><u><| row1 |></u></b>";


$bodyTemplate .= " </a>";


$bodyTemplate .= " </font>";


$bodyTemplate .= " <font face='verdana' size='1' color='black'>";


$bodyTemplate .= " <b><br>[ Only <| row2 |>] </b>";


$bodyTemplate .= " </font>";


$bodyTemplate .= "</td>";





$s = mysql_connect("localhost", "xxxxx", "xxxxxx"); //HOST,USERNAME,PASSWORD


$d = mysql_select_db("xxxxxx_com_au", $s); // Database name

$r = new RecNav($s, "SELECT * FROM books ORDER BY bookId ASC", $bodyTemplate, $headerTemplate, "", 5);



echo $r->ShowRecs($page);





?>


</body>


</html>



Reply With Quote
  #4  
Old October 27th, 2003, 07:26 PM
billybongchong billybongchong is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: AU
Posts: 5 billybongchong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 53 sec
Reputation Power: 0
My class file is

<?php

// Default number of records
define("DEFAULT_NUM_RECS", 10);
define("DEFAULT_TEMPLATE_HEADER", "<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td width='10%' height='21' bgcolor='black' align='center'><font color='white' face='verdana' size='1'><b>Id</b></font></td><td width='80%' height='21' bgcolor='black'><font color='white' face='verdana' size='1'><b>Description</b></font></td><td width='10%' height='21' bgcolor='black' align='center'><font color='white' face='verdana' size='1'><b>Price</b></font></td></tr>");
define("DEFAULT_TEMPLATE", "<tr><td width='10%' height='21' align='center'><font face='verdana' size='1' color='darkblue'><b><| row0 |></b></font></td><td width='80%' height='21'><font face='verdana' size='1' color='black'><| row1 |></font></td><td width='10%' height='21'><font face='verdana' size='1' color='red'>$<| row2 |></font></td></tr>");
define("DEFAULT_TEMPLATE_FOOTER", "</table>");


echo $yourquery;

class RecNav
{
function RecNav(&$LinkIdentifier, $Query, $Template=DEFAULT_TEMPLATE, $TemplateHeader=DEFAULT_TEMPLATE_HEADER, $TemplateFooter=DEFAULT_TEMPLATE_FOOTER, $RecsPerPage=DEFAULT_NUM_RECS)
{
// Validate constructor parameters
if(!@mysql_query("SELECT 1", $LinkIdentifier))
{ die("MYSQL link identifier is invalid"); }
else
{
$this->__linkId = $LinkIdentifier;
}

if(!ereg("^SELECT", $Query))
{ die("Invalid query: query must start with 'SELECT'"); }

else
{ $this->__query = $Query; }

if($Template == "")
{ $this->__template = DEFAULT_TEMPLATE; }
else
{ $this->__template = $Template; }

if($TemplateHeader == "")
{ $this->__templateHeader = DEFAULT_TEMPLATE_HEADER; }
else
{ $this->__templateHeader = $TemplateHeader; }

if($TemplateFooter == "")
{ $this->__templateFooter = DEFAULT_TEMPLATE_FOOTER; }
else
{ $this->__templateFooter = $TemplateFooter; }

if(!is_numeric($RecsPerPage) || $RecsPerPage < 1)
{ $this->__recsPerPage = DEFAULT_NUM_RECS; }
else
{ $this->__recsPerPage = $RecsPerPage; }
}

function ShowRecs($Page=1)
{
// Using the classes variables and the $Page variable,
// the ShowRecs function will query the database and
// return the records based on the $__template variable.

$finalOutput = $this->__templateHeader;

if($Page <= 1)
{
$Page = 1;
$query = $this->__query . " LIMIT 0, " . $this->__recsPerPage;
}
else
{ $query = $this->__query . " LIMIT " . (($Page-1) * $this->__recsPerPage) . ", " . $this->__recsPerPage; }

$result = mysql_query($query);
$hasRecords = mysql_num_rows($result) == 0 ? false : true;

if($hasRecords)
{
// At least one records returned from the query
while($row = mysql_fetch_row($result))
{
$newRow = $this->__template;

for($i = 0; $i < mysql_num_fields($result); $i++)
{ $newRow = str_replace("<| row" . $i . " |>", $row[$i], $newRow); }

$finalOutput .= $newRow;
}
}
else
{
// No records returned from the query
$newRow = $this->__template;
$newRow = str_replace("<| row0 |>", "No records found", $newRow);

// Replace all template tags with &nbsp;
$newRow = ereg_replace("<| row[0-9] |>", "&nbsp;", $newRow);

$finalOutput .= $newRow;
}

$finalOutput .= $this->__templateFooter;

// Build the recordset paging links
$numTotalRecs = mysql_num_rows(mysql_query($this->__query));
$numPages = ceil($numTotalRecs / $this->__recsPerPage);
$nav = "";

// Can we have a link to the previous page?
if($Page > 1)
$nav .= "<a href='$PHP_SELF?page=" . ($Page-1) . "'><< Prev</a> |";

for($i = 1; $i < $numPages+1; $i++)
{
if($Page == $i)
{
// Bold the page and dont make it a link
$nav .= " <b>$i</b> |";
}
else
{
// Link the page
$nav .= " <a href='$PHP_SELF?page=$i'>$i</a> |";
}
}

// Can we have a link to the next page?
if($Page < $numPages)
$nav .= " <a href='$PHP_SELF?page=" . ($Page+1) . "'>Next >></a>";

// Strip the trailing pipe if there is one
$nav = ereg_replace("|$", "", $nav);

$finalOutput .= "<div align='right'><font face='verdana' size='1'><br>Pages: $nav</font></div>";

return $finalOutput;
}

var $__linkId;
var $__dbType;
var $__query;
var $__template;
var $__templateHeader;
var $__templateFooter;
var $__recsPerPage;

}
?>

Reply With Quote
  #5  
Old September 10th, 2006, 12:42 PM
jerry jerry is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 1 jerry User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 29 sec
Reputation Power: 0
Talking solution

$nav = ereg_replace("/|$/", "", $nav);

REG_EMPTY because it was empty. I had same problem.


Reply With Quote
  #6  
Old April 15th, 2007, 02:30 PM
Trield Trield is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 Trield User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 52 sec
Reputation Power: 0
Exclamation Problem with this Class

I got it working just great for 1st page. I use my categories table to display the page with links that would go to my next page, which deals with the classifications that are under the categories (depends of course on which link they clicked.)

So I tried just using the same thing I have always used when selecting only certain records with SQL such as:

$r = new RecNav($s, "SELECT * FROM classification WHERE parent_id=<| row0 |>", $bodyTemplate, $headerTemplate, "", 10);

and I tried (I put <| row0 |> into $pid):

$r = new RecNav($s, "SELECT * FROM classification WHERE parent_id LIKE '%$pid%'", $bodyTemplate, $headerTemplate, "", 10);

What am I doing wrong??? (The only thing I changed in the code is putting in the where statement.) I get html on my page and it looks like there is no records....but if I put the number of my parent_id that I want in it works fine. So, it has to be the the parameter I am putting in wrong.

Please can someone help me in this??? I am not that experienced in PHP and I need to get this up and running.

Thanks so much!!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Dynamic MySQL Paging Class example problems


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway