FinlandsSvenska Posted January 3, 2010 Share Posted January 3, 2010 I'm trying to make it where I can have a "Global Message" on my site. It will appear under the logo. I can do that part (lolbasic), but I have a page only accessable to admins/mods (that works too). 2 files are involved, template.php and global_message.php. global message.php is the file that contains the text box and submit button. It will send the text in the box to the mysql database 'atbbs' and the table 'glbmsg' The table has 2 fields: no (AI) text I need to know what mysql query I should run to get the highest 'no' and the 'text' that goes with it. Tell me if I need to elaborate, FS Quote Link to comment https://forums.phpfreaks.com/topic/187011-im-not-sure-how-you-would-go-about-doing-this/ Share on other sites More sharing options...
trq Posted January 3, 2010 Share Posted January 3, 2010 What exactly does the no field contain? Quote Link to comment https://forums.phpfreaks.com/topic/187011-im-not-sure-how-you-would-go-about-doing-this/#findComment-987589 Share on other sites More sharing options...
FinlandsSvenska Posted January 3, 2010 Author Share Posted January 3, 2010 What exactly does the no field contain? a number e.g. NO | TEXT 1 "o hai thar" 2 "hello, I am test" ... the no field is for numbers. Quote Link to comment https://forums.phpfreaks.com/topic/187011-im-not-sure-how-you-would-go-about-doing-this/#findComment-987590 Share on other sites More sharing options...
ignace Posted January 3, 2010 Share Posted January 3, 2010 I believe to answer such questions manuals were created. Quote Link to comment https://forums.phpfreaks.com/topic/187011-im-not-sure-how-you-would-go-about-doing-this/#findComment-987591 Share on other sites More sharing options...
trq Posted January 3, 2010 Share Posted January 3, 2010 SELECT `text` FROM tbl ORDER BY no DESC LIMIT 1 ps: TEXT is a terrible name for a filed as it is a reserved word within sql (hence the backticks in my example). Quote Link to comment https://forums.phpfreaks.com/topic/187011-im-not-sure-how-you-would-go-about-doing-this/#findComment-987593 Share on other sites More sharing options...
FinlandsSvenska Posted January 3, 2010 Author Share Posted January 3, 2010 SELECT `text` FROM tbl ORDER BY no DESC LIMIT 1 ps: TEXT is a terrible name for a filed as it is a reserved word within sql (hence the backticks in my example). So will this display only one record? Quote Link to comment https://forums.phpfreaks.com/topic/187011-im-not-sure-how-you-would-go-about-doing-this/#findComment-987595 Share on other sites More sharing options...
trq Posted January 3, 2010 Share Posted January 3, 2010 It will retrieve one record. Quote Link to comment https://forums.phpfreaks.com/topic/187011-im-not-sure-how-you-would-go-about-doing-this/#findComment-987596 Share on other sites More sharing options...
FinlandsSvenska Posted January 3, 2010 Author Share Posted January 3, 2010 It will retrieve one record. Could you help me with this too? I have the code $glob_msg = $result; and in my browser it returns: Catchable fatal error: Object of class mysqli_result could not be converted to string in C:\xampplite\htdocs\includes\template.php on line 83 Quote Link to comment https://forums.phpfreaks.com/topic/187011-im-not-sure-how-you-would-go-about-doing-this/#findComment-987599 Share on other sites More sharing options...
trq Posted January 3, 2010 Share Posted January 3, 2010 Were going to need more code than that I'm afraid. Quote Link to comment https://forums.phpfreaks.com/topic/187011-im-not-sure-how-you-would-go-about-doing-this/#findComment-987601 Share on other sites More sharing options...
FinlandsSvenska Posted January 3, 2010 Author Share Posted January 3, 2010 Were going to need more code than that I'm afraid. Oh lord... Involving that last snippet or the sql? Quote Link to comment https://forums.phpfreaks.com/topic/187011-im-not-sure-how-you-would-go-about-doing-this/#findComment-987604 Share on other sites More sharing options...
trq Posted January 3, 2010 Share Posted January 3, 2010 A few lines prior to and after line 83 of template.php would probably be helpful. Quote Link to comment https://forums.phpfreaks.com/topic/187011-im-not-sure-how-you-would-go-about-doing-this/#findComment-987605 Share on other sites More sharing options...
FinlandsSvenska Posted January 3, 2010 Author Share Posted January 3, 2010 A few lines prior to and after line 83 of template.php would probably be helpful. Actually, line 83 is where $glob_msg is echo'ed. Quote Link to comment https://forums.phpfreaks.com/topic/187011-im-not-sure-how-you-would-go-about-doing-this/#findComment-987607 Share on other sites More sharing options...
trq Posted January 3, 2010 Share Posted January 3, 2010 A few lines prior to and after line 83 of template.php would probably be helpful. Actually, line 83 is where $glob_msg is echo'ed. Yeah, I figured that. Read my last post again. Quote Link to comment https://forums.phpfreaks.com/topic/187011-im-not-sure-how-you-would-go-about-doing-this/#findComment-987610 Share on other sites More sharing options...
FinlandsSvenska Posted January 3, 2010 Author Share Posted January 3, 2010 A few lines prior to and after line 83 of template.php would probably be helpful. Actually, line 83 is where $glob_msg is echo'ed. Yeah, I figured that. Read my last post again. I think it will have something to do with getting the `text` and making it the $glob_msg (if you know what I mean). I have little idea how to do this. (as you can see, I am new to mysql + php, and I learn by example) Do you have a link or could you explain? Quote Link to comment https://forums.phpfreaks.com/topic/187011-im-not-sure-how-you-would-go-about-doing-this/#findComment-987612 Share on other sites More sharing options...
trq Posted January 3, 2010 Share Posted January 3, 2010 Can you post some relevant code? Were not mind readers. You are trying to echo a mysqli_result object. Objects can not be echo'd. See here for an example of what needs to be done with your object in order for you to extract its data. Quote Link to comment https://forums.phpfreaks.com/topic/187011-im-not-sure-how-you-would-go-about-doing-this/#findComment-987614 Share on other sites More sharing options...
FinlandsSvenska Posted January 3, 2010 Author Share Posted January 3, 2010 Can you post some relevant code? Were not mind readers. You are trying to echo a mysqli_result object. Objects can not be echo'd. See here for an example of what needs to be done with your object in order for you to extract its data. as you wish. { $mys = "SELECT `text` FROM glbmsg ORDER BY no DESC LIMIT 1"; mysql_query($mys,$con); $glob_msg = $result; } ?> <h1 id="logo"> <a rel="index" href="/"><?php echo SITE_TITLE . "<br>" . $glob_msg?></a> </h1> Quote Link to comment https://forums.phpfreaks.com/topic/187011-im-not-sure-how-you-would-go-about-doing-this/#findComment-987616 Share on other sites More sharing options...
trq Posted January 3, 2010 Share Posted January 3, 2010 Where exactly is $result defined? Quote Link to comment https://forums.phpfreaks.com/topic/187011-im-not-sure-how-you-would-go-about-doing-this/#findComment-987617 Share on other sites More sharing options...
FinlandsSvenska Posted January 3, 2010 Author Share Posted January 3, 2010 Where exactly is $result defined? I feel like an idiot. I didn't define it.... I thought I had put something in there. Well, I looked at that page, and I'm not sure what to try. I'm sorry I'm such a noob. Quote Link to comment https://forums.phpfreaks.com/topic/187011-im-not-sure-how-you-would-go-about-doing-this/#findComment-987618 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.