Hello,
Can somebody help me out.
I basically want to display the results if the number of rows returned is greater than zero, and if not, echo out a reason why.
However, when using the code below, it doesn’t echo anything even if there are no results.
Any ideas ?
[code=php]
<?php # this file
$page_title = “Pictures”;
include (‘./includes/header.html’);
// Check for a valid picture ID, through GET or POST.
if ( (isset($_GET[‘id’])) && (is_numeric($_GET[‘id’])) ) { // Accessed through picturesarea.php.
$id = $_GET[‘id’];
} elseif ( (isset($_POST[‘id’])) && (is_numeric($_POST[‘id’])) ) {// Form has been submitted.
$id = $_POST[‘id’];
} else { // No valid ID, Kill the script.
echo ‘<h2>Page Error</h2><p class=”error”>This page has been accessed in error. <a href=”picturesarea.php”>Return to ‘Pictures’.</a></p><p><br /><br /></p>’;
include (‘./includes/footer.html’);
exit();
}
require_once (‘../mysql_connect.php’); // Connect to the database
$query2 = “SELECT aname FROM area WHERE id = $_GET[id]”;
$result2 = mysql_query($query2) or trigger_error(“Query: $query2n<br />MySQL Error: ” . mysql_error());
$row2 = mysql_fetch_array($result2);
$query = “SELECT CONCAT(image_name, ‘, ‘, dateUpload), id, user_id FROM user_images WHERE aid = $_GET[id] AND approved=’Y'”;
$result = mysql_query($query) or trigger_error(“Query: $queryn<br />MySQL Error: ” . mysql_error());
echo ‘<p><h2>’ . $row2[aname] . ‘</h2></p>’;
$num = mysql_num_rows($result);
while ($row = mysql_fetch_array($result)) {
$query3 = “SELECT user_id, username FROM users WHERE user_id = $row[user_id]”;
$result3 = mysql_query($query3) or trigger_error(“Query: $query3n<br />MySQL Error: ” . mysql_error());
$row3 = mysql_fetch_array($result3);
if ($num > 0) { // If it ran OK, display the records.
echo ‘<p><a href=”picture.php?id=’ . $row[1] . ‘”>’ . $row[‘0’] . ‘</a> – posted by : <a href=”view_profile.php?id=’ . $row3[‘user_id’] . ‘”>’ . $row3[‘username’] . ‘</a></p>’;
}
else { // If it did not run OK.
echo ‘<p class=”error”>There are currently no pictures in the database for the area. Please check back soon</p>’;
}
}
?>
<?
include (‘./includes/footer.html’);
?>