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 Quote 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(); Quote 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 Quote 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 Quote 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 Quote 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>'; } } } ?> Quote 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 Quote 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() Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/51692-solved-help-mysql_query/#findComment-254690 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.