The PHP that is confusing me is the following, where 'page' is the first value after LIMIT. I don't understand how to retrieve the variable 'page'.
Code: Select all
if ($_GET[‘page’]==NULL){
$start = 0;
} else {
$start = $_GET[‘page’];
}Moderator: General Moderators
Code: Select all
if ($_GET[‘page’]==NULL){
$start = 0;
} else {
$start = $_GET[‘page’];
}Code: Select all
$limit = 3;
$page = ($_GET['page'] > 0) ? $_GET['page'] : 1;
if ($village == 'G63') {
$sql= "SELECT count(*) as total FROM table WHERE Name LIKE '%$businesstype%' OR (Type LIKE '%$businesstype%' OR Keywords LIKE '%$businesstype%')";
}
else{
$sql= "SELECT count(*) as total FROM table WHERE Village = '$village' AND (Name LIKE '%$businesstype%' OR Type LIKE '%$businesstype%' OR Keywords LIKE '%$businesstype%')";
}
$result= mysql_query($sql);
$record = mysql_fetch_object($result);
$total = $record->total;
$num_pages = ceil($total/$limit);
$page = ($page <= 0) ? 1 : $page;
$page = ($page > $num_pages) ? $num_pages : $page;
$html[] = "<a href=\"Results3.php?page=" .($page-1)."\">Prev</a>";
for ($x=1; $x<=$num_pages; $x++) {
$html[] = "<a href=\"Results3.php?page=".$x."\".$x</a>";
}
$html[] = "<a href=\"Results3.php?page=".($page+1)."\">Next</a>";
echo implode(" | ",$html);
if ($village == 'G63') {
$sql= "SELECT * FROM table WHERE Name LIKE '%$businesstype%' OR (Type LIKE '%$businesstype%' OR Keywords LIKE '%$businesstype%') LIMIT ".(($page-1)*$limit).",".limit;
}
else {
$sql= "SELECT * FROM table WHERE Village = '$village' AND (Name LIKE '%$businesstype%' OR Type LIKE '%$businesstype%' OR Keywords LIKE '%$businesstype%') LIMIT ".(($page-1)*$limit).",".limit;
}
//What seems to be happening is that the following statement
//is always returning 0.
if (mysql_num_rows($sql)==0) {
echo "<p>There are currently no businesses in the directory that match your search.</p>
<p>Tip: Try using broader search terms; eg. 'farm', rather than 'farmers'</p>";
}
else{
while ($row = mysql_fetch_row($sql)) {
print "<p><b>$row[1]</b><br/>\n
$row[8]<br/>\n
$row[2], $row[3]<br/>\n
$row[4]<br/>\n
$row[5]<br/>\n
phone: $row[6]<br/>\n
fax: $row[7]<br/>\n
email: <a href=\"mailto:$row[9]\">$row[9]</a><br/>\n
web: <a href=\"http://$row[10]\" target=\"_blank\">$row[10]</a><br/>\n
</p>";
}
}Code: Select all
$businesstype= ($_GET['businesstype']);
$village= ($_GET['village']);Code: Select all
<?php
// Connect to database
$databasename= "XXX";
$username = "XXX";
$table = "XXX";
$password = "XXX";
$db = mysql_connect("$host", "$username", "$password");
mysql_select_db("$databasename", $db);
$num_rows = mysql_num_rows(mysql_query("SELECT * FROM $table"));
$limit = 10; // this many per page
$id=$_GET['id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("SELECT * FROM $table LIMIT $id, $limit");
echo '<table border="1">'."\n";
while($row=mysql_fetch_array($results)) {
$record=$row['id'];
$address=$row["address"];
$city=$row["city"];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td><td>'.$city.'</td></tr>'."\n";
}
echo '</table>';
// show previous link
if ($id>=$limit) {
$prev=$id-$limit;
echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$prev.'">prev</a>';
//i'm guessing the above is what i need to alter?
} else {
echo '<span style="color: #999999;">prev</span>';
}
echo ' ';
// show next link
if ($id<($num_rows - $limit)) {
$next=$id+$limit;
echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$next.'">next</a>';
} else {
echo '<span style="color: #999999;">next</span>';
}
?>Code: Select all
$result = mysql_query("SELECT * FROM table WHERE Name LIKE '%$businesstype%' OR (Type LIKE '%$businesstype%' OR Keywords LIKE '%$businesstype%') LIMIT $id, $limit");Code: Select all
<?php
// Connect to database
$databasename= "XXX";
$username = "XXX";
$table = "XXX";
$password = "XXX";
$db = mysql_connect("$host", "$username", "$password");
mysql_select_db("$databasename", $db);
$num_rows = mysql_num_rows(mysql_query("SELECT * FROM $table"));
$limit = 10; // this many per page
$id=$_GET['id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("SELECT * FROM $table LIMIT $id, $limit");
echo '<table border="1">'."\n";
while($row=mysql_fetch_array($results)) {
$record=$row['id'];
$address=$row["address"];
$city=$row["city"];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td><td>'.$city.'</td></tr>'."\n";
}
echo '</table>';
// show previous link
if ($id>=$limit) {
$prev=$id-$limit;
echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$prev.'">prev</a>';
//i'm guessing the above is what i need to alter?
} else {
echo '<span style="color: #999999;">prev</span>';
}
echo ' ';
// show next link
if ($id<($num_rows - $limit)) {
$next=$id+$limit;
echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$next.'">next</a>';
} else {
echo '<span style="color: #999999;">next</span>';
}
?>Code: Select all
$result = mysql_query("e;SELECT * FROM table WHERE Name LIKE '%$businesstype%' OR (Type LIKE '%$b me if i pare my query down to 'select * from table'. Trouble is my query contains a WHERE clause and whenever I click the 'next' link, the next page contains unfiltered data as if the query had just been SELECT * FROM table.
I'm guessing I somehow need to adapt the echo statement for the links at the end?
Here's charp's code:Code: Select all
<?php
// Connect to database
$databasename= "e;XXX"e;;
$username = "e;XXX"e;;
$table = "e;XXX"e;;
$password = "e;XXX"e;;
$db = mysql_connect("e;$host"e;, "e;$username"e;, "e;$password"e;);
mysql_select_db("e;$databasename"e;, $db);
$num_rows = mysql_num_rows(mysql_query("e;SELECT * FROM $table"e;));
$limit = 10; // this many per page
$id=$_GETї'id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("e;SELECT * FROM $table LIMIT $id, $limit"e;);
echo '<table border="e;1"e;>'."e;\n"e;;
while($row=mysql_fetch_array($results)) {
$record=$rowї'id'];
$address=$rowї"e;address"e;];
$city=$rowї"e;city"e;];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td><td>'.$city.'</td></tr>'."e;\n"e;;
}
echo '</table>';
// show previous link
if ($id>=$limit) {
$prev=$id-$limit;
echo '<a href="e;'.$_SERVERї'PHP_SELF'].'?id='.$prev.'"e;>prev</a>';
//i'm guessing the above is what i need to alter?
} else {
echo '<span style="e;color: #999999;"e;>prev</span>';
}
echo '&nbsp;&nbsp;&nbsp;&nbsp;';
// show next link
if ($id<($num_rows - $limit)) {
$next=$id+$limit;
echo '<a href="e;'.$_SERVERї'PHP_SELF'].'?id='.$next.'"e;>next</a>';
} else {
echo '<span style="e;color: #999999;"e;>next</span>';
}
?>Code: Select all
$re Trouble is my query contains a WHERE clause and whenever I click the 'next' link, the next page contains unfiltered data as if the query had just been SELECT * FROM table.
I'm guessing I somehow need to adapt the echo statement for the links at the end?
Here's charp's code:Code: Select all
<?php
// Connect to database
$databasename= "e;XXX"e;;
$username = "e;XXX"e;;
$table = "e;XXX"e;;
$password = "e;XXX"e;;
$db = mysql_connect("e;$host"e;, "e;$username"e;, "e;$password"e;);
mysql_select_db("e;$databasename"e;, $db);
$num_rows = mysql_num_rows(mysql_query("e;SELECT * FROM $table"e;));
$limit = 10; // this many per page
$id=$_GETї'id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("e;SELECT * FROM $table LIMIT $id, $limit"e;);
echo '<table border="e;1"e;>'."e;\n"e;;
while($row=mysql_fetch_array($results)) {
$record=$rowї'id'];
$address=$rowї"e;address"e;];
$city=$rowї"e;city"e;];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td><td>'.$city.'</td></tr>'."e;\n"e;;
}
echo '</table>';
// show previous link
if ($id>=$limit) {
$prev=$id-$limit;
echo '<a href="e;'.$_SERVERї'PHP_SELF'].'?id='.$prev.'"e;>prev</a>';
//i'm guessing the above is what i need to alter?
} else {
echo '<span style="e;color: #999999;"e;>prev</span>';
}
echo '&nbsp;&nbsp;&nbsp;&nbsp;';
// show next link
if ($id<($num_rows - $limit)) {
$next=$id+$limit;
echo '<a href="e;'.$_SERVERї'PHP_SELF'].'?id='.$next.'"e;>next</a>';
} else {
echo '<span style="e;color: #999999;"e;>next</span>';
}
?>Code: Select all
$result = mysql_query("e;SELECT * FROMelect * from table'. Trouble is my query contains a WHERE clause and whenever I click the 'next' link, the next page contains unfiltered data as if the query had just been SELECT * FROM table.
I'm guessing I somehow need to adapt the echo statement for the links at the end?
Here's charp's code:Code: Select all
<?php
// Connect to database
$databasename= "XXX";
$username = "XXX";
$table = "XXX";
$password = "XXX";
$db = mysql_connect("$host"e;, "e;$username"e;, "e;$password"e;);
mysql_select_db("e;$databasename"e;, $db);
$num_rows = mysql_num_rows(mysql_query("e;SELECT * FROM $table"e;));
$limit = 10; // this many per page
$id=$_GETї'id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("e;SELECT * FROM $table LIMIT $id, $limit"e;);
echo '<table border="e;1"e;>'."e;\n"e;;
while($row=mysql_fetch_array($results)) {
$record=$rowї'id'];
$address=$rowї"e;address"e;];
$city=$rowї"e;city"e;];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td><td>'.$city.'</td></tr>'."e;\n"e;;
}
echo '</table>';
// show previous link
if ($id>=$limit) {
$prev=$id-$limit;
echo '<a href="e;'.$_SERVERї'PHP_SELF'].'?id='.$prev.'"e;>prev</a>';
//i'm guessing the above is what i need to alter?
} else {
echo '<span style="e;color: #999999;"e;>prev</span>';
}
echo '&nbsp;&nbsp;&nbsp;&nbsp;';
// show next link
if ($id<($num_rows - $limit)) {h this one, but i did find code in another post by charp that works for me if i pare my query down to 'select * from table'. Trouble is my query contains a WHERE clause and whenever I click the 'next' link, the next page contains unfiltered data as if the query had just been SELECT * FROM table.
I'm guessing I somehow need to adapt the echo statement for the links at the end?
Here's charp's code:Code: Select all
<?php
// Connect to database
$databasename= "XXX";
$username = "XXX";
$table = "XXX";
$password = "XXX";
$db = mysql_connect("$host", "$username", "$password");
mysql_select_db("$databasename", $db);
$num_rows = mysql_num_rows(mysql_query("SELECT * FROM $table"));
$limit = 10; // this many per page
$id=$_GET['id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("SELECT * FROM $table LIMIT $id, $limit");
echo '<table border="1">'."\n";
while($row=mysql_fetch_array($results)) {
$record=$row['id'];
$address=$row["address"];
$city=$row["city"];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td><td>'.$city.'</td></tr>'."\n";
}
echo '</table>';
// show previous link
if ($id>=$limit) {
$prev=$id-$limit;
echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$prev.'">prev</a>';
//i'm guessing the above is what i need to alter?
} else {
echo '<span style="color: #999999;">prev</span>';
}
echo ' ';
// show next link
if ($id<($num_rows - $limit)) {
$next=$id+$limit;
echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$next.'">next</a>';
} else {
echo '<span style="color: #999999;">next</span>';
}
?>Code: Select all
$result = mysql_query("SELECT * FROM table WHERE Name LIKE '%$businesstype%' OR (Type LIKE '%$businesstype%' OR Keywords LIKE '%$businesstype%') LIMIT $id, $limit");Code: Select all
<?php
// Connect to database
$databasename= "XXX";
$username = "XXX";
$table = "XXX";
$password = "XXX";
$db = mysql_connect("$host", "$username", "$password");
mysql_select_db("$databasename", $db);
$num_rows = mysql_num_rows(mysql_query("SELECT * FROM $table"));
$limit = 10; // this many per page
$id=$_GET['id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("SELECT * FROM $table LIMIT $id, $limit");
echo '<table border="1">'."\n";
while($row=mysql_fetch_array($results)) {
$record=$row['id'];
$address=$row["address"];
$city=$row["city"];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td><td>'.$city.'</td></tr>'."\n";
}
echo '</table>';
// show previous link
if ($id>=$limit) {
$prev=$id-$limit;
echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$prev.'">prev</a>';
//i'm guessing the above is what i need to alter?
} else {
echo '<span s;quote;XXX";
$db = mysql_connect("$host", "$username", "$password");
mysql_select_db("$databasename", $db);
$num_rows = mysql_num_rows(mysql_query("SELECT * FROM $table"));
$limit = 10; // this many per page
$id=$_GET['id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("SELECT * FROM $table LIMIT $id, $limit");
echo '<table border="1">'."\n";
while($row=mysql_fetch_array($results)) {
$record=$row['id'];
$address=$row["address"];
$city=$row["city"];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td><td>'.$city.'</td></tr>'."\n";
}
echo '</table>';
// show previous link
if ($id>=$limit) {
$prev=$id-$limit;
echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$prev.'">prev</a>';
//i'm guessing the above is what i need to alter?
} else {
echo '<span style="color: #999999;">prev</span>';
}
echo ' ';
// show next link
if ($id<($num_rows - $limit)) {
$next=$id+$limit;
echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$next.'">next</a>';
} else {
echo '<span style="color: #999999;">next</span>';
}
?>Code: Select all
$result = mysql_query("SELECT * FROM table WHERE Name LIKE '%$businesstype%' OR (Type LIKE '%$businesstype%' OR Keywords LIKE '%$businesstype%') LIMIT $id, $limit");Code: Select all
<?php
// Connect to database
$databasename= "XXX";
$username = "XXX";
$table = "XXX";
$password = "XXX";
$db = mysql_connect("$host", "$username", "$password");
mysql_select_db("$databasename"e;, $db);
$num_rows = mysql_num_rows(mysql_query("e;SELECT * FROM $table"e;));
$limit = 10; // this many per page
$id=$_GETї'id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("e;SELECT * FROM $table LIMIT $id, $limit"e;);
echo '<table border="e;1"e;>'."e;\n"e;;
while($row=mysql_fetch_array($results)) {
$record=$rowї'id'];
$address=$rowї"e;address"e;];
$city=$rowї"e;city"e;];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td><td>'.$city.'</td></tr>'."e;\n"e;;
}
echo '</table>';
// show previous link
if ($id>=$limit) {
$prev=$id-$limit;
echo '<a href="e;'.$_SERVERї'PHP_SELF'].'?id='.$prev.'"e;>prev</a>';
//i'm guessing the above is what i need to alter?
} else {
echo '<span style="e;color: #999999;"e;>prev</span>';
}
echo '&nbsp;&nbsp;&nbsp;&nbsp;';
// show next link
if ($id&l down to 'select * from table'. Trouble is my query contains a WHERE clause and whenever I click the 'next' link, the next page contains unfiltered data as if the query had just been SELECT * FROM table.
I'm guessing I somehow need to adapt the echo statement for the links at the end?
Here's charp's code:Code: Select all
<?php
// Connect to database
$databasename= "e;XXX"e;;
$username = "e;XXX"e;;
$table = "e;XXX"e;;
$password = "e;XXX"e;;
$db = mysql_connect("e;$host"e;, "e;$username"e;, "e;$password"e;);
mysql_select_db("e;$databasename"e;, $db);
$num_rows = mysql_num_rows(mysql_query("e;SELECT * FROM $table"e;));
$limit = 10; // this many per page
$id=$_GETї'id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("e;SELECT * FROM $table LIMIT $id, $limit"e;);
echo '<table border="e;1"e;>'."e;\n"e;;
while($row=mysql_fetch_array($results)) {
$record=$rowї'id'];
$address=$rowї"e;address"e;];
$city=$rowї"e;city"e;];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td><td>'.$city.'</td></tr>'."e;\n"e;;
}
echo '</table>';
// show previous link
if ($id>=$limit) {
$prev=$id-$limit;
echo '<a href="e;'.$_SERVERї'PHP_SELF'].'?id='.$prev.'"e;>prev</a>';
//i'm guessing the above is what i need to alter?
} else {
echo '<span style="e;color: #999999;"e;>prev</span>';
}
echo '&nbsp;&nbsp;&nbsp;&nbsp;';
// show next link
if ($id<($num_rows - $limit)) {
$next=$id+$limit;
echo '<a href="e;'.$_SERVERї'PHP_SELF'].'?id='.$next.'"e;>next</a>';
} else {
echo '<span style="e;color: #999999;"her post by charp that works for me if i pare my query down to 'select * from table'. Trouble is my query contains a WHERE clause and whenever I click the 'next' link, the next page contains unfiltered data as if the query had just been SELECT * FROM table.
I'm guessing I somehow need to adapt the echo statement for the links at the end?
Here's charp's code:Code: Select all
<?php
// Connect to database
$databasename= "e;XXX"e;;
$username = "e;XXX"e;;
$table = "XXX";
$password = "XXX";
$db = mysql_connect("$host", "$username", "$password");
mysql_select_db("$databasename", $db);
$num_rows = mysql_num_rows(mysql_query("SELECT * FROM $table"));
$limit = 10; // this many per page
$id=$_GET['id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("e;SELECT * FROM $table LIMIT $id, $limit"e;);
echo '<table border="e;1"e;>'."e;\n"e;;
while($row=mysql_fetch_array($results)) {
$record=$rowї'id'];
$address=$rowї"e;address"e;];
$city=$rowї"e;city"e;];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td><td>'.$city.'</td></tr>'."e;\n"e;;
}
echo '</table>';
// show previous link
if ($id>=$limit) {
$prev=$id-$limit;
echo '<a href="e;'.$_SERVERї'PHP_SELF'].'?id='.$prev.'"e;>prev</a>';
//i'm guessing the above is what i need to alter?
} else {
echo '&he 'next' link, the next page contains unfiltered data as if the query had just been SELECT * FROM table.
I'm guessing I somehow need to adapt the echo statement for the links at the end?
Here's charp's code:Code: Select all
<?php
// Connect to database
$databasename= "e;XXX"e;;
$username = "e;XXX"e;;
$table = "e;XXX"e;;
$password = "e;XXX"e;;
$db = mysql_connect("e;$host"e;, "e;$username"e;, "e;$password"e;);
mysql_select_db("e;$databasename"e;, $db);
$num_rows = mysql_num_rows(mysql_query("e;SELECT * FROM $table"e;));
$limit = 10; // this many per page
$id=$_GETї'id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("e;SELECT * FROM $table LIMIT $id, $limit"e;);
echo '<table border="e;1"e;>'."e;\n"e;;
while($row=mysql_fetch_array($results)) {
$record=$rowї'id'];
$address=$rowї"e;address"e;];
$city=$rowї"e;city"e;];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td><td>'.$city.'</td></tr>'."e;\n"e;;
}
echo '</table>';
// show previous link
if ($id>=$limit) {
$prev=$id-$limit;
echo '<a href="e;'.$_SERVERї'PHP_SELF'].'?id='.$prev.'"e;>prev</a>';
//i'm guessing the above is what i need to alter?
} else {
echo '<span style="e;color: #999999;"e;>prev</span>';
}
echo '&nbsp;&nbsp;&nbsp;&nbsp;';
// show next link
if ($id<($num_rows - $limit)) {
$next=$id+$limit;
echo '<a href="e;'.$_SERVERї'PHP_SELF'].'?id='.$next.'"e;>next</a>';
} else {
echo '<span style="e;color: #999999;"e;>next</span>';
}
?>Code: Select all
$result = mysql_query("SELECT * FROM table WHERE Name LIKE '%$businesstype%' OR (Type LIKE '%$businesstype%' OR Keywords LIKE '%$businesstype%') LIMIT $id, $limit");Code: Select all
<?php
// Connect to database
$databasename= "XXX";
$username = "XXX";
$table = "XXX";
$password = "XXX";
$db = mysql_connect("$host", "$username", "$password");
mysql_select_db("$databasename", $db);
$num_rows = mysql_num_rows(mysql_query("SELECT * FROM $table"));
$limit = 10; // this many per page
$id=$_GETї'id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("e;SELECT * FROM $table LIMIT $id, $limit"e;);
echo '<table border="e;1"e;>'."e;\n"e;;
while($row=mysql_fetch_array($results)) {
$record=$rowї'id'];
$address=$rowї"e;address"e;];
$city=$rowї"e;city"e;];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td><td>'.$city.'</td></tr>'."e;\n"e;;
}
echo '</table>';
// show previous link
if ($id>=$limit) {
$prev=$id-$limit;
echo '<a href="e;'.$_SERVERї'PHP_SELF'].'?id='.$prev.'"e;>prev</a>';
//i'm guessing the above is what i need to alter?
} else {
echo '<sput i did find code in another post by charp that works for me if i pare my query down to 'select * from table'. Trouble is my query contains a WHERE clause and whenever I click the 'next' link, the next page contains unfiltered data as if the query had just been SELECT * FROM table.
I'm guessing I somehow need to adapt the echo statement for the links at the end?
Here's charp's code:Code: Select all
<?php
// Connect to database
$databasename= "XXX";
$username = "XXX";
$table = "XXX";
$password = "XXX";
$db = mysql_connect("$host", "$username", "$password");
mysql_select_db("$databasename", $db);
$num_rows = mysql_num_rows(mysql_query("SELECT * FROM $table"));
$limit = 10; // this many per page
$id=$_GET['id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("SELECT * FROM $table LIMIT $id, $limit");
echo '<table border="1">'."\n";
while($row=mysql_fetch_array($results)) {
$record=$row['id'];
$address=$row["address"];
$city=$row["city"];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td>&the query had just been SELECT * FROM table.
I'm guessing I somehow need to adapt the echo statement for the links at the end?
Here's charp's code:Code: Select all
<?php
// Connect to database
$databasename= "XXX";
$username = "XXX";
$table = "XXX";
$password = "XXX";
$db = mysql_connect("$host", "$username", "$password");
mysql_select_db("$databasename", $db);
$num_rows = mysql_num_rows(mysql_query("SELECT * FROM $table"));
$limit = 10; // this many per page
$id=$_GET['id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("SELECT * FROM $table LIMIT $id, $limit");
echo '<table border="1">'."\n";
while($row=mysql_fetch_array($results)) {
$record=$row['id'];
$address=$row["address"];
$city=$row["city"];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td><td>'.$city.'</td></tr>'."\n";
}
echo '</table>';
// show previous link
if ($id>=$limit) {
$prev=$id-$limit;
echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$prev.'">prev</a>';
//i'm guessing the above is what i need to alter?
} else {
echo '<span style="color: #999999;">prev</span>';
}
echo ' ';
// show next link
if ($id<($num_rows - $limit)) {
$next=$id+$limit;
echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$next.'">next</a>';
} else {
echo '<span style="color: #999999;">next</span>';
}
?>Code: Select all
$result = mysql_query("SELECT * FROM table WHERE Name LIKE '%$businesstype%' OR (Type LIKE '%$businesstype%' OR Keywords LIKE '%$businesstype%') LIMIT $id, $limit");Code: Select all
<?php
// Connect to database
$databasename= "XXX";
$username = "XXX";
$table = "XXX";
$password = "XXX";
$db = mysql_connect("$host", "$username", "$password");
mysql_select_db("$databasename", $db);
$num_rows = mysql_num_rows(mysql_query("SELECT * FROM $table"));
$limit = 10; // this many per page
$id=$_GET['id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("SELECT * FROM $table LIMIT $id, $limit");
echo '<table border="1">'."\n";
while($row=mysql_fetch_array($results)) {
$record=$row['id'];
$address=$row["address"];
$city=$row["city"];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td><td>'.$city.'</td></tr>'."\n";
}
echo '</table>';
// show previous link
if ($id>=$limit) {
$prev=$id-$limit;
echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$prev.'">prev</a>';
//i'm guessing the above is what i need to alter?
} else {
echo '<span style="color: #999999;">prev</span>';
}
echo ' ';
// show next link
if ($id<($num_rows - $limit)) {
$next=$id+$limit;
echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$next.'">next</a>';
} else {
echo '<span style="color: #999999;">next</span>';
}
?>Code: Select all
$result = mysql_query("SELECT * FROM table WHERE Name LIKE '%$businesstype%' OR (Type LIKE '%$businesstype%' OR Keywords LIKE '%$businesstype%') LIMIT $id, $limit");Code: Select all
$result = mysql_query("SELECT * FROM table WHERE Name LIKE '%$businesstype%' OR (Type LIKE '%$businesstype%' OR Keywords LIKE '%$businesstype%') LIMIT $id, $limit");Code: Select all
<?php
// Connect to database
$databasename= "XXX";
$username = "XXX";
$table = "XXX";
$password = "XXX";
$db = mysql_connect("$host", "$username", "$password");
mysql_select_db("$databasename", $db);
$num_rows = mysql_num_rows(mysql_query("SELECT * FROM $table"));
$limit = 10; // this many per page
$id=$_GET['id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("SELECT * FROM $table LIMIT $id, $limit");
echo '<table border="1">'."\n";
while($row=mysql_fetch_array($results)) {
$record=$row['id'];
$address=$row["address"];
$city=$row["city"];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td><td>'.$city.'</td></tr>'."\n";
}
echo '</table>';
// show previous link
if ($id>=$limit) {
$prev=$id-$limit;
echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$prev.'">prev</a>';
//i'm guessing the above is what i need to alter?
} else {
echo '<span style="color: #999999;">prev</span>';
}
echo ' ';
// show next link
if ($id<($num_rows - $limit)) {
$next=$id+$limit;
echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$next.'">next</a>';
} else {
echo '<span style="color: #999999;">next</span>';
}
?>Code: Select all
$result = mysql_query("e;SELECT * FROM table WHERE Name LIKE '%$businesstype%' OR (Type LIKE '%$buLECT * FROM table.
I'm guessing I somehow need to adapt the echo statement for the links at the end?
Here's charp's code:Code: Select all
<?php
// Connect to database
$databasename= "XXX";
$username = "XXX";
$table = "XXX";
$password = "XXX";
$db = mysql_connect("$host", "$username", "$password");
mysql_select_db("$databasename", $db);
$num_rows = mysql_num_rows(mysql_query("SELECT * FROM $table"));
$limit = 10; // this many per page
$id=$_GETї'id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("e;SELECT * FROM $table LIMIT $id, $limit"e;);
echo '<table border="e;1"e;>'."e;\n"e;;
while($row=mysql_fetch_array($results)) {
$record=$rowї'id'];
$address=$rowї"e;address"e;];
$city=$rowї"e;city"e;];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td><td>'.$city.'</td></tr>'."e;\n"e;;
}
echo '</table>';
// show previous link
if ($id>=$limit) {
$prev=$id-$limit;
echo '<a href="e;'.$_SERVERї'PHP_SELF'].'?id='.$prev.'"e;>prev</a>';
//i'm guessing the above is what i need to alter?
} else {
echo '<span style="e;color: #999999;"e;>prev</span>';
}
echo '&nbsp;&nbsp;&nbsp;&nbsp;';
// show next link
if ($id<($num_rows - $limit)) {
$next=$id+$limit;
echo '<a href="e;'.$_SERVERї'PHP_SELF'].'?id='.$next.'"e;>next</a>';
} else {
echo '<span style="e;color: #999999;"e;>next</span>';
}
?>
[XXX";
$password = "XXX";
$db = mysql_connect("$host", "$username", "$password");
mysql_select_db("$databasename", $db);
$num_rows = mysql_num_rows(mysql_query("SELECT * FROM $table"));
$limit = 10; // this many per page
$id=$_GET['id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("SELECT * FROM $table LIMIT $id, $limit");
echo '<table border="e;1"e;>'."e;\n"e;;
while($row=mysql_fetch_array($results)) {
$record=$rowї'id'];
$address=$rowї"e;address"e;];
$city=$rowї"e;city"e;];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td><td>'.$city.'</td></tr>'."e;\n"e;;
}
echo '</table>';
// show previouh this one, but i did find code in another post by charp that works for me if i pare my query down to 'select * from table'. Trouble is my query contains a WHERE clause and whenever I click the 'next' link, the next page contains unfiltered data as if the query had just been SELECT * FROM table.
I'm guessing I somehow need to adapt the echo statement for the links at the end?
Here's charp's code:Code: Select all
<?php
// Connect to database
$databasename= "XXX";
$username = "XXX";
$table = "XXX";
$password = "XXX";
$db = mysql_connect("$host", "$username", "$password");
mysql_select_db("$databasename", $db);
$num_rows = mysql_num_rows(mysql_query("SELECT * FROM $table"));
$limit = 10; // this many per page
$id=$_GET['id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("SELECT * FROM $table LIMIT $id, $limit");
echo '<table border="1">'."\n";
while($row=mysql_fetch_array($results)) {
$record=$row['id'];
$address=$row["address"];
$city=$row["city"];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td><td>'.$city.'</td></tr>'."\n";
}
echo '</table>';
// show previous link
if ($id>=$limit) {
$prev=$id-$limit;
echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$prev.'">prev</a>';
//i'm guessing the above is what i need to alter?
} else {
echo '<span style="color: #999999;">prev</span>';
}
echo ' ';
// show next link
if ($id<($num_rows - $limit)) {
$next=$id+$limit;
echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$next.'">next</a>';
} else {
echo '<span style="color: #999999;">next</span&g
<?php
// Connect to database
$databasename= "XXX";
$username = "XXX";
$table = "XXX";
$password = "XXX";
$db = mysql_connect("$host", "$username", "$password");
mysql_select_db("$databasename", $db);
$num_rows = mysql_num_rows(mysql_query("SELECT * FROM $table"));
$limit = 10; // this many per page
$id=$_GET['id']; // which record to display next
// start with the first row
if (!isset($id)) {
$id=0;
} else {
$id = $id;
}
// grab data from database
$results=mysql_query("SELECT * FROM $table LIMIT $id, $limit");
echo '<table border="1">'."\n";
while($row=mysql_fetch_array($results)) {
$record=$row['id'];
$address=$row["address"];
$city=$row["city"];
echo '<tr><td>'.$record.'</td><td>'.$address.'</td><td>'.$city.'</td></tr>'."\n";
}
echo '</table>';
// show previous link
if ($id>=$limit) {
$prev=$id-$limit;
echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$prev.'">prev</a>';
//i'm guessing the above is what i need to alter?
} else {
echo '<span style="color: #999999;">prev</span>';
}
echo ' ';
// show next link
if ($id<($num_rows - $limit)) {
$next=$id+$limit;
echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$next.'">next</a>';
} else {
echo '<span style="color: #999999;">next</span>';
}
?>Code: Select all
$result = mysql_query("SELECT * FROM table WHERE Name LIKE '%$businesstype%' OR (Type LIKE '%$businesstype%' OR Keywords LIKE '%$businesstype%') LIMIT $id, $limit");