crzyman
Members-
Posts
25 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
crzyman's Achievements
Newbie (1/5)
0
Reputation
-
Thanks! Works great.
-
I want to limit the amout of text that gets displayed from the database, which I can do using this statement: [code] $text = substr($message, 0, 80); [/code] Now I am trying to display only 40 char per line. I thought this would work: [code] $text = substr($message, 0, 80); $trim = trim($text, 0, 40, " \r."); echo nl2br("$name\n $trim \n $time\n"); [/code] But that would of been to easy. Can someone please help me out? Many thanks.
-
Limit the number of rows created in a database? *SOLVED*
crzyman replied to crzyman's topic in PHP Coding Help
I want to say thanks to everyone who helped me out here. It’s working fine now. I couldn’t have done it with out you. Happy coding. -
Limit the number of rows created in a database? *SOLVED*
crzyman replied to crzyman's topic in PHP Coding Help
Thanks. This is what I have. I have a form called comments.php. It looks like this: [code] <?PHP // this value will change dependeing on what page is being viewed. $myValue = "Joe"; ?> <form action="comments2.php" method="GET"> <INPUT TYPE='TEXT' value='name' NAME='name' SIZE=30 maxlength='100'><br> <INPUT TYPE='TEXT' value='message' NAME='message' SIZE=30 maxlength='100'> <input type="hidden" name=myValues value="<?=$myValue?>"> <input type="submit" name="submit" value="submit"> </form> [/code] Now this is the code for comments2.php [code] <?php mysql_connect("localhost","name","password"); mysql_select_db("news"); $artist_name = $_GET['myValues']; $result = mysql_query("SELECT * FROM shoutbox WHERE artist_name='$artist_name'"); $num_rows = mysql_num_rows($result); echo $num_rows; if(isset($_GET['submit'])) { if ($num_rows == "5") { $sql = "UPDATE shoutbox SET message = '$message', time=now() WHERE artist_name = '$artist_name' AND time=(SELECT min(time) FROM shoutbox WHERE artist_name = '$artist_name')"; } else { $sql=MYSQL_QUERY("INSERT INTO shoutbox (artist_name,name,message)". "VALUES ('$artist_name','$name', '$message')"); } } ?> [/code] I have also went back to using timestamp. So my table now looks like this: artist_name varchar(40) id int(11) name text message longtext time timestamp NULL DEFAULT CURRENT_TIMESTAMP And thats it. The code will update the database if there are only four rows for artist_name, but if there are five nothing happens. It just won't update. I think it has something to do with timestamp, but I'm at a loss. Thanks for your time and effort. -
Can someone please tell me what is wrong with this statement? If there are four rows in the database a fifth one will be added, but it will not update. Any ideas? [code] if ($num_rows == "5") { $sql = mysql_query("UPDATE shoutbox SET message='$message', time=now() WHERE artist_name='$artist_name' AND time=(SELECT min(time) FROM shoutbox WHERE artist_name='$artist_name')"); } else { $sql=MYSQL_QUERY("INSERT INTO shoutbox (artist_name,name,message)". "VALUES ('$artist_name','$name', '$message')"); } [/code]
-
Limit the number of rows created in a database? *SOLVED*
crzyman replied to crzyman's topic in PHP Coding Help
Thanks Huggie. I wish I could say it worked but no such luck. These are the varibles I'm using. I moved the quotes outside the second to the last bracket. It runs, but it won't update the db. [code] $sql = mysql_query("UPDATE shoutbox SET message='$message', time=now() WHERE artist_name='$artist_name' AND time=(SELECT min(time) FROM shoutbox WHERE artist_name='$artist_name')"); [/code] Any thoughts? -
Limit the number of rows created in a database? *SOLVED*
crzyman replied to crzyman's topic in PHP Coding Help
Sorry. I want to thank you. I really apriciate your time ant patience. Here is what i have now. [code] if ($num_rows == "5") { $sql = "UPDATE shoutbox SET message = '$message', date = now() WHERE artist_name = '$artist_name' AND date = (SELECT min(date) FROM shoutbox WHERE artist_name = '$artist_name')"; } else { $sql=MYSQL_QUERY("INSERT INTO shoutbox (artist_name,name,message)". "VALUES ('$artist_name','$name', '$message')"); } [/code] The table shoutbox is set up like this: artist_name varchar(40) id int(11) name text message longtext time datetime (I changed this from timestamp as per your advice) Thanks agian. -
Limit the number of rows created in a database? *SOLVED*
crzyman replied to crzyman's topic in PHP Coding Help
This is what I have now, it will insert if less than five, but will not update. I feel we are getting close. Any ideas. Thanks. [code] if ($num_rows == "5") { $sql = "UPDATE shoutbox SET message = '$message' WHERE time= (SELECT min(date) FROM shoutbox WHERE artist_name = '$artist_name')"; } else { $sql=MYSQL_QUERY("INSERT INTO shoutbox (artist_name,name,message)". "VALUES ('$artist_name','$name', '$message')"); } [/code] -
Limit the number of rows created in a database? *SOLVED*
crzyman replied to crzyman's topic in PHP Coding Help
I am using timestamp. This is the code I now have, but nothing is being entered into the database. Please help, I'm so confused. [code] if ($num_rows == "5") { $sql = "UPDATE shoutbox SET message = '$message' WHERE time= (SELECT min(date) FROM shoutbox WHERE artist_name = '$artist_name')"; } else { $sql = "INSERT INTO shoutbox (artist_name, name, message) VALUES ($artist_name, $name,$message)"; [/code] -
Limit the number of rows created in a database? *SOLVED*
crzyman replied to crzyman's topic in PHP Coding Help
O-k, great. I've now have the row time in my table set up as timestamp, so i am no longer inserting the time into the row. It is created automaticly. This is how my code looks to delete the row if it is more than five: [code] <?php mysql_connect("localhost","name","password"); mysql_select_db("news"); $myValue = "Joe"; $result = mysql_query("SELECT * FROM shoutbox WHERE artist_name='$myValue'"); $num_rows = mysql_num_rows($result); if ( $num_rows > 5) { echo $myValue; echo "You have more then 5 rows."; mysql_query("DELETE FROM shoutbox WHERE artist_name='$myValue' ORDER BY timestamp LIMIT 1"); } ?> [/code] Thank you. -
Limit the number of rows created in a database? *SOLVED*
crzyman replied to crzyman's topic in PHP Coding Help
Alright here is what I have, but it won't DELETE anything. I entered the time and date into each row using this format: [code] $time = date("h:ia m/d/y"); [/code] Here is the code I'm working on to delete the oldest rows if there are more than five rows. [code] <?php mysql_connect("localhost","name","password"); mysql_select_db("news"); $myValue = "Joe"; $result = mysql_query("SELECT * FROM shoutbox WHERE artist_name='$myValue'"); $num_rows = mysql_num_rows($result); if ( $num_rows > 5) { echo $myValue; echo " You have more then 5 rows."; $sql = MYSQL_QUERY("DELETE FROM shoutbox WHERE artist_name='$myValue' ORDER BY timestamp LIMIT 5"); } ?> [/code] Any advice? Thanks. -
Is there a way to limit the number of rows that are created in a database? I have a shoutbox that keeps track of the id, artist_name, name, message, and date. When a user enters his name and message a new row in the database get created and stores the id, artist_name, name, message, and date. Now what I want to do is limit the number of rows that are created for say artist_name: "Joe". When five users post comments five rows get created. When the sixth user enters a comment I want the first comment(row in the database) to be deleted and the sixth to be created, hence only five rows in the database for "Joe". I think this might be asking a bit to much for php, but its never let me down before. Any ideas. Thanks.
-
Thank you so very much. Its working great.
-
Hello. This is driving me nuts. I have a page that loads information from a database into a page using the include statement. So if the varible $name = "Joe" then it will pull all the information from the database for joe. This works great. Now I am trying to make a shout box on the page. This is my code: comment.php [code] <?PHP $myValue = "Joe"; ?> <form action="test.php" method="GET"> <INPUT TYPE='TEXT' value='name' NAME='name' SIZE=30 maxlength='100'><br> <INPUT TYPE='TEXT' value='message' NAME='message' SIZE=30 maxlength='100'> <input type="hidden" name=$myValues <input type="submit" name="submit" value="submit"> </form> [/code] This creates the form that allows a user to enter his/her name and message. It calls test.php, which looks like this: [code] <? mysql_connect("localhost","name","password"); mysql_select_db("news"); $artist_name = $_GET['$myValues']; if($submit) { $time=date("h:ia d/j/y"); $result=MYSQL_QUERY("INSERT INTO shoutbox (id,artist_name,name,message,time)". "VALUES ('NULL','$artist_name','$name', '$message','$time')"); } ?> [/code] The information for $myValue doesn't get entered into the database. The rest of it works. Somehow I have to pass the value of $myValue to the script, test.php, from the form which is comment.php. Can this even be done or am I way out of key here? Please advise.
-
Thank you for your help.