ccrevcypsys Posted December 20, 2007 Share Posted December 20, 2007 Can you use an else with a while statement because i might have it wrong... I dont know how i could possible have it wrong but i am trying to add a statement that comes up when a search comes up in no results here is the code i have <?php while ($row = mysql_fetch_array($mainquery, MYSQL_ASSOC)){ ?> <tr> <td class="soList" width="10%"><a href="serviceOrder.php?p=so&id=<?php echo $row['id']; ?>"><?php echo $row['id']; ?></a></td> <td class="soList" width="15%"><a href="serviceOrder.php?p=so&id=<?php echo $row['id']; ?>"><?php echo $row['dateCompleted']; ?></a></td> <td class="soList" width="30%"><a href="serviceOrder.php?p=so&id=<?php echo $row['id']; ?>"><?php echo $row['name']; ?></a></td> <td class="soList" width="30%"><a href="serviceOrder.php?p=so&id=<?php echo $row['id']; ?>"><?php echo $row['customer_name']; ?></a></td> <td class="soList" width="15%"><a href="serviceOrder.php?p=so&id=<?php echo $row['id']; ?>"><?php echo $row['status']; ?></a></td> </tr> <?php }else{ ?> <tr><td colspan="6">We Are Sorry But There Where No Matches For What You Are Looking For...</td></tr> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/82543-solved-while/ Share on other sites More sharing options...
p2grace Posted December 20, 2007 Share Posted December 20, 2007 I don't think you can use an else in a while statement. I'd check the number of rows returned by the query, if it's zero display the text accordingly. Link to comment https://forums.phpfreaks.com/topic/82543-solved-while/#findComment-419615 Share on other sites More sharing options...
GuitarGod Posted December 20, 2007 Share Posted December 20, 2007 Yeah, what the poster above said <?php if ( mysql_num_rows( $mainquery ) > 0 ) { // Your 'while' query here while ( $row = ..... { } } else { // No results } ?> Link to comment https://forums.phpfreaks.com/topic/82543-solved-while/#findComment-419621 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.