Jump to content

Display Tables Controls help!!


mapmedia

Recommended Posts

How do I add 'startrow' to an existing query (i.e. where state=california)?

 

 

$id=$_GET['state'];

ini_set ("display_errors", "1");

error_reporting(E_ALL);

 

$sqlCommand = "SELECT * FROM COUNTIES where state = '$id' LIMIT 0, 10";

$result = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());

 

$fields_num = mysqli_num_fields($result);

 

echo "<h1>Test Table</h1>";

echo "<table border='1'><tr>";

// printing table headers

for($i=0; $i<$fields_num; $i++)

{

    $field = mysqli_fetch_field($result);

    echo "<td>{$field->name}</td>";

}

echo "</tr>\n";

// printing table rows

while($row = mysqli_fetch_row($result))

{

    echo "<tr>";

 

    // $row is array... foreach( .. ) puts every element

    // of $row to $cell variable

    foreach($row as $cell)

        echo "<td>$cell</td>";

 

    echo "</tr>\n";

}

mysqli_free_result($result);

 

if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) {

  $startrow = 0;

} else {

  $startrow = (int)$_GET['startrow'];

}

 

echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+10).'">Next</a>';

?>

Link to comment
https://forums.phpfreaks.com/topic/203372-display-tables-controls-help/
Share on other sites

$id=$_GET['state'];
$start = (isset($_GET['startrow'])) ? (int)$_GET['startrow'] : 0;
ini_set ("display_errors", "1");
error_reporting(E_ALL);

$sqlCommand = "SELECT * FROM COUNTIES where state = '$id' LIMIT $start, 10";
$result = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());

$fields_num = mysqli_num_fields($result);

echo "<h1>Test Table</h1>";
echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
    $field = mysqli_fetch_field($result);
    echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysqli_fetch_row($result))
{
    echo "<tr>";

    // $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    foreach($row as $cell)
        echo "<td>$cell</td>";

    echo "</tr>\n";
}
mysqli_free_result($result);

if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) {
  $startrow = 0;
} else {
  $startrow = (int)$_GET['startrow'];
}

echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+10).'">Next</a>';
?>

Did you happen to look at these lines?

 

$id=$_GET['state'];
$start = (isset($_GET['startrow'])) ? (int)$_GET['startrow'] : 0;
ini_set ("display_errors", "1");
error_reporting(E_ALL);

$sqlCommand = "SELECT * FROM COUNTIES where state = '$id' LIMIT $start, 10";
$result = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());

How do I create new url with startrow using my existing query?

 

$sqlCommand = "SELECT * FROM COUNTIES where state = '$id' LIMIT $start, 10";

 

echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+10).'">Next</a>';

 

I need to alter the echo code to include the $id??

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.