mapmedia Posted May 30, 2010 Share Posted May 30, 2010 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 More sharing options...
jcbones Posted May 30, 2010 Share Posted May 30, 2010 $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>'; ?> Link to comment https://forums.phpfreaks.com/topic/203372-display-tables-controls-help/#findComment-1065434 Share on other sites More sharing options...
mapmedia Posted May 30, 2010 Author Share Posted May 30, 2010 not sure if that was a reply or just quoting my code Any help much welcome Link to comment https://forums.phpfreaks.com/topic/203372-display-tables-controls-help/#findComment-1065488 Share on other sites More sharing options...
jcbones Posted May 31, 2010 Share Posted May 31, 2010 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()); Link to comment https://forums.phpfreaks.com/topic/203372-display-tables-controls-help/#findComment-1065520 Share on other sites More sharing options...
mapmedia Posted May 31, 2010 Author Share Posted May 31, 2010 oh thanks it didn't have any effect at all for some reason. from this: county.php?state=california to this: county.php?startrow=10 I am thinking the state=california still needs to be part of the call. Link to comment https://forums.phpfreaks.com/topic/203372-display-tables-controls-help/#findComment-1065605 Share on other sites More sharing options...
riwan Posted May 31, 2010 Share Posted May 31, 2010 to combine those, the call would need to be this : county.php?state=california&startrow=10 Link to comment https://forums.phpfreaks.com/topic/203372-display-tables-controls-help/#findComment-1065626 Share on other sites More sharing options...
mapmedia Posted May 31, 2010 Author Share Posted May 31, 2010 thanks. how would I edit this line to reflect that? echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+10).'">Next</a>'; Link to comment https://forums.phpfreaks.com/topic/203372-display-tables-controls-help/#findComment-1065682 Share on other sites More sharing options...
mapmedia Posted May 31, 2010 Author Share Posted May 31, 2010 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?? Link to comment https://forums.phpfreaks.com/topic/203372-display-tables-controls-help/#findComment-1065841 Share on other sites More sharing options...
jcbones Posted May 31, 2010 Share Posted May 31, 2010 echo '<a href="'.$_SERVER['PHP_SELF'].'?state=' . $id . '&startrow='.($startrow+10).'">Next</a>'; Try that. Link to comment https://forums.phpfreaks.com/topic/203372-display-tables-controls-help/#findComment-1065843 Share on other sites More sharing options...
mapmedia Posted May 31, 2010 Author Share Posted May 31, 2010 Shazam! That worked! Very helpful. Many thanks bro! Link to comment https://forums.phpfreaks.com/topic/203372-display-tables-controls-help/#findComment-1065846 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.