CGS - Forums

Please login or register.

Login with username, password and session length
Advanced search  

News:

Pages: [1]   Go Down

Author Topic: Q about a PHP script  (Read 1567 times)

0 Members and 1 Guest are viewing this topic.

Puritan

  • Administrator
  • Overlord
  • *****
  • Offline Offline
  • Posts: 1840
  • Beach Patrol
    • View Profile
    • Come Get Some
Q about a PHP script
« on: January 02, 2012, 06:55:55 PM »

I've added a small PHP script that counts rows from the database.
This is put on this page: http://www.scent-88.com/mapbase/maplistings.php
Now, the counter displays two more maps than it should (display=35 but there is only 33 maps registered)  :o
I think the script maybe are counting the first (zero) row and maybe the last row who is not filled in yet..


Code:


mysql_select_db ("database"); 
$result = mysql_query("SELECT * FROM table"); 
 
$num_rows = mysql_num_rows($result); 
 
// Display the results 
 
echo $num_rows;




Anyone have an idea on how to change the script?
« Last Edit: April 23, 2012, 09:40:44 PM by Puritan »
Logged
Grammar - The difference between knowing your shit and knowing you're shit

Forge

  • Overlord
  • *****
  • Offline Offline
  • Posts: 2084
    • View Profile
Re: Computers & software
« Reply #1 on: January 02, 2012, 07:54:26 PM »

If nobody here has an answer, Tx at Duke4 might know.
Logged
Take it down to the beach with a hammer and pound sand up your ass

Puritan

  • Administrator
  • Overlord
  • *****
  • Offline Offline
  • Posts: 1840
  • Beach Patrol
    • View Profile
    • Come Get Some
Re: Computers & software
« Reply #2 on: January 02, 2012, 08:35:41 PM »

I also tried this code:
Guess what?
Same result  :-[


$query = ("SELECT * FROM $table"); 
 
$result = mysql_query($query) or die("Error in query: $query. " .
$row = mysql_fetch_row($result);

$columnCount = count($row);


Logged
Grammar - The difference between knowing your shit and knowing you're shit

Forge

  • Overlord
  • *****
  • Offline Offline
  • Posts: 2084
    • View Profile
Re: Computers & software
« Reply #3 on: January 02, 2012, 09:22:00 PM »

some examples from google searching:


mysql_select_db("database", $link);

$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";

----------------------------------------------------------

$query = "SELECT type, COUNT(name) FROM products GROUP BY type";
   
$result = mysql_query($query) or die(mysql_error());

----------------------------------------------------------

$query = "SELECT COUNT(1) FROM table");
$result = mysql_query($query) or die(mysql_error());

$row = mysql_fetch_row($result);

echo $row[0];

-------------------------------------------------------

Logged
Take it down to the beach with a hammer and pound sand up your ass

Puritan

  • Administrator
  • Overlord
  • *****
  • Offline Offline
  • Posts: 1840
  • Beach Patrol
    • View Profile
    • Come Get Some
Re: Computers & software
« Reply #4 on: January 02, 2012, 10:22:05 PM »

^Thanks for your input  ;)
I've tried those too...


But I found one error: Now there is 35 maps in the base but it displays 36.
The last 'extra' entry must be the (zero) line in SQL base.
I don't dare to delete that line at this stage.


I think we have to live with that 'extra' map for a while  :)
Logged
Grammar - The difference between knowing your shit and knowing you're shit
Pages: [1]   Go Up
 

Page created in 0.386 seconds with 20 queries.