Jump to content

[SOLVED] Help: mysql_query()


clown[NOR]

Recommended Posts

I have one simple question.. why does this work:

 

<?php

function visSisteNyhet()
{
	c2db();
	$result = mysql_query("SELECT * FROM `news_article` WHERE authorized='1' ORDER BY `id` DESC LIMIT 1");
	if (!$result) { die(); }

	$dbRows = mysql_num_rows($result);
	if ($dbRows > 0) {
		$dbField = mysql_fetch_array($result);
		$id = $dbField['id'];
		$title = $dbField['title'];
		return '<a href="atikkel.php?id='.$id.'">'.$title.'</a>';
	}
}

?>

 

but this doesn't return anything:

<?php

function visSisteNyhet()
{
	c2db();
	$result = mysql_query("SELECT id,title FROM `news_article` WHERE authorized='1' ORDER BY `id` DESC LIMIT 1");
	if (!$result) { die(); }

	$dbRows = mysql_num_rows($result);
	if ($dbRows > 0) {
		$dbField = mysql_fetch_array($result);
		$id = $dbField['id'];
		$title = $dbField['title'];
		return '<a href="atikkel.php?id='.$id.'">'.$title.'</a>';
	}
}

?>

 

the change is in the $query line

 

Thanks In Advance

- Clown

Link to comment
Share on other sites

a) its the $result line ;D not $query :D;)

b) try this... i've had issues with some names of columns left on their own... therefore go `!

 

[s]$result = mysql_query("SELECT id,title FROM `news_article` WHERE authorized='1' ORDER BY `id` DESC LIMIT 1");
if (!$result) { die(); }[/s]
$result = mysql_query("SELECT `id`,`title` FROM `news_article` WHERE `authorized`='1' ORDER BY `id` DESC LIMIT 1") or die();

Link to comment
Share on other sites

haha... yeah about the $query ... my bad... I'm used to add the query into the $query and then run it trough the $result...hehehe... shit happens...

 

but for the problem... it still don't work... the output is nothing...

 

EDIT: I just tried adding mysql_error() inside die()... no errors

Link to comment
Share on other sites

Woho

<?php

function visSisteNyhet()
{
	c2db();
	$result = mysql_query("SELECT id,title FROM `news_article` WHERE authorized='1' ORDER BY `id` DESC LIMIT 1");
	if (!$result) { die(); }

	$dbRows = mysql_num_rows($result);
	if ($dbRows > 0) {
		$dbField = mysql_fetch_array($result);
		$id = $dbField['id'];
		$title = $dbField['title'];
		return '<a href="atikkel.php?id='.$id.'">'.$title.'</a>';
	}
}

?>

Should then be

<?php

function visSisteNyhet()
{
	c2db();
	$result = mysql_query("SELECT id,title FROM `news_article` WHERE authorized='1' ORDER BY `id` DESC LIMIT 1");
	if (!$result) { die(); }

	$dbRows = mysql_num_rows($result);
	if ($dbRows > 0) {
                       
		while($dbField = mysql_fetch_object($result))
		{
                        $id = $dbField['id'];
		$title = $dbField['title'];
		return '<a href="atikkel.php?id='.$id.'">'.$title.'</a>';
                        }
	}
}

?>

Link to comment
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.