clown[NOR] Posted May 16, 2007 Share Posted May 16, 2007 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 More sharing options...
taith Posted May 16, 2007 Share Posted May 16, 2007 a) its the $result line not $query 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 https://forums.phpfreaks.com/topic/51692-solved-help-mysql_query/#findComment-254651 Share on other sites More sharing options...
clown[NOR] Posted May 16, 2007 Author Share Posted May 16, 2007 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 https://forums.phpfreaks.com/topic/51692-solved-help-mysql_query/#findComment-254657 Share on other sites More sharing options...
iLLeLogicaL Posted May 16, 2007 Share Posted May 16, 2007 try using mysql_fetch_object instead of mysql_fetch_array. That should fix it Link to comment https://forums.phpfreaks.com/topic/51692-solved-help-mysql_query/#findComment-254664 Share on other sites More sharing options...
clown[NOR] Posted May 16, 2007 Author Share Posted May 16, 2007 that returned this error: Fatal error: Cannot use object of type stdClass as array in G:\www\dassrevyen\V2\includes\functions\nyheter.php on line 12 Link to comment https://forums.phpfreaks.com/topic/51692-solved-help-mysql_query/#findComment-254666 Share on other sites More sharing options...
iLLeLogicaL Posted May 16, 2007 Share Posted May 16, 2007 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 https://forums.phpfreaks.com/topic/51692-solved-help-mysql_query/#findComment-254669 Share on other sites More sharing options...
clown[NOR] Posted May 16, 2007 Author Share Posted May 16, 2007 ok..tried it.. and it still returns: Fatal error: Cannot use object of type stdClass as array in G:\www\dassrevyen\V2\includes\functions\nyheter.php on line 12 Link to comment https://forums.phpfreaks.com/topic/51692-solved-help-mysql_query/#findComment-254673 Share on other sites More sharing options...
taith Posted May 16, 2007 Share Posted May 16, 2007 ahoy! while($dbField = mysql_fetch_object($result)) you need array()/assoc() Link to comment https://forums.phpfreaks.com/topic/51692-solved-help-mysql_query/#findComment-254683 Share on other sites More sharing options...
clown[NOR] Posted May 16, 2007 Author Share Posted May 16, 2007 thanks for your help guys... much appriciated Link to comment https://forums.phpfreaks.com/topic/51692-solved-help-mysql_query/#findComment-254690 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.