Jump to content

Im just getting back into PHPing...


V-Man

Recommended Posts

Hey guys, It's been ages!

 

Alright, Im just now getting back into PHPing and have found my self in a slump.  Here's what I want to do.

 

Select all the rows out of a table (this will be five, as all others will be deleted) and display them with the text and the user that posted it.  Im coding a shout box for my guild website.

 

Heres what I have so far.  And yes, my session based login works already and the variables pass correctly.

 

the SQL table that i set up

CREATE TABLE `shout` (
  `id` mediumint( unsigned NOT NULL default '0',
  `text` varchar(40) NOT NULL default '',
  `user` varchar(32) NOT NULL default '',
  `shown` int(1) NOT NULL default '1',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

 

Now, I know what I need to do:

select the rows, display them like so:

 

 

 

"blah blah blah blah",

--{the username}

 

"blah blah blah blah",

--{the username}

 

 

 

 

That's what I need to do.  But I can't for the life of my remember how to do it.  Any suggestions?

Link to comment
Share on other sites

Not just a select, I can do the basic part. 

 

SELECT * FROM shout

 

I can do that.  What I cant remember how to do is select the rows, then display them as seen above, but only doing the five newest.  Thats what i cant remember

Link to comment
Share on other sites

yes, I updated my DB.  The error im getting is

 

ou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'query' at line 1

 

 

 

 

NOT the unidentifyed row error.

Link to comment
Share on other sites

$query = "INSERT INTO shout (`text`,`user`,`shown`) VALUES ('".$post."','".$user."',CURRENT_TIMESTAMP)";

 

Only other problem I can see is that you're trying to insert a TIMESTAMP variable into an INT container sized 1 - meaning it can only store a single number (0-9). Try changing the datatype of "shown" to DATETIME. You could also use INT size 10 UNSIGNED and use this instead:

$query = "INSERT INTO shout (`text`,`user`,`shown`) VALUES ('".$post."','".$user."','".time()."')";

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.