Jump to content

help in this code please


hackerspk

Recommended Posts

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);
}

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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);
}

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.