|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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> |
|
#4
|
|||
|
|||
|
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 $newRow = ereg_replace("<| row[0-9] |>", " ", $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; } ?> |
|
#5
|
|||
|
|||
|
$nav = ereg_replace("/|$/", "", $nav);
REG_EMPTY because it was empty. I had same problem. ![]() |
|
#6
|
|||
|
|||
|
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!! |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Dynamic MySQL Paging Class example problems |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|