You seem to be creating a new table on every iteration - perhaps it would be better to just add a row on every iteration of the while loop. OK, quite a few things. Here's refactored code - it contains html formatting (\n\t) - take them out if you want.
$host="xxxxxx"; // Host name
$username="xxx_username"; // Mysql username
$password="xxx_password"; // Mysql password
$db_name="xxx_databasename"; // Database name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$per_page = 6;
$pages_query = mysql_query("SELECT COUNT (*) FROM 'xxx_tablename'");
$pages = ceil(mysql_num_rows($pages_query) / $per_page);
//pre page - hold putative page number from input (or = 1)
$pre_page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
//set proper page number - ensure in range
if($pre_page < 1){
$page = 1;
}elseif($pre_page > $pages){
$page = $pages;
}else{
$page = $pre_page;
}
$start = ($page - 1) * $per_page;
$query = mysql_query("SELECT * FROM `members_list` LIMIT $start, $per_page");
$output = "<table id='table-3'>\n\t<thead>\n\t\t<tr>\n\t\t\t<th> Name : </th>\n\t\t\t<th> Address : </th>\n\t\t\t<th>Zip Code : </th>\n\t\t</tr>\n\t</thead>\n\t<tbody>";
while ($query_row = mysql_fetch_assoc($query)){
$output .= "\n\t\t<tr>\n\t\t\t<td>{$query_row['name']}</td>\n\t\t\t<td>{$query_row['address']}</td>\n\t\t\t<td>{$query_row['zipcode']}</td>\n\t\t</tr>";
}
$output .= "\n\t</tbody>\n</table>";
echo $output;
// close MySQL connection
mysql_close();
I think your main problem was that you had single quotes around the table name. For this use `backticks` instead
diafol
Keep Smiling
10,681 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
Sorry edited my post while you posted. See above.
diafol
Keep Smiling
10,681 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
No this again:
SELECT COUNT (*) FROM 'xxx_tablename'
should be
SELECT COUNT (*) AS cnt FROM `xxx_tablename`
AND
$pages = ceil(mysql_num_rows($pages_query) / $per_page);
COULD BE
$data = mysql_fetch_assoc($pages_query);
$cnt = $data['cnt'];
$pages = ceil($cnt / $per_page);
diafol
Keep Smiling
10,681 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
SO what's not working?
echo out bits of code as you go along, e.g.
echo $cnt;
etc. That should give you an idea of the current values / state of your variables.
diafol
Keep Smiling
10,681 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
Please no PMs. Everything to the forum. Anyway, looked at the site/code. You've still got single quotes about your table names. Change them to backticks (`).
diafol
Keep Smiling
10,681 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57