Tutorials
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOtherTutorials

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old July 28th, 2002, 02:18 AM
Darth Evad Darth Evad is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 4 Darth Evad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Prev - Next link tutorial.

I checked out a couple of these tutorials and decided to go with the one codewalker has.
When I use it I get an Undefined index: count in line...
Also, it won't show the first record of each page. I'm using 6 records per page and it shows 45 - 41 (ORDER BY refnum DESC) when it should show 46 - 41.
Any suggestions.

Reply With Quote
  #2  
Old July 28th, 2002, 02:35 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via Yahoo to EvilivE
RE: Prev - Next link tutorial.

Your talking about this:
php Code:
Original - php Code
  1. $query = "SELECT count(*) as count FROM table";
  2. $result = mysql_query($query);
  3. $row = mysql_fetch_array($result);
  4. $numrows = $row['count'];


Try changing the index count to total. So it looks like this:
php Code:
Original - php Code
  1. $query = "SELECT count(*) as total FROM table";
  2. $result = mysql_query($query);
  3. $row = mysql_fetch_array($result);
  4. $numrows = $row['total'];


HTH

Reply With Quote
  #3  
Old July 28th, 2002, 02:47 AM
Darth Evad Darth Evad is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 4 Darth Evad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Prev - Next link tutorial.

Still the same. I guess I should provide some code incase it's a problem elsewhere.
php Code:
Original - php Code
  1.  
  2. <?
  3.  
  4. $host = 'localhost';
  5. $user = 'evad';
  6. $password = 'evad';
  7. $db = 'darth';
  8.  
  9. if(!isset($start))
  10. {
  11.     $start=0;
  12. }
  13.  
  14. $link_id = mysql_connect($host, $user, $password);
  15. $query = ("SELECT * FROM dave ORDER BY refnum DESC LIMIT " . $start . ", 6");
  16. $result = mysql_query($query);
  17. $query = ("SELECT count(*) as total FROM apartment ORDER BY refnum DESC");
  18. $row = mysql_fetch_array($result);
  19. $numrows = $row['total']; //THIS IS WHERE THE UNDEFINED INDEX IS
  20.  
  21. while ($query_data = mysql_fetch_row($result))
  22. {
  23.     echo ("<table><tr><td rowspan=11><a href='images/example.jpg' target='any-window'><img src='images/example.jpg' alt='Your home in color' width='175' height='131' align='left'></a></td></tr><tr><td width=135>Name - </td><td>$query_data[0]</td></tr><tr><td>Phone number - </td><td>$query_data[1]</td></tr><tr><td>E-mail - <td><a class=mail href=mailto:$query_data[2]>$query_data[2]</a></td></tr><tr><td>Bedrooms - </td><td>$query_data[3]</td></tr><tr><td>Bathrooms - </td><td>$query_data[4]</td></tr><tr><td>Square feet - </td><td>$query_data[5]</td></tr><tr><td>Description - </td><td>$query_data[6]</td></tr><tr><td>Date submitted - </td><td>$query_data[7]</td></tr><tr><td>Reference number - </td><td>$query_data[8]</td></tr><tr><td><form><input type=submit name='approve' value='Approved'></form></td></tr></table><hr>");
  24. }
  25.  
  26. if($start > 0)
  27. {
  28.    echo "<div align="left"><a href="" . $PHP_SELF . "?start=" . ($start - 6) .
  29.         "">Previous Page</a></div>";
  30. }
  31. if($numrows > ($start + 6))
  32. {
  33.    echo "<div align="right"><a href="" . $PHP_SELF . "?start=" . ($start + 6) .
  34.         "">Next Page</a></div>";
  35. }
  36.  
  37. ?>

Reply With Quote
  #4  
Old July 28th, 2002, 03:08 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via Yahoo to EvilivE
RE: Prev - Next link tutorial.

OK, let me give this a shot.

First thing: There is no need to place parens, (), around you assignments to $query.
Second: Parens are not required for echo, take those out.
Third: to be consistent with the tutorial your echo statment is in the wrong place (and this is where your problem starts).

//You assigned $query to this string, take out parens
$query = ("SELECT * FROM dave ORDER BY refnum DESC LIMIT " . $start . ", 6");

// this is where you actually query the db
$result = mysql_query($query);

// then you assigned $query to this other string, take parens out
$query = ("SELECT count(*) as total FROM apartment ORDER BY refnum DESC");

// here you assign $row to the result set of your _FIRST_ query
$row = mysql_fetch_array($result);

// now your trying to use an index value total but this index value is in your second query that you never executed
$numrows = $row['total'];

I hope that makes a little sense.

Reply With Quote
  #5  
Old July 28th, 2002, 03:44 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 25
RE: Prev - Next link tutorial.

No. ;)
See my sig. :p

I understand what I've got now.
I don't understand why I am missing every 6th record starting with number 1.
I also don't understand why I get the undefined index.

Thanks though.

Reply With Quote
  #6  
Old July 28th, 2002, 04:52 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via Yahoo to EvilivE
RE: Prev - Next link tutorial.

Lets work on one problem at a time, the index thing.
It is more important to understand why it is happening as opposed to me giving you the code to fix it, feed a person for life mentality.

This is the logic:
a) build a query string
b) execute query
c) create an array with data
d) do something with data

// lets call this, ummmmm, FIRST_QUERY. now you have part "a" done
$query = ("SELECT * FROM dave ORDER BY refnum DESC LIMIT " . $start . ", 6");

// this is part "b" for FIRST_QUERY
$result = mysql_query($query);

// this is part "a" for SECOND_QUERY
$query = ("SELECT count(*) as total FROM apartment ORDER BY refnum DESC");

// this is part "c" for FIRST_QUERY
$row = mysql_fetch_array($result);

// this is part "d" of SECOND_QUERY
$numrows = $row['total'];

// this is again part "c" for FIRST_QUERY
while ($query_data = mysql_fetch_row($result))

Something is missing, right?

Reply With Quote
  #7  
Old July 28th, 2002, 05:15 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via Yahoo to EvilivE
RE: Prev - Next link tutorial.

Try this:
php Code:
Original - php Code
  1.  
  2. <?
  3. // THIS INFO SHOULD NEVER BE HERE!!!!!!!!!!!!!!!!!!!!!!!
  4. // PLACE IT IN A DIRECTORY OUTSIDE YOUR SERVERS DOCUMENT ROOT !!!!!!!!!!!!!
  5.  
  6. $host = 'localhost';
  7. $user = 'evad';
  8. $password = 'evad';
  9. $db = 'darth';
  10.  
  11. if(!isset($start))
  12. {
  13.     $start=0;
  14. }
  15.  
  16. // connect to mysql and select a db
  17. $link_id = mysql_connect($host, $user, $password);
  18.  
  19.  
  20. $query  = "SELECT * FROM dave ORDER BY refnum DESC LIMIT " . $start . ", 6";
  21. $result = mysql_query($query);
  22. while ($query_data = mysql_fetch_row($result)){ // you could use mysql_fetch_array() here, then you could access the indicies by "name"
  23.   echo "<table>
  24.           <tr>
  25.             <td rowspan=11><a href='images/example.jpg' target='any-window'><img src='images/example.jpg' alt='Your home in color' width='175' height='131' align='left'></a></td>
  26.           </tr>
  27.           <tr>
  28.             <td width=135>Name - </td>
  29.             <td>".$query_data[0]."</td>
  30.           </tr>
  31.           <tr>
  32.             <td>Phone number - </td>
  33.             <td>".$query_data[1]."</td>
  34.           </tr>
  35.           <tr>
  36.             <td>E-mail - </td>
  37.             <td><a class=mail href=mailto:".$query_data[2].">".$query_data[2]."</a></td>
  38.           </tr>
  39.           <tr>
  40.             <td>Bedrooms - </td>
  41.             <td>".$query_data[3]."</td>
  42.           </tr>
  43.           <tr>
  44.             <td>Bathrooms - </td>
  45.             <td>".$query_data[4]."</td>
  46.           </tr>
  47.           <tr>
  48.             <td>Square feet - </td>
  49.             <td>".$query_data[5]."</td>
  50.           </tr>
  51.           <tr>
  52.             <td>Description - </td>
  53.             <td>".$query_data[6]."</td>
  54.           </tr>
  55.           <tr>
  56.             <td>Date submitted - </td>
  57.             <td>".$query_data[7]."</td>
  58.           </tr>
  59.           <tr>
  60.             <td>Reference number - </td>
  61.             <td>".$query_data[8]."</td>
  62.           </tr>
  63.           <tr>
  64.             <td><form><input type=submit name='approve' value='Approved'></form></td>
  65.           </tr>
  66.         </table>
  67.         <hr>";
  68. }
  69.  
  70. $query   = "SELECT count(*) as total FROM apartment ORDER BY refnum DESC";
  71. $result  = mysql_query($query);
  72. $row     = mysql_fetch_array(result);
  73. $numrows = $row['total'];
  74.  
  75. if($start > 0)
  76. {
  77.    echo "<div align="left"><a href="" . $PHP_SELF . "?start=" . ($start - 6) .
  78.         "">Previous Page</a></div>";
  79. }
  80. if($numrows > ($start + 6))
  81. {
  82.    echo "<div align="right"><a href="" . $PHP_SELF . "?start=" . ($start + 6) .
  83.         "">Next Page</a></div>";
  84. }
  85.  
  86. ?>


It should get you started, _study_ it.

Reply With Quote
  #8  
Old July 28th, 2002, 05:43 AM
Darth Evad Darth Evad is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 4 Darth Evad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Prev - Next link tutorial.

OK! I get it. I kept looking for syntax rather than logic.
Thank you very much!

Reply With Quote
  #9  
Old July 28th, 2002, 05:47 AM
Darth Evad Darth Evad is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 4 Darth Evad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Prev - Next link tutorial.

Doh...
I just went back and looked at the tutorial.
It has
//display data
right where I should display my data.
After reading what you posted and seeing your example, I realized I had already read that.
Sorry about that and thanks again.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOtherTutorials > Prev - Next link tutorial.


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




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

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




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek