
- You are not logged in. | Login
December 20, 2006 12:39 pm
- admin
- Administrator


Discuss article: "Working with MySQL: Detailed"
We sugest you to leave your comments
Discussed article: "Working with MySQL: Detailed"
April 6, 2007 9:52 am
- mambojim
- Member


Re: Discuss article: "Working with MySQL: Detailed"
Data like DATE, TIME, DATETIME and TIMESTAMP can be formatted by means of function date_format (look mysql manual). Use it and don’t format data through php- it’s just a waste of system resources.
Don’t you think that MySQL wastes the same system resources when formatting data… Although if server of data base management system is on another machine, the other ones are spent, of course. However it’s the same.
April 6, 2007 10:37 am
- Stre@m
- Member


Re: Discuss article: "Working with MySQL: Detailed"
you are to process it by means of intval: $id = intval($id)).
It will be shorter: $id = (int) $id. And you also have forgotten about a rather useful thing - LIMIT
$somefield = str_replace("'", "'", $somefield).
Hmmm... Maybe it’s right to write $somefield = str_replace("'", "", $somefield)?
April 6, 2007 11:11 am
- monkeydude
- Member


Re: Discuss article: "Working with MySQL: Detailed"
$somefield = str_replace("'", "'", $somefield).
Hmmm... Maybe it’s right to write $somefield = str_replace("'", "", $somefield)?
Maybe it’s possible just to suppress everything (except for a-z 0-9 – seriously, does someone use logins like ##john or $%^peter?) From the line got all the SQL keywords are excluded.
If it is a user name and he desired a strange name which is similar to an SQL-request by registration, message like “This name is already possessed” is displayed…
It should be much simpler. And there is nothing about data base projecting methodology here. These are just elementary things. You would say what do ‘they’ need it for? It would be rather useful for ‘us’…Somethimes… Others are going to work with DB after us. I don’t want to be abused due to the fact only that some time ago I believed myself to be a great Programmer.
April 6, 2007 11:49 am
- Stre@m
- Member


Re: Discuss article: "Working with MySQL: Detailed"
What for do you need functions if this navigation string is used on the page once only? Isn’t it simpler to include or request pages.inc which draws the necessary string and get current page along with number of pages within a request in the main page? It will also enable you to take into account specificity of request – filtration, sorting and it is also useful to indicate ‘page 5 of 2b’ at the top of a page.
You are not going to verify number of pages – such a client can always be found who is interested in entering a big number with hands.
Navigation string can be used twice – if there are two lists on a page (although it is a rather sophisticated variant
) The thing is that include and require for data output are forbidden by me as far as I use templates. Following is done there:
$page->assign(array("limit" => get_limit(...), "nav_bar" => draw_bar(...)));
Last edited by Stre@m (April 10, 2007 7:03 am)
April 10, 2007 7:18 am
- purplebean
- Member


Re: Discuss article: "Working with MySQL: Detailed"
This all is rather simple and nice but it would be better to continue (extend) the article for the case when some sources for resulting list formation (which may have different structure) exist (are used).
April 10, 2007 7:31 am
- Stre@m
- Member


Re: Discuss article: "Working with MySQL: Detailed"
if ($count/2==intval($count/2))
Replace it with $count & 1. After this I’m not likely to read the rest.
$amount = @mysql_result(mysql_query("SELECT count(id) as goods_total FROM goods"),0);
What is this? 
list ($amount) = mysql_fetch_row (...); Isn’t it better?
Last edited by Stre@m (April 10, 2007 7:32 am)
April 10, 2007 7:43 am
- Conker
- Member


Re: Discuss article: "Working with MySQL: Detailed"
All these variants are good for that case only when everything is divided into entries. And what can we do with variants when large piece of text is included into the field and we need to divide it into pages depending on the number of lines which user is likely to see on a page? Are there any algorithms? I’ve been trying for a long time…
April 10, 2007 7:56 am
- SRG
- Member


Re: Discuss article: "Working with MySQL: Detailed"
It’s a perfect script. Thanks! The only bug has been mentioned when working (or isn’t it a bug?) – if the general lines’ number is less than number of lines on the page, all lines from the table are put out…
April 10, 2007 8:06 am
- cplusplus
- Member


Re: Discuss article: "Working with MySQL: Detailed"
Is it possible to insert text from a text file, for instance, CSV into phpMyAdmn?
April 10, 2007 8:40 am
- tucansam
- Member


Re: Discuss article: "Working with MySQL: Detailed"
I have such a question. What is more productive in this case: to use LIMIT and get 2 queries to the base as a result (one of them is count and the other one is basic) or select all entries at once and do mysql_data_seek afterwards?
April 10, 2007 8:47 am
- Stre@m
- Member


Re: Discuss article: "Working with MySQL: Detailed"
You’d better make one query with count and another one with LIMIT. But count won’t suit if you have grouping in your query.
April 10, 2007 9:04 am
- Keeper
- Member


Re: Discuss article: "Working with MySQL: Detailed"
I have lots of news on my site. I divide them among pages (each page having N news). News are sorted on date in drawback order (the newer ones come first). In some time the very first news is going to appear on M page which means that URL will look like page.php?page_number=M Some time ago this news was on M-K page and it was exactly the moment when it was indexed by search engines. Then it is going to display this URL that hasn’t been possessing this news for a long time. Thus someone is very unlikely to be satisfied with such pages division method. Somehow we are to make URL look like page.php?page_where_first_news_id=L. Then a query will look like select (...) from news where news_id < $page_where_first_news limit N. It’s clear how to get URLs of the previous and the next page. But I cannot realize how to calculate URL of the page I. Are there any ideas about how to manage it with the minimal queries’ number?
April 10, 2007 9:33 am
- mmwfan
- Member


Re: Discuss article: "Working with MySQL: Detailed"
We have a site written in PHP. We keep examining it and learning.
The problem is following. Everything is mixed on the site at the moment. The entire information is obtained from the base. We’d like to systemize this information according to the themes. But it isn’t clear how to do it via PHP. How to form query to the base in such a way that only the information needed will be displayed on the page? I’m not likely to involve the base. I’d like to limit myself with rewriting queries only. I.e. sorted data should be already present on the page.
There is one more thing. A file without extension weighing 280kb is saved on the server. As far as there is nothing else similar to the base I’ve got a suggestion that there is a base itself. Is it necessary for a MySQL-base to have an extension? And what extension should it be?
April 10, 2007 9:38 am
- Stre@m
- Member


Re: Discuss article: "Working with MySQL: Detailed"
Base is a directory in which files are paced (three files for each table). All of them have got extensions.
April 10, 2007 9:47 am
- selmahyekishot
- Member


Re: Discuss article: "Working with MySQL: Detailed"
It makes sense to use most MySql sub-functions in WHERE by tables’ joining only.
In the rest of cases it’s just overloading of the base.
April 10, 2007 9:54 am
- Stre@m
- Member


Re: Discuss article: "Working with MySQL: Detailed"
And reducing of loading on PHP due to simplifying of syntactic constructions.
April 10, 2007 12:32 pm
- cplusplus
- Member


Re: Discuss article: "Working with MySQL: Detailed"
Gentlemen, tell me please if the second parameter under Unix is necessary by mysql_query:
$res=mysql_query($qstring)
$res=mysql_query($qstring,$conn)
The first string works under windows and as to Unix I have been criticized severely for the second one although it works there as well 
April 10, 2007 12:50 pm
- Stre@m
- Member


Re: Discuss article: "Working with MySQL: Detailed"
cplusplus, look up documentation. We can see:
resource mysql_query (string query [, resource link_identifier])
mysql_query() sends a query to the currently active database on the server that's associated with the specified link identifier. If link_identifier isn't specified, the last opened link is assumed. If no link is open, the function tries to establish a link as if mysql_connect() was called with no arguments, and use it.
What questions do you have? It simply can be a bit obscure which resource is used by overview of text. But for me this situation seems to be quite normal as far as I’m familiar with Perl in which defaults are used frequently.
April 10, 2007 12:55 pm
- sirburpsalot
- Member


Re: Discuss article: "Working with MySQL: Detailed"
How about building tree with one selection?
Like:
id,pid,text
pid=Parent Id
What can you tell about it?
April 10, 2007 1:06 pm
- yendii
- Member


Re: Discuss article: "Working with MySQL: Detailed"
I’ve got such a problem… Paginal sorting has already passed into history. I’d like to create news’ archive on years and months. News’ date is of the DATE type in format YYYY-MM-DD... How can I realize it? Or should I make every page separately?
April 10, 2007 1:13 pm
- napkdd1
- Member


Re: Discuss article: "Working with MySQL: Detailed"
I also had to make some tens of units with paginal output. Thank you for saving me so much time. The functions are perfect.
April 10, 2007 1:30 pm
- mellis
- Member


Re: Discuss article: "Working with MySQL: Detailed"
This all is good only in case when there are few entries in the base. And what if I have 100000 entries? Can you imagine that each string will contain pages’ numbers? It will occupy at least half the screen. But you are not to suggest something like displaying greater number of strings on a page. There are some interesting solutions but I’d like something better and nicer. Who would like to write a universal script for displaying pages?
April 10, 2007 1:41 pm
- Stre@m
- Member


Re: Discuss article: "Working with MySQL: Detailed"
Only 5 neighbour pages are put out in this string. If you need more, it's quite possible to do.
April 10, 2007 1:57 pm
- steven9x
- Member


Re: Discuss article: "Working with MySQL: Detailed"
if ($count/2==intval($count/2))
It's not the best variant. It isn't nice!!!
I do it like this:
$bgcolor=array("#eeeeee", "#fafafa");
for ($i=0, $y=count($post); $i<$y; $i++) {
print "<tr bgcolor=".$bgcolor[($i % 2)]."><td></td></tr>";
}//forIt's not a problem to apply this idea here...
The code of my own works without any problems. At this it is 5 times shorter and it doesn't have bugs which were discussed above...


