General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

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:
  #1  
Old October 17th, 2003, 12:24 AM
Alicia Alicia is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 117 Alicia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 29 sec
Reputation Power: 6
page numbering prob

Hi guys,

I wanted to do page numbering in my results page. My code used to be okay before i put the code for page numbering.

I am wondering where did i do wrong because now it seems like not able to search properly. Now i am not able to get any results even the record is in the db. It seems like i screwed up with the sql query. Can you give me a hint where i've done wrong. Thanks..

Please advise

my code:
PHP Code:
<?php 

// Database Connection 
mysql_connect("""user","pass") or die("Unable to connect to the server");
mysql_select_db("user_db") or die("Unable to connect to database");

// If current page number, use it 
// if not, set one! 

if(!isset($_GET['page'])){ 
    
$page 1
} else { 
    
$page $_GET['page']; 


// Define the number of results per page 
$max_results 15

// Figure out the limit for the query based 
// on the current page number. 
$from = (($page $max_results) - $max_results); 

// Perform MySQL query on only the current page number's results 
$sql 'select * from `club1` ';
$joiner 'where ';
if (!empty(
$c_category)) 
{
$sql .= "{$joiner}`bcategory` LIKE '{$c_category}'";
$joiner 'and ';
}

if (!empty(
$c_desc)) 
{
$sql .= "{$joiner}`c_desc` LIKE '%$c_desc%'";
$joiner 'and ';
}

if (!empty(
$c_name))

$sql .= "{$joiner}`bcompany` LIKE '%$c_name%'";
$joiner 'and ';


if (!empty(
$c_state))

$sql .= "{$joiner}`bstate` LIKE '%$c_state%'";
$joiner 'and ';



if (!empty(
$c_country))

$sql .= "{$joiner}`bcountry` LIKE '$c_country'";
$joiner 'and ';

//continue for the rest of the variables

$result mysql_query ("$sql ORDER BY `bcompany` LIMIT $from, $max_results") or die (mysql_error()); 
//$sql = mysql_query("SELECT * FROM club1 LIMIT $from, $max_results") or die (mysql_error()); 


echo "<u><b>Your search: </b></u><br>" ;
if (!empty(
$c_category)) 
{
echo 
'<b>Category :</b>';
echo 
$c_category,'<br>';
}

if (!empty(
$c_country)) 
{
echo 
'<b>Country :</b>';
echo 
$c_country ,'<br>';
}


if (!empty(
$c_desc)) 
{
echo 
'<b>Description :</b>';
echo 
$c_desc ,'<br>';
}

if (!empty(
$c_name))

echo 
'<b>Name :</b>';
echo 
$c_name,'<br>';


if (!empty(
$c_state))

echo 
'<b>State :</b>';
echo 
$c_state,'<br>';


?>


<br></font></p>
<table border="0" width="656">
    <tr>
        <td width="72" bordercolor="#CCCCCC" bgcolor="#FFCCFF">
            <p><font size="2" face="Arial" color="#3300CC"><b>Results:</b></font></p>
        </td>
        <td width="259" bordercolor="#CCCCCC" bgcolor="#FFCCFF">
            <p>
        <font size="2" face="Arial" color="#3300CC"><b>


<?
if($no == 0){
echo 
" <b>Sorry, no results found. Please try again.</b>";
include (
"list_pgbd_new.htm");
exit ();
       }
?>
</b></font>
        
        </p>
        </td>
        <td width="94" bordercolor="#CCCCCC" bgcolor="#FFCCFF">
            <p><font size="2" face="Arial" color="#3300CC"><b>No of results:</b></font></p>
        </td>
        <td width="203" bordercolor="#CCCCCC" bgcolor="#FFCCFF">
            <p>
        <font size="2" face="Arial" color="#3300CC"><b><?php 
        
echo "( $no )";
        
?></b></font>
        
        </p>
        </td>
    </tr>
<?    
while ($row mysql_fetch_array ($result)) {
 
?>
   <tr>
        <td width="72">
            <p><font size="2" face="Arial" color="#3300CC">&nbsp;Company:</font></p>
        </td>
        <td width="568" colspan="3">
            <p><font size="2" face="Arial" color="#3300CC"><b><?php echo $row["bcompany"]; ?></b></font></p>
        </td>
    </tr>
    <tr>
        <td width="72">
            <p><font size="2" face="Arial" color="#3300CC">&nbsp;Address:</font></p>
        </td>
        <td width="259">
            <p><font size="2" face="Arial" color="#3300CC"><?php echo $row["badd"]; ?></font></p>
        </td>
        <td width="94">
            <p><font size="2" face="Arial" color="#3300CC">ZipCode:</font></p>
        </td>
        <td width="203">
            <p><font size="2" face="Arial" color="#3300CC"><?php echo $row["bzipcode"]; ?></font> </p>
        </td>
    </tr>
    <tr>
        <td width="72">
            <p><font size="2" face="Arial" color="#3300CC">&nbsp;State:</font></p>
        </td>
        <td width="259">
            <p><font size="2" face="Arial" color="#3300CC"><?php echo $row["bstate"]; ?></font></p>
        </td>
        <td width="94">
            <p><font size="2" face="Arial" color="#3300CC">Country:</font> </p>
        </td>
        <td width="203">
            <p><font size="2" face="Arial" color="#3300CC"><?php echo $row["bcountry"]; ?></font></p>
        </td>
    </tr>
    <tr>
        <td width="72">
            <p><font size="2" face="Arial" color="#3300CC">&nbsp;Phone:</font></p>
        </td>
        <td width="259">
            <p>
    <font size="2" face="Arial" color="#3300CC"><?
    
echo $row["b_phone_country"].$row["b_phone_area"].'-'.$row["b_phone_no"];
    
?></font>
    </p>
        </td>
        <td width="94">
            <p><font size="2" face="Arial" color="#3300CC">&nbsp;Fax:</font></p>
        </td>
        <td width="203">
            <p>
    <font size="2" face="Arial" color="#3300CC"><?    
    
echo $row["b_fax_country"].$row["b_fax_area"].'-'.$row["b_fax_no"];
    
?></font>
    
    </p>
        </td>
    </tr>
    <tr>
        <td width="646" colspan="4">
            <p><font size="2" face="Arial" color="#3300CC"><?php
        
if ( $row["c_desc"]!="")
        {
        echo 
"<br><b>Description: </b>";
        echo 
$row["c_desc"];
        }
        
?></font>
        </p>
        </td>
    </tr>
    <tr>
        <td width="646" colspan="4">
            <p><font size="2" face="Arial" color="#3300CC"><?php 
        
if ( $row["url"]!="")
        {
        echo 
"<br><b>URL: </b>";
        echo 
$row["burl"]," | ";
        echo 
$row["Contact_us"];
        }
        
?></font>
        
        </p>
        </td>
    </tr>
    <tr>
        <td width="646" colspan="4">
            <p><font size="2" face="Arial" color="#3300CC">&nbsp;</font></p>
        </td>
    </tr>
    <? ?>
</table>


<?
//page numbering
$total_results mysql_result(mysql_query

/*why i need to put count then follow by 'as Num' in this query.,, my friend said i should put there even it is not used, is that so ?? */ 
("SELECT COUNT(*) as Num FROM club1"),0); 

$total_pages ceil($total_results $max_results); 

echo 
"<center>Select a Page<br />"

if(
$page 1){ 
    
$prev = ($page 1); 
    echo 
"<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a>&nbsp;"


for(
$i 1$i <= $total_pages$i++){ 
    if((
$page) == $i){ 
        echo 
"$i&nbsp;"
        } else { 
            echo 
"<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a>&nbsp;"
    } 



if(
$page $total_pages){ 
    
$next = ($page 1); 
    echo 
"<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>"

echo 
"</center>"
?>

Reply With Quote
  #2  
Old October 17th, 2003, 01:46 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
As per the rules of the board, please make sure you code is not more than 40 lines... otherwise it would be best to put it in a separate file and attach it.

__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #3  
Old October 17th, 2003, 02:28 AM
Alicia Alicia is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 117 Alicia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 29 sec
Reputation Power: 6
sorry coz i dunno about this rule..

Reply With Quote
  #4  
Old October 17th, 2003, 08:19 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Also, why don't you describe what happens? Do you get an error message? Do incorrect results return (if so, what are they and what's wrong with them)? Do no results return?

Reply With Quote
  #5  
Old October 17th, 2003, 09:09 PM
Alicia Alicia is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 117 Alicia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 29 sec
Reputation Power: 6
No, there is no error returned, that is why i am wondering what's wrong with my code.

Reply With Quote
  #6  
Old October 20th, 2003, 08:13 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Try having your code print out the queries, and then run them manually at the mysql command line. This'll help you find any syntax errors that the server perhaps isn't returning to your code.

As for adding the "Num" alias, it's probably not necessary here since you're using the offset rather than the label, but typically if you're executing functions on a column, you need to give it an alias so you can refer to it later by name.

Reply With Quote
  #7  
Old January 13th, 2004, 12:35 PM
apresx apresx is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Atlanta, GA
Posts: 1 apresx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to apresx
Quote:
Originally posted by Alicia
PHP Code:
//page numbering
$total_results mysql_result(mysql_query

/*why i need to put count then follow by 'as Num' in this query.,, my friend said i should put there even it is not used, is that so ?? */ 
("SELECT COUNT(*) as Num FROM club1"),0); 

$total_pages ceil($total_results $max_results); 


The reason behind this is that the LIMIT clause on your SQL will reduce the results to the maximum allowed records printed per page. So you'll be getting just that: the maximum allowed per page ($max_results = 15).

That statement will run a query of ALL of the club1 table to get its total number of rows.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > page numbering prob


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 3 hosted by Hostway
Stay green...Green IT