Jump to content

Recommended Posts

I've written queries hundreds of times. Can someone please figure out what I can't.

Table has 40 rows. Hostname, username, password, and dbname are all correct.

I keep hitting the else statement and getting nothing.

 

<?php

function dbconnect() {
$hostname = "******";
$username = "******";
$password = "******";
$dbname   = "******";

mysql_connect($hostname, $username, $password) OR DIE ("Unable to connect.");
mysql_select_db($dbname);
}

function dbclose() {
mysql_close();
}

function getNews() {
dbconnect();
$query = "SELECT * FROM news ORDER BY id DESC LIMIT 5";
$reslut = mysql_query($query) OR DIE ("Error: getNews().");
if ($result) {
	while ($r = mysql_fetch_array($result)) {
		$post = $r["post"];
		$date = $r["date"];
		$ymd = explode("-", $date);
		$postDate = date("F j, Y", mktime(0, 0, 0, $ymd[2], $ymd[0], $ymd[1]));
			echo "<div class=\"content\">
				<div class=\"newsdate\">$postDate</div>
				<p>$post</p>
			</div>\n";
	}
} else {
	echo "There are currently no updates about the chapter.";
}
dbclose();
}
?>

Link to comment
https://forums.phpfreaks.com/topic/55893-solved-query-broken/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.