XeroXer Posted December 28, 2006 Share Posted December 28, 2006 Hi again allI have been having some php problems with my site.Yesterday I created a simple forum and user profiles.The thing is that if someone goes into a userid that doesn't exists I want to show an error.Now it only shows a blank page.My code is like this:[code]<?phpecho "<table border='1' cellspacing='2' cellpadding='2'><tr><td><strong>Topic</strong></td><td><strong>Date</strong></td><td><strong>User</strong></td></tr>";$threads = $_GET['t'];include("config/database.php");$con = mysql_connect("$mysqlhost","$mysqlusr","$mysqlpass") or die('Could not connect: ' . mysql_error());mysql_select_db($db_name, $con) or die(mysql_error());$results = mysql_query("SELECT * FROM v2_forum_threads WHERE catid = '$threads' ORDER BY id") or die(mysql_error());while($row = mysql_fetch_array($results)){echo "<tr><td><a href='forum_thread.php?t=";echo $row['id'];echo "'>";echo $row['topic'];echo "</a></td><td>";echo $row['date'];echo "</td><td>";echo "<a href='profile.php?u=";echo $row['userid'];echo "'>";$userid = $row['userid'];$results = mysql_query("SELECT * FROM v2_users WHERE id = '$userid'") or die(mysql_error());while($rows = mysql_fetch_array($results)){echo $rows['name'];}echo "</a></td></tr>";}mysql_close($con);echo "</table>";echo "<br><p align='right'><a href='forum_post.php?t=";echo $threads;echo "'>Post thread</a></p>";?>[/code]I want that if no catid that is the same as $threads it should show a simple message to the user. Link to comment https://forums.phpfreaks.com/topic/32042-solved-if-no-result-with-that-id-from-mysql/ Share on other sites More sharing options...
craygo Posted December 28, 2006 Share Posted December 28, 2006 Just check the number of rows returned.[code]<?php$results = mysql_query("SELECT * FROM v2_forum_threads WHERE catid = '$threads' ORDER BY id") or die(mysql_error());$num_rows = mysql_num_rows($results);if($num_rows > 0){while($row = mysql_fetch_array($results))// blah blah blah} else {echo "No threads found";}?>[/code]Ray Link to comment https://forums.phpfreaks.com/topic/32042-solved-if-no-result-with-that-id-from-mysql/#findComment-148723 Share on other sites More sharing options...
XeroXer Posted December 28, 2006 Author Share Posted December 28, 2006 Thanks.Simple but still it saved my day... Link to comment https://forums.phpfreaks.com/topic/32042-solved-if-no-result-with-that-id-from-mysql/#findComment-148729 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.