Jump to content

[SOLVED] Snippet, invisible problem.


Lambneck

Recommended Posts

Can anyone see what the problem is in this short script?

I get the "else" message: "That record does not exist!"

However the info is in fact in the database, so there is something

wrong (Im assuming in the query) that I cant find.

 

<?php

if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");

if (!mysql_select_db($database))
    die("Can't select database");

$sql = "SELECT * FROM $table ORDER BY id DESC LIMIT 25";
$result = mysql_query($sql) or die("Error ". mysql_error(). " with query ". $sql);
if(mysql_num_rows($result) == 1){
$row = mysql_fetch_array($result);

$postTime  = strtotime("-2 hours");
$diffArray = timeDiff($postTime);


echo '<div id="front_page_post_container">';
echo '<div id="title_container">';
echo '<h2>';
echo '<a href="blorum-topic.php?id='.$row['id'].'">'.stripslashes($row['title']).'</a>';
echo '</h2>';
echo '</div>';
echo '<div id="post_container">';
echo stripslashes(nl2br(substr($row['post'],0,450)));
echo ' <a href="blorum-topic.php?id='.$row['id'].'">Read on...</a>';
echo '</div>';
echo '<div id="name_date_container">';

print "<pre>";
	print_r($diffArray);
print "</pre>";

echo '</div>';
echo '</div>';

}else{
echo "That record does not exist!";
}

Link to comment
https://forums.phpfreaks.com/topic/159733-solved-snippet-invisible-problem/
Share on other sites

Hi

 

In which case simply change it to if(mysql_num_rows($result) >= 1), but then you need to loop through them all.

 

Something like this:-

 

<?php

if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");

if (!mysql_select_db($database))
die("Can't select database");

$sql = "SELECT * FROM $table ORDER BY id DESC LIMIT 25";
$result = mysql_query($sql) or die("Error ". mysql_error(). " with query ". $sql);
if(mysql_num_rows($result) == 1)
{

$postTime  = strtotime("-2 hours");
$diffArray = timeDiff($postTime);


echo '<div id="front_page_post_container">';
while($row = mysql_fetch_array($result))
{
	echo '<div id="title_container">';
	echo '<h2>';
	echo '<a href="blorum-topic.php?id='.$row['id'].'">'.stripslashes($row['title']).'</a>';
	echo '</h2>';
	echo '</div>';
	echo '<div id="post_container">';
	echo stripslashes(nl2br(substr($row['post'],0,450)));
	echo ' <a href="blorum-topic.php?id='.$row['id'].'">Read on...</a>';
	echo '</div>';
	echo '<div id="name_date_container">';

	print "<pre>";
	print_r($diffArray);
	print "</pre>";
	echo '</div>';
}
echo '</div>';
}
else
{
echo "That record does not exist!";
}
?>

 

All the best

 

Keith

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.