Welcome to WebmasterWorld Guest from 18.206.48.142

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

You can SELECT * FROM with limits, but INSERT with limit?

mysql

     
3:30 am on Sep 29, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 23, 2007
posts: 82
votes: 0


This may seem like a silly question, but if you can limit the results you pull from MySQL, in theory couldn't you limit what you insert into the database? I found a good quick reference that may help others, but I don't see anything about what I am looking for.

<snip>

The reason I ask is because say for instance some commercial CMS systems allow only so many pages total for a certain price...greater than that a little more and so on. There has to be a way to limit the entries. Any help is appreciated.

Brad

[edited by: eelixduppy at 7:20 am (utc) on Sep. 29, 2007]
[edit reason] removed url [/edit]

8:39 am on Sept 29, 2007 (gmt 0)

New User

10+ Year Member

joined:Sept 28, 2007
posts:7
votes: 0


Hi,
i dont knoe about the limit in the sql statment but you can create the limit in your PHP script.
if you'll post your sql , maybe new ideas will come

Cheers,

3:18 am on Sept 30, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 23, 2007
posts: 82
votes: 0


Thank you for the reply. The code portion containing the SQL statement wasn't long so I just posted that whole php code section.

<?php
require_once "validator_file.php";

if ($HTTP_POST_VARS){
$validator = new Validator();
$validator->validateGeneral($HTTP_POST_VARS['page_no'], EDITOR_PAGE_NO);
$validator->validateGeneral($HTTP_POST_VARS['title'], EDITOR_CATEGORY_TITLE);
$validator->validateGeneral($HTTP_POST_VARS['fckeditor'], EDITOR_CONTENT);

if ( $validator->foundErrors() ){
echo '<b style="color:#C92E2A; font-size:12px;"> '. ERROR_PLEASE_INSERT .' </b> <br /><i>'.$validator->listErrors('<br>').'</i><br><br />';
}else{
//database_connect();
[b]$insert = "INSERT INTO
category (title, text, keywords, metaDesc, robots, box1, box2, page_no)
VALUES ('$title', '$fckeditor', '$keywords', '$metaDesc', '$robots', '$box1', '$box2', '$page_no')";[/b]

if ($query3 = mysql_query($insert) or die(mysql_error())){

echo '<b> '. DATABASE_SUCCESS .' </b><br><br>';

}else{

echo('<p>MySQL Error #' . mysql_errno() . '</b><br>' . mysql_error() .'</p>');

}
}
}
?>


Sorry about the link eelixduppy, no harm intended. Thank you for any suggestions on this.
Brad
5:09 am on Sept 30, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 15, 2004
posts:1867
votes: 0


I couldn't see the point of putting any kind of limit on your insert statement. It is just inserting once, I believe.

If there was a certain kind of loop or anything which makes the insert statement to run again, you might want to have the limit. But I don't see why you need it now.

9:09 am on Sept 30, 2007 (gmt 0)

New User

10+ Year Member

joined:Sept 28, 2007
posts:7
votes: 0


i agree with Habtom
8:31 pm on Sept 30, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 23, 2007
posts: 82
votes: 0


Your right the INSERT statement only inserts the info once to the database. I needed to word it differently...basically I want to limit the number of times a new page can be added.

For instance...if the CMS system only allows a total of 10 pages to be added, and there are currently 10 pages...when the user goes to add the 11th page they will get an error saying something like "No more pages can be added at this time". Not sure how to create this in php...any ideas?

8:38 pm on Sept 30, 2007 (gmt 0)

New User

10+ Year Member

joined:Mar 12, 2007
posts: 26
votes: 0


There is no such feature for MySQL. If you want to limit the number of rows for some reason, get the current number of rows before inserting and show an error if it's >= 10.
12:00 pm on Oct 1, 2007 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15756
votes: 0


select the count from mysql before you do the insert and if 10 pages already exist, then display the error
12:55 pm on Oct 1, 2007 (gmt 0)

New User

10+ Year Member

joined:Mar 12, 2007
posts: 26
votes: 0


Isn't that exactly what I just said?
12:59 pm on Oct 1, 2007 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15756
votes: 0


yep, I obviously missed that somehow
6:09 pm on Oct 2, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 23, 2007
posts: 82
votes: 0


Thank you for the replies. I haven't had much time to mess with this at the moment, but will hopefully be able to give it a shot sometime this week.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members