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
https://forums.phpfreaks.com/topic/51692-solved-help-mysql_query/
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();

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

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>';
                        }
	}
}

?>

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.