SunQuest
           Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old August 14th, 2003, 12:48 PM
cmcdonld cmcdonld is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 14 cmcdonld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
PHP/MSSQL Query Question

Hey guys, I've been teaching myself PHP/SQL; can someone tell me why I am only receiving one row returned in this query? I know my DB has over a 100 rows and I want them all to display. I have not been able to find many examples using mssql except for the PHP manual, is mysql basically the same thing? Thanks!


</tr>
<?php
$db_name = "db name";
$table_name = "table name";
$connection = mssql_connect("", "", "") or die("Unable to connect to the database.");
$db = mssql_select_db($db_name, $connection) or die("Unable to connect to the database.");

$query = "SELECT ID, DistrictName FROM $table_name ORDER BY ASC";

$result = mssql_query($query, $connection) or die("Could not process query.");

while ($row = mssql_fetch_array($result)) {
$ID = $row['ID'];
$DistrictName = $row['DistrictName'];
}
?>
<tr>
<td>
<?php echo "$ID" ?>
</td>
<td>
<?php echo "$DistrictName" ?>
</td>
</tr>
</table>

Reply With Quote
  #2  
Old August 14th, 2003, 12:53 PM
coderboi coderboi is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 80 coderboi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: PHP/MSSQL Query Question

You're ending your while() clause too early...
try this:

php Code:
Original - php Code
  1.  
  2.  
  3. </tr>
  4. <?php
  5. $db_name = "db name";
  6. $table_name = "table name";
  7. $connection = mssql_connect("", "", "") or die("Unable to connect to the database.");
  8. $db = mssql_select_db($db_name, $connection) or die("Unable to connect to the database.");
  9.  
  10. $query = "SELECT ID, DistrictName FROM $table_name ORDER BY ASC";
  11.  
  12. $result = mssql_query($query, $connection) or die("Could not process query.");
  13.  
  14. while ($row = mssql_fetch_array($result)) {
  15. $ID = $row['ID'];
  16. $DistrictName = $row['DistrictName'];
  17. ?>
  18. <tr>
  19. <td>
  20. <?php echo "$ID" ?>
  21. </td>
  22. <td>
  23. <?php echo "$DistrictName" ?>
  24. </td>
  25. </tr>
  26. <?
  27. }
  28. ?>
  29. </table>

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > PHP/MSSQL Query Question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway