hackerspk Posted July 26, 2011 Share Posted July 26, 2011 i am a newbie i make this script to add automatic link (href) in my site its working but i have 83000 titles in mysql dabase so this script is not executing now if there is any way to make this one better or there is an other way to do this work thanks $user_name = "root"; $password = ""; $database = "salar"; $server = "127.0.0.1"; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); if ($db_found) { $SQL = "SET NAMES 'utf8'"; mysql_query($SQL); $SQL = "SELECT * FROM dle_mylinks ORDER BY LENGTH( title ) DESC"; $result = mysql_query($SQL); while ($db_field = mysql_fetch_assoc($result)) { $row['full_story'] = str_replace ($db_field['title'],"<a href=\"?newsid=" . $db_field['id'] . "\">" . $db_field['title'] . "</a>" ,$row['full_story']); $row['short_story'] = str_replace ($db_field['title'],"<a href=\"?newsid=" . $db_field['id'] . "\">" . $db_field['title'] . "</a>" ,$row['short_story']); } $mydata =$row['short_story'] . $row['full_story']; mysql_close($db_handle); } else { print "Database NOT Found "; mysql_close($db_handle); } Quote Link to comment Share on other sites More sharing options...
Maq Posted July 26, 2011 Share Posted July 26, 2011 but i have 83000 titles in mysql dabase so this script is not executing now I'm a little confused about what's 'not executing'. Are you getting a blank screen? Errors? Timing out? What's happening? Quote Link to comment Share on other sites More sharing options...
WebStyles Posted July 26, 2011 Share Posted July 26, 2011 also not sure what you mean, but at a quick glance, you've got a database handle that you're not using... instead of mysql_query($SQL); try mysql_query($SQL,$db_handle); (in both places) also, you should consider creating a new mysql user instead of using root. hope this helps Quote Link to comment Share on other sites More sharing options...
hackerspk Posted July 26, 2011 Author Share Posted July 26, 2011 i got this error Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\salar\engine\modules\show.full.php on line 623 and i also use mysql_query($SQL,$db_handle); but i got same result Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\salar\engine\modules\show.full.php on line 623 and i also creat a new user for it but it not works Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 26, 2011 Share Posted July 26, 2011 There's no (good) reason to be retrieving and displaying 83000 pieces of information on one web page. You should be using pagination to display a manageable amount of information at one time. See this link - http://www.phpfreaks.com/tutorial/basic-pagination Quote Link to comment Share on other sites More sharing options...
WebStyles Posted July 26, 2011 Share Posted July 26, 2011 totally agree with PFMaBiSmAd. also you may want to check if your database has proper indexes to speed up searches. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 26, 2011 Share Posted July 26, 2011 Also you have a logic issue here while ($db_field = mysql_fetch_assoc($result)) { $row['full_story'] = str_replace ($db_field['title'],"<a href=\"?newsid=" . $db_field['id'] . "\">" . $db_field['title'] . "</a>" ,$row['full_story']); $row['short_story'] = str_replace ($db_field['title'],"<a href=\"?newsid=" . $db_field['id'] . "\">" . $db_field['title'] . "</a>" ,$row['short_story']); } $mydata =$row['short_story'] . $row['full_story']; The variable $mydata will only hold the value to the last row (83,000th row). The previous 82,999 rows will not be outputted at all. You also don't seem to be doing anything with the $mydata variable either. Quote Link to comment Share on other sites More sharing options...
hackerspk Posted July 26, 2011 Author Share Posted July 26, 2011 There's no (good) reason to be retrieving and displaying 83000 pieces of information on one web page. You should be using pagination to display a manageable amount of information at one time. See this link - http://www.phpfreaks.com/tutorial/basic-pagination iam not displaying 83000 pieces on one page it just replace a list of words with a hyperlink on them. but i think it will search for each word 83000 times. if iam true ? Quote Link to comment Share on other sites More sharing options...
hackerspk Posted July 26, 2011 Author Share Posted July 26, 2011 Also you have a logic issue here while ($db_field = mysql_fetch_assoc($result)) { $row['full_story'] = str_replace ($db_field['title'],"<a href=\"?newsid=" . $db_field['id'] . "\">" . $db_field['title'] . "</a>" ,$row['full_story']); $row['short_story'] = str_replace ($db_field['title'],"<a href=\"?newsid=" . $db_field['id'] . "\">" . $db_field['title'] . "</a>" ,$row['short_story']); } $mydata =$row['short_story'] . $row['full_story']; The variable $mydata will only hold the value to the last row (83,000th row). The previous 82,999 rows will not be outputted at all. You also don't seem to be doing anything with the $mydata variable either. hi listen this is a translator of a language Urdu to roman it translate on base of words for example player = blayer wild = vild so on and it work very good with 50000 words but when i increase the dictionary it is not working and also $mydata just display translated list of words if thery are in first row or in last. these are the results but i dont know if this code is good or bad help me please Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 26, 2011 Share Posted July 26, 2011 Your query is selecting all the rows within the dle_mylink table, and ordering the results by the size of the title in descending order (ie largest title to smallest title) $SQL = "SELECT * FROM dle_mylinks ORDER BY LENGTH( title ) DESC"; If that table has 83000 rows then it'll return 83000 results. The while loop will iterate over the results 83000 times. while ($db_field = mysql_fetch_assoc($result)) { $row['full_story'] = str_replace ($db_field['title'],"<a href=\"?newsid=" . $db_field['id'] . "\">" . $db_field['title'] . "</a>" ,$row['full_story']); $row['short_story'] = str_replace ($db_field['title'],"<a href=\"?newsid=" . $db_field['id'] . "\">" . $db_field['title'] . "</a>" ,$row['short_story']); } The code within the while loop (between the curly braces { and } ) will be executed for every row the query is returned. So if your query returns 83000 rows then those two lines WILL be executed 83000 times. After the while loop you have this line $mydata =$row['short_story'] . $row['full_story']; Here you are concatenating the $row['short_story'] and $row['full_story'] variables into one value and assigning that to the $mydata variable. The $mydata variable will only store the result from the very last row returned by your query. You are not doing anything with the previous 82999 rows, as the while loop will keep overwriting the $row['short_story'] and $row['full_story'] variables each time it processes the next row. Quote Link to comment Share on other sites More sharing options...
hackerspk Posted July 26, 2011 Author Share Posted July 26, 2011 oh ! please tell me how will it work good and fast ? thanks Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 26, 2011 Share Posted July 26, 2011 What are you trying to do? Quote Link to comment Share on other sites More sharing options...
hackerspk Posted July 26, 2011 Author Share Posted July 26, 2011 i just want to make a translator which tranlate from Urdu to Roman language for my site i have complete dictionary for this puorpose i just need a page who translate . thanks for your reply Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 26, 2011 Share Posted July 26, 2011 You would typically make a unique word list (from your $row['short_story'] and $row['full_story'] content) and then query the database table for just that list of words. Translating something implies displaying the translated words. The code you have posted is simply converting the original found words into links with with an id. That would require that someone click on each link/word to do something. Is that what you want? I would think that you would either want to replace the words or perhaps display the translation of the word when you hover the mouse over each original word? Perhaps, if you post a short example showing what a typical $row['short_story'] would be and what the final output should be? Quote Link to comment Share on other sites More sharing options...
hackerspk Posted July 26, 2011 Author Share Posted July 26, 2011 yes you are true in starting i want to make a link on it but now i think to translate whole paragraph using this code $user_name = "root"; $password = ""; $database = "salar"; $server = "127.0.0.1"; $mydata = "text to translate"; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); if ($db_found) { $SQL = "SET NAMES 'utf8'"; $SQL = "SELECT * FROM dle_roman ORDER BY LENGTH( roman ) DESC"; $result = mysql_query($SQL); while ($db_field = mysql_fetch_assoc($result)) { $mydata = str_replace ($db_field['urdu'],$db_field['roman'],$mydata); } echo $mydata; mysql_close($db_handle); } else { print "Database NOT Found "; mysql_close($db_handle); } Quote Link to comment Share on other sites More sharing options...
hackerspk Posted July 29, 2011 Author Share Posted July 29, 2011 if there is no solution for it ? Quote Link to comment 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.