Jump to content

Code error!


laserdude45

Recommended Posts

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

[code]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);
}[/code]
Link to comment
Share on other sites

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:
[code]<?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']);
}?>[/code]

Ken
Link to comment
Share on other sites

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...
Link to comment
Share on other sites

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,
[code]



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);
[/code]
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.