Jump to content


Photo

Code error!


  • Please log in to reply
3 replies to this topic

#1 laserdude45

laserdude45
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 10 October 2006 - 09:01 PM

Can someone tell me whats wrong with this sql statement andor function!

function Get_Theme()
{
	$sql = "SELECT * FROM pm_theme WHERE current=1";
	$res = mysql_query($sql);
	while ($row = mysql_fetch_object($res));
	{
		$theme_name = $row->name;
	}
	$theme = $theme_name;
	return($theme);
}


#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 10 October 2006 - 09:10 PM

Are you seeing any errors? Why do you think it is wrong?
Remove the semi-colon at the end of the while statement.

If you're expecting multiple rows from the query, the code will only return the last value.

If there is only one possible row, I would write the code something like:
<?php
function Get_Theme()
{
	$sql = "SELECT name FROM pm_theme WHERE current=1";
	$res = mysql_query($sql);
        if(!$res) return(mysql_error()); // syntax error in the select statement
	$row = mysql_fetch_assoc($res);
	return($row['name']);
}?>

Ken

#3 laserdude45

laserdude45
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 10 October 2006 - 09:29 PM

Ok heres the problem, nothing shows up on the screen... A theme should come up but for some reason nothing shows up! Im getting mad because Ive been working on this one littile part of my script for over a week!

Btw.. I tried the code but it didnt work... but thanks for helping :)
So if anyone can think why it wouldnt work or would like to see the source code just post :)

EDIT: lol as soon as I posted that I rember now that I forgot to change something in the DB lol... I'll fix this and see if it works!
EDIT EDIT: Well after getting mysql to work lol(Error 2013) it still doesnt work... Nothing shows up, It retrives the file in theory but it doesnt work! So if anyone can figure out why or tell me that its not that function that's causing the problem please say, Im gonna try one more thing but I dont think it will make a differnece...

#4 laserdude45

laserdude45
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 10 October 2006 - 11:58 PM

Heres the code, http://gtaa.exofire.net/phpmissile.zip if someone can tell me why its not working....

BTW you need to edit config.php in includes folder to your mysql stuff
AND you need to execute this code on a database,



CREATE TABLE `pm_admin` (
  `user` text NOT NULL,
  `pass` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;







CREATE TABLE `pm_modules` (
  `id` int(11) NOT NULL auto_increment,
  `title` text NOT NULL,
  `custom` text NOT NULL,
  `active` tinyint(4) NOT NULL,
  `onmenu` tinyint(4) NOT NULL,
  `Admin_des` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;




INSERT INTO `pm_modules` VALUES (1, 'Test', 'Test', 1, 1, 'A test module for phpmissile');




CREATE TABLE `pm_news` (
  `id` int(11) NOT NULL auto_increment,
  `heading` tinytext NOT NULL,
  `content` longtext NOT NULL,
  `author` tinytext NOT NULL,
  `date` date NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;




INSERT INTO `pm_news` VALUES (1, 'Your site has been setup', 'Welcome to the wonderful phpmissile Alpha 1!\r\n\r\nGoto admin/s.php .\r\n\r\nAfter you create the user, you must delete s.php.', 'Anthony Crognale', '2006-09-24');

Post your results





CREATE TABLE `pm_theme` (
  `id` int(11) NOT NULL auto_increment,
  `name` text NOT NULL,
  `current` int(11) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

INSERT INTO `pm_theme` VALUES (1, 'pm', 1);





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users