MartinMar52011 Posted March 6, 2011 Share Posted March 6, 2011 I have the code below: ---------------------------------------------------------------------- ------------------------------------ <div id="content"> <table width="998" border="0" cellspacing="4" id="stuff"> <?php do { ?> <tr> <td><?php echo $row_Recordset1['name']; ?></td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> <div id="spryTable" spry:region="ds1"> <table align="center"> <tr> <th spry:sort="name"> </th> </tr> <tr spry:repeat="ds1" spry:setrow="ds1" spry:hover="hover" spry:select="selected"> <td height="40" align="center">{name}</td> // green line <td height="40" align="center">{name}</td> //orange line </tr> </table> </div> ---------------------------------------------------------------------- -------------------------------- At the moment the green line of code will display the entire record of names, and the orange line displays the entire record again in another column of the table. The problem is, I want half the names to be printed in one column and the other half of names to be displayed in the other column. Can someone show me how to set the php code to do this? I've been trying various things for a while now without success. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/229725-how-can-i-limit-the-of-results-displayed-from-a-recordset/ Share on other sites More sharing options...
jcbones Posted March 6, 2011 Share Posted March 6, 2011 None of that is PHP, please post your code. No one will steal it, I promise. Quote Link to comment https://forums.phpfreaks.com/topic/229725-how-can-i-limit-the-of-results-displayed-from-a-recordset/#findComment-1183415 Share on other sites More sharing options...
doddsey_65 Posted March 6, 2011 Share Posted March 6, 2011 in your query add to the bottom of it LIMIT followed by your limit: LIMIT 1 Quote Link to comment https://forums.phpfreaks.com/topic/229725-how-can-i-limit-the-of-results-displayed-from-a-recordset/#findComment-1183424 Share on other sites More sharing options...
jcbones Posted March 6, 2011 Share Posted March 6, 2011 That is not what he is asking Dodd, he want's to separate the columns, 50% in one, and 50% in the second. Quote Link to comment https://forums.phpfreaks.com/topic/229725-how-can-i-limit-the-of-results-displayed-from-a-recordset/#findComment-1183430 Share on other sites More sharing options...
doddsey_65 Posted March 6, 2011 Share Posted March 6, 2011 that will teach me to read the post and not just the subject. now that i have read the post then yes please share some of your php code. also share what you have tried in this process. Quote Link to comment https://forums.phpfreaks.com/topic/229725-how-can-i-limit-the-of-results-displayed-from-a-recordset/#findComment-1183431 Share on other sites More sharing options...
MartinMar52011 Posted March 8, 2011 Author Share Posted March 8, 2011 I have the complete code below (minus the two style sheet files). Right now the webpage will display two columns of names (lets consider one last names at the moment). The script will result in the display of two columns with the same list of names. The problem is: I want only half the names to appear in one column (lets say from Albert to Henry) and the other half in the other column (lets say from Homer to Zebra). Does someone know how to amend this code so that it will display the names as desired? CODE BELOW: <?php require_once('Connections/connector.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_connector, $connector); $query_Recordset1 = "SELECT name FROM listings_name ORDER BY name_id ASC"; $Recordset1 = mysql_query($query_Recordset1, $connector) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Name Search</title> <style type="text/css"> </style> <link href="common_styles.css" rel="stylesheet" type="text/css" /> <link href="main_cols.css" rel="stylesheet" type="text/css" /> <script src="SpryAssets/SpryData.js" type="text/javascript"></script> <script src="SpryAssets/SpryHTMLDataSet.js" type="text/javascript"></script> <script type="text/javascript"> var ds1 = new Spry.Data.HTMLDataSet(null, "listings_name", {firstRowAsHeaders: false, columnNames: ['name']}); ds1.setColumnType("name", "html"); </script> </head> <body> <div id="wrapper"> <table width="998" border="0" cellspacing="4" id="listings_name"> <?php do { ?> <tr> <td><?php echo $row_Recordset1['name']; ?></td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> <div id="spryTable" spry:region="ds1"> <table align="center"> <tr> <th spry:sort="name"> </th> </tr> <tr spry:repeat="ds1" spry:setrow="ds1" spry:hover="hover" spry:select="selected"> <td height="40" align="center">{name}</td> <td height="40" align="center">{name}</td> </tr> </table> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/229725-how-can-i-limit-the-of-results-displayed-from-a-recordset/#findComment-1184268 Share on other sites More sharing options...
jcbones Posted March 9, 2011 Share Posted March 9, 2011 I noted the changes, and additions. Hope it helps. <?php require_once('Connections/connector.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_connector, $connector); $query_Recordset1 = "SELECT name FROM listings_name ORDER BY name_id ASC"; $Recordset1 = mysql_query($query_Recordset1, $connector) or die(mysql_error()); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Name Search</title> <style type="text/css"> </style> <link href="common_styles.css" rel="stylesheet" type="text/css" /> <link href="main_cols.css" rel="stylesheet" type="text/css" /> <script src="SpryAssets/SpryData.js" type="text/javascript"></script> <script src="SpryAssets/SpryHTMLDataSet.js" type="text/javascript"></script> <script type="text/javascript"> var ds1 = new Spry.Data.HTMLDataSet(null, "listings_name", {firstRowAsHeaders: false, columnNames: ['name']}); ds1.setColumnType("name", "html"); </script> </head> <body> <div id="wrapper"> <table width="998" border="0" cellspacing="4" id="listings_name"> <?php //changed this section to break the while loop, when half the rows have been displayed. $half_rows = round($totalRows_Recordset1 / 2); $i = 0; while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)) { ?> <tr> <td><?php echo $row_Recordset1['name']; ?></td> </tr> <?php if(++$i == $half_rows) break; } ?> </table> <?php //This table added, Holds 2nd half of names. I'm sure you can get it to line up right in dreamweaver. ?> <table width="998" border="0" cellspacing="4" id="listings_name"> <?php while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)) { ?> <tr> <td><?php echo $row_Recordset1['name']; ?></td> </tr> <?php } ?> </table> </div> <div id="spryTable" spry:region="ds1"> <table align="center"> <tr> <th spry:sort="name"> </th> </tr> <tr spry:repeat="ds1" spry:setrow="ds1" spry:hover="hover" spry:select="selected"> <td height="40" align="center">{name}</td> <td height="40" align="center">{name}</td> </tr> </table> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/229725-how-can-i-limit-the-of-results-displayed-from-a-recordset/#findComment-1184845 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.