vj5 Posted January 23, 2008 Share Posted January 23, 2008 I want to loop through the data and display 25 records. Here is my code: $CNT1=0;$QRY1="Select * from `tblconfirm` where `brokerid` = '".$lu."' ORDER BY `caseID` DESC LIMIT 25";$result = mysql_query($QRY1);$CNT1= mysql_num_rows($result);echo "$QRY1<br>";if ($CNT1 != 0) { $idx=0; while ($idx < $CNT1) { // EXTRACT DATA FROM THE DATABASE $sdate = mysql_result($result, $idx, "sub-date"); $bor = mysql_result($result, $idx, "brokerid"); $car = mysql_result($result, $idx, "carrier"); $gnum = mysql_result($result, $idx, "group_number"); $gnam = mysql_result($result, $idx, "group_name"); $type = mysql_result($result, $idx, "type"); $sgroup = mysql_result($result, $idx, "subgroup"); $cid = mysql_result($result, $idx, "caseID"); $rep = mysql_result($result, $idx, "rep"); $actiontxt = mysql_result($result, $idx, "action-text"); $status = mysql_result($result, $idx, "status"); $idx++; }}//SHOW RESULT TO THE SCREENecho "<div id=bor-int-box>";echo "$sdate:";echo "$bor";echo "($cid)";echo "</div>"; Can someone please tell how to display 25 records at a time. I am able to see only one, the top most. Link to comment Share on other sites More sharing options...
Lulzim Posted January 23, 2008 Share Posted January 23, 2008 you are looping through data, save the results to variables and echo them outside the loop. the variables will contain ONLY values from the last record, that's why you get only last record.print the results inside while loop. $CNT1=0;$QRY1="Select * from `tblconfirm` where `brokerid` = '".$lu."' ORDER BY `caseID` DESC LIMIT 25";$result = mysql_query($QRY1);$CNT1= mysql_num_rows($result);echo "$QRY1<br>";if ($CNT1 != 0) { $idx=0; while ($idx < $CNT1) { // EXTRACT DATA FROM THE DATABASE $sdate = mysql_result($result, $idx, "sub-date"); $bor = mysql_result($result, $idx, "brokerid"); $car = mysql_result($result, $idx, "carrier"); $gnum = mysql_result($result, $idx, "group_number"); $gnam = mysql_result($result, $idx, "group_name"); $type = mysql_result($result, $idx, "type"); $sgroup = mysql_result($result, $idx, "subgroup"); $cid = mysql_result($result, $idx, "caseID"); $rep = mysql_result($result, $idx, "rep"); $actiontxt = mysql_result($result, $idx, "action-text"); $status = mysql_result($result, $idx, "status"); $idx++; //SHOW RESULT TO THE SCREEN echo "<div id=bor-int-box>"; echo "$sdate:"; echo "$bor"; echo "($cid)"; echo "</div>"; }} Link to comment Share on other sites More sharing options...
vj5 Posted January 23, 2008 Author Share Posted January 23, 2008 Thanks. I got it fixed. I have another question. How to retrieve records that have multiple copies of records and I want only one and the latest one? Link to comment Share on other sites More sharing options...
Lulzim Posted January 23, 2008 Share Posted January 23, 2008 what do you mean with "records that have multiple copies of records"you mean distinct values? Link to comment Share on other sites More sharing options...
vj5 Posted January 23, 2008 Author Share Posted January 23, 2008 correct. But my sql statement goes like this: select * from tblconfirm; I have multiple values to be retrieved. Link to comment Share on other sites More sharing options...
jhecht Posted January 24, 2008 Share Posted January 24, 2008 Not sure, but i believe that is what the "SELECT DISTINCT * FROM table" syntax was invented for... Link to comment Share on other sites More sharing options...
vj5 Posted January 24, 2008 Author Share Posted January 24, 2008 Not sure, but i believe that is what the "SELECT DISTINCT * FROM table" syntax was invented for... Select DISTINCT * from tblconfirm is not retrieving distinct values. Is there any way to do it? Link to comment Share on other sites More sharing options...
justsomeguy Posted January 24, 2008 Share Posted January 24, 2008 You need to use a WHERE clause with the select statement. Without knowing the structure of the database or what you're looking for I can't say what the WHERE would say. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.