Unable to jump to row 0

Started on the old forum in December 2013 · view the original in the archive · old links redirect here

18 replies · 904 views · started 12 years ago · 1 min read

TL;DR · summary of 18 replies
  • tzapone asked about fixing a code issue related to jumping to row 0, but no solution was provided.
  • tzapone had another problem with spam detection in his code; the desired output wasn't achieved as expected.
  • Ghost suggested using preg_replace with modifiers for exact word matching and case insensitivity, which could solve the issue.
  • tzapone also asked about a VIP member feature on their site where color text options remain after the VIP period expires. A solution was provided by adding code to handle this scenario.

Written automatically from the replies by a language model on our own server. It can be wrong; the posts below are the source.

4 participants
tzapone Junior · 30 posts #1
$currD=date("d", time());
$currm=date("m", time());

$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `ank_d_r` = '$currD' and `ank_m_r` = '$currm'",$db), 0);
$k_bday=mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `ank_d_r` = '$currD' and `ank_m_r` = '$currm' LIMIT 1 "),0);
$bday=mysql_result(mysql_query("SELECT `id` FROM `user` WHERE `ank_d_r` = '$currD' and `ank_m_r` = '$currm' LIMIT 1 "),0);

$sisa=$k_post-1;

echo '<div class="p_t2">';

if($k_post==0){
echo "";
}

if($k_post==1){
echo "<table class='notif' width='100%'><tr><td width='2%'><img src='/style/icons/ultah.png'> <a href='/info.php?id=$bday'>$k_bday</a> sarbatoreste azi ziua de nastere</td></tr></table>";
}
if($k_post>=2){
echo "<table class='notif' width='100%'><tr><td width='2%'><img src='/style/icons/ultah.png'> <a href='/info.php?id=$bday'>$k_bday</a> si <a href='/list_bday.php?SESS=$sess'> inca $sisa </a> sarbatoresc azi data nasterii </td></tr></table>";

}

i received 2 errors in lines:

$k_bday=mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `ank_d_r` = '$currD' and `ank_m_r` = '$currm' LIMIT 1 "),0);
$bday=mysql_result(mysql_query("SELECT `id` FROM `user` WHERE `ank_d_r` = '$currD' and `ank_m_r` = '$currm' LIMIT 1 "),0);

what is wrong in this code?

tzapone Junior · 30 posts #2
$k_post=mysql_fetch_row(mysql_query("SELECT COUNT(*)FROM`user`WHERE`ank_d_r`='$currD'&&`ank_m_r`='$currm'",$db));
$k_post=$k_post[0];
$k_bday=mysql_fetch_row(mysql_query("SELECT`nick`FROM`user`WHERE`ank_d_r`='$currD'&&`ank_m_r`='$currm' LIMIT 1"));
$k_bday=$k_bday[0];
$bday=mysql_fetch_row(mysql_query("SELECT`id`FROM`user`WHERE`ank_d_r`='$currD'&&`ank_m_r`='$currm' LIMIT 1"));
$bday=$bday[0];

i put like this and it work. Sorry for the topic. You cand delete or close.

something else Fellow · 2,296 posts #3

A "like" for finding out the answer yourself 🙂

tzapone Junior · 30 posts #4

thanks 😀 but now i have another problem . Not an error , but i don't like how the code works:

$q1=mysql_query("SELECT * FROM `banned_word`");
while ($spam = mysql_fetch_assoc($q1))
{
$str=str_replace($spam['text'],$spam['word'],$str);
} 

I want to make a spam detection, i put in db a word like : mama and should appear mm . Untill now is perfect, but when i write mamamia appera mmmia. How to change the code to appear the word mamamia corect? without spam filter.

something else Fellow · 2,296 posts #5

So why not put it in your spam block as "mama " (with space at end)

tzapone Junior · 30 posts #6

if i put with space end the word mama appear mama 😛 without censure

something else Fellow · 2,296 posts #8

GumSlone wrote:

$str=str_replace($spam['text'].' ',$spam['word'],$str); 

I would go for:

$str=str_replace($spam['text'],$spam['word'],$str.' '); 

to avoid breaking any existing string replacements

tzapone Junior · 30 posts #9

GumSlone wrote:

$str=str_replace($spam['text'].' ',$spam['word'],$str); 

if i put this code the word's appears without cenzure, and the other code appear the same: mama = mm

<?
// 
// 
function output_text($str,$br=1,$html=1,$smiles=1,$links=1,$bbcode=1)
{
	global $theme_ini;
	
$q1=mysql_query("SELECT * FROM `spam`");
while ($spam = mysql_fetch_assoc($q1))
{
$str=str_ireplace($spam['text'],$spam['sait'],$str);

}

	//if ($br && isset($theme_ini['text_width']))$str=wordwrap($str, $theme_ini['text_width'], ' ',1);

	if ($html)$str=htmlentities($str, ENT_QUOTES, 'UTF-8'); // 

	if ($links)$str=links($str); //

	if ($smiles)

		$str=smiles($str); // 

	if ($bbcode)
	{
		$tmp_str=$str;
		$str=bbcode($str); // 
	}

	if ($br)
	{
		$str=br($str); // 
	}

	return stripslashes($str); // 
}

// 

function input_value_text($str){return output_text($str,0,1,0,0,0);}

function rez_text( $text, $maxwords = 15, $maxchar = 100 ){
	$sep=' ';

	$sep2=' »';

	$words = explode($sep,$text);

	$char = iconv_strlen($text,'utf-8');

	if (count($words) > $maxwords){		$text = join($sep, array_slice($words, 0, $maxwords));
	}

	if ( $char > $maxchar ){
		$text = iconv_substr( $text, 0, $maxchar, 'utf-8' );

	}

	return $text.$sep2;
}

function rez_text2( $text, $maxwords = 70, $maxchar = 700 )
{
$sep=' ';

$sep2='';

$words = explode($sep,$text);

$char = iconv_strlen($text,'utf-8');

if (count($words) > $maxwords){
$text = join($sep, array_slice($words, 0, $maxwords));

}

if ( $char > $maxchar ){
$text = iconv_substr( $text, 0, $maxchar, 'utf-8' );

}

return $text.$sep2;

}

function rez_text3( $text, $maxwords = 150, $maxchar = 1500 ){
$sep=' ';

$sep2='';

$words = explode($sep,$text);

$char = iconv_strlen($text,'utf-8');

if (count($words) > $maxwords){
$text = join($sep, array_slice($words, 0, $maxwords));

}

if ( $char > $maxchar ){
$text = iconv_substr( $text, 0, $maxchar, 'utf-8' );

}

return $text.$sep2;
}
?>

this is my output text php file

something else Fellow · 2,296 posts #10

something else wrote: So why not put it in your spam block as "mama " (with space at end)

something else wrote: I would go for:

$str=str_replace($spam['text'],$spam['word'],$str.' '); 

to avoid breaking any existing string replacements

These 2 work together correctly - if they are not working for you, then you need to delete the original "mama"

tzapone Junior · 30 posts #11

i deleted, i try with space at the end, et the beggining. The same, when i write mamamia appear mmmia

Ghost Senior · 366 posts #12

tzapone wrote: i deleted, i try with space at the end, et the beggining. The same, when i write mamamia appear mmmia

you could try using preg_replace instead. using the \b modifier and the i modifier. you can match just the words your looking for exactly. and also upper and lower case char.

something like:

$str = preg_replace(trim('/\b'.$spam['text'].'\b/i'), trim($spam['word']), $str);

which should then match mama. Mama. MaMa etc. but not match mamamia

<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>
tzapone Junior · 30 posts #13

Ghost wrote: you could try using preg_replace instead. using the \b modifier and the i modifier. you can match just the words your looking for exactly. and also upper and lower case char.

something like:

$str = preg_replace(trim('/\b'.$spam['text'].'\b/i'), trim($spam['word']), $str);

which should then match mama. Mama. MaMa etc. but not match mamamia

yes is very good 😀 but need one more update. If i put wink for example like spam word , and i write .wink. ( to show smiley ) appear .wi*k. If you can fix that is a perfect code.

something else Fellow · 2,296 posts #14

tzapone wrote: i deleted, i try with space at the end, et the beggining. The same, when i write mamamia appear mmmia

exactly you put a space at the start which matched " mama"mia - where as just at the end would have matched lol

tzapone Junior · 30 posts #15

thank you all for help 🙂

One more important question i have for you guy. I put on my site VIPMEMBERS activated by time ( 1 day, 2 days etc... ) . Everything is good, but if a member activated for example the option color text, this option will remain after the vip period expires and i don't want that. I try something like this:

$membruvip = mysql_result(mysql_query("SELECT COUNT(*) FROM `vipuri` WHERE `id_utilizator` = '$user[id]' AND `time` > '$time'"), 0);
if ($membruvip==0)
{
echo " ".output_text($statuse['msg'])." ";
}else{
echo "<span style=\"color:$profil[culoaretext]\">";
echo " ".output_text($statuse['msg'])." ";
echo "</span>\n";
} 

but not work very well. If you are not a vip member you can't see any color and if you are a vip member you can see all the color ( even if the user cu vip expires post a message). this is the page where you can activate vip member. Maybe you may know how after the vip expires the color text , and color nick set to mod default.

<?
include_once '../../sys/inc/start.php';
include_once '../../sys/inc/compress.php';
include_once '../../sys/inc/sess.php';
include_once '../../sys/inc/home.php';
include_once '../../sys/inc/settings.php';
include_once '../../sys/inc/db_connect.php';
include_once '../../sys/inc/ipua.php';
include_once '../../sys/inc/fnc.php';
include_once '../../sys/inc/adm_check.php';
include_once '../../sys/inc/user.php';

$set['title'] = 'Membri vip';
include_once '../../sys/inc/thead.php';
title();

if (!isset($user))
header("location: /index.php?");

err();
aut();

if (isset($user))
{
if (isset($_POST['stav']) && isset($_POST['msg']))
{
if ($_POST['stav']==1)
{
	$st=1;
	$tm=$time+86400;
	$vipstatut=1;
}
else if ($_POST['stav']==2)
{
	$st=2;
	$tm=$time+172800;
	$vipstatut=1;
}
else if ($_POST['stav']==3)
{
	$st=3;
	$tm=$time+259200;
	$vipstatut=1;
}
else if ($_POST['stav']==4)
{
	$st=4;
	$tm=$time+345600;
	$vipstatut=1;
}
else if ($_POST['stav']==5)
{
	$st=5;
	$tm=$time+432000;
	$vipstatut=1;
}
else if ($_POST['stav']==6)
{
	$st=6;
	$tm=$time+518400;
	$vipstatut=1;
}
else if ($_POST['stav']==7)
{
	$st=7;
	$tm=$time+604800;
	$vipstatut=1;
}

else if ($_POST['stav']==8)
{
	$st=30;
	$tm=$time+2592000;
	$vipstatut=1;
}
else if ($_POST['stav']==9)
{
	$st=365;
	$tm=$time+31536000;
	$vipstatut=1;
}
$msg=my_esc($_POST['msg']);

if ($user['money']>=$st)
{
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `liders` WHERE `id_user` = '$user[id]'"), 0)==0)
{
	//mysql_query("INSERT INTO `liders` (`id_user`, `stav`, `msg`, `time`, `time_p`) values('$user[id]', '$st', '".$msg."', '$tm', '$time')");
	mysql_query("INSERT INTO `liders` (`id_user`, `stav`, `msg`, `time`, `time_p`, `vipstatut`) values('$user[id]', '$st', '".$msg."', '$tm', '$time', '$vipstatut')");
	
}
else
{
	//mysql_query("UPDATE `liders` SET `time` = '$tm', `time_p` = '$time', `msg` = '$msg', `stav` = '$st' WHERE `id_user` = '$user[id]'");
	
	mysql_query("UPDATE `liders` SET `time` = '$tm', `time_p` = '$time', `msg` = '$msg', `stav` = '$st', `vipstatut` = '$vipstatut' WHERE `id_user` = '$user[id]'");
}

mysql_query("UPDATE `user` SET `money` = '".($user['money']-$st)."' WHERE `id` = '$user[id]' LIMIT 1");

$_SESSION['message'] = 'Ai devenit cu succes membru vip!!';
header("Location: /user/liders/index.php?ok");
exit;

}else{
$err='Nu ai suficiente monede pentru a deveni membru vip';
}
}else{
$err='Statusul nu poate fi gol';
}
err();

echo '<div class="foot">';
echo '<img src="/style/icons/str2.gif" alt="S"/> <a href="/user/money/">Servicii extra</a> | <b>Membru vip</b>';
echo '</div>';

echo '<div class="mess">';
echo 'Pentru a ajunge membru vip trebuie sa ai in cont cel putin <b style="color:red;">1</b> <b style="color:green;"> diamant </b>. Acest serviciu este 
calculat pe zi, zi in care ne vom asigura ca vei in TOP. Pozitia ta in TOP depinde de numarul de diamante (timpul total de inchiriere)! 
In plus, profilul tau va putea fi vizibil prin rotatie in sectiunea Dating si Conectati!';
echo '</div>';

echo '<form class="main" method="post" action="?">';
	echo '<span style="color: red">Vreau sa fiu vip timp de:</span> <select name="stav">
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
	<option value="4">4</option>
	<option value="5">5</option>
	<option value="6">6</option>
	<option value="7">7</option>
	<option value="8">30</option>
	<option value="9">365</option>
	</select> zile<br />';
	
echo 'Status membru vip (100 caractere)<textarea name="msg"></textarea><br />';

echo '<input value="Fa-ma vip" type="submit" />';
echo '</form>';
}

echo '<div class="foot">';
echo '<img src="/style/icons/str2.gif" alt="S"/> <a href="/user/money/">Servicii extra</a> | <b>Membru vip</b>';
echo '</div>';

include_once '../../sys/inc/tfoot.php';
?>

Added after 6 minutes:

I think with something like this can be done:

mysql_query("UPDATE `user` SET `color` = '"default"' WHERE `id` = '$user[id]' LIMIT 1");

but i don' know where to put it in this file 🙁

Added after 42 minutes:

problem solved with:

$membruvip = mysql_result(mysql_query("SELECT COUNT(*) FROM `liders` WHERE `id_user` = '$user[id]' AND `time` > '$time'"), 0);
if ($membruvip==0)
{
mysql_query("UPDATE `user` SET `mcolor` = '#000000' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("UPDATE `user` SET `ncolor` = '#3251FF' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("UPDATE `user` SET `ncolor2` = '#3251FF' WHERE `id` = '$user[id]' LIMIT 1");
}

in a file that is included in all the site. Somethimes i am so stupid 🙁 sorry for all my stupid posts.

tzapone Junior · 30 posts #16

i came with another problem and i hope is the last one:

<?php
include_once 'sys/inc/start.php';
include_once 'sys/inc/compress.php';
include_once 'sys/inc/sess.php';
include_once 'sys/inc/home.php';
include_once 'sys/inc/settings.php';
include_once 'sys/inc/db_connect.php';
include_once 'sys/inc/ipua.php';
include_once 'sys/inc/fnc.php';
include_once 'sys/inc/user.php';

$set['title']='Vanzare pestisori'; // заголовок страницы

include_once 'sys/inc/thead.php';
title();
err();
aut();

if(isset($user)){
//if($gconf[0]['open']!=1){

$action=htmlspecialchars(trim($_GET['action']));

switch ($action){

default:
echo "<div class='foot'>";
echo '1 pestisor = 20 de puncte<br/>';
echo '</div>';
echo "<div class='foot'>";
echo '<img src="/style/icons/fish.png" alt="+"> Ai prins <b>'.$user['extra_ball'].' pestisori</b><br/>';
echo '</div>';
echo "<div class='foot'>";
echo '<img src="/style/icons/many.gif" alt="+"> Ai in cont: <b>'.$user['balls'].'</b> puncte<br/>';
echo '</div>';
echo "<div class='p_t'>";
echo '<form action="vinde_pesti.php?action=change" method="post">';
echo 'Cati pesti vinzi?<br/>';
echo '<input name="num" type="text" value=""/><br/>';
echo '<input type="submit" value="Vinde"/>';
echo '</form>';
echo '</div>';
break;

case 'change':
$num=(int)$_POST['num'];
if(!$num || $num<1){echo 'Nu ai nici un pestisor!';break;};
if($user['extra_ball']<$num){echo 'Nu ai atati pestisori!';break;};
$baks=$num*20;
mysql_query("UPDATE `user` SET `balls`=`balls`+'$baks',`extra_ball`=`extra_ball`-'$num' WHERE `id`='".$user['id']."'");

echo 'Ai vandut cu succes pestisorul!';
break;

}
;
//}else{echo '<div class="msg">Jocul este oprit de catre administrator!</div>';};

}else{
echo '<div class="msg">Numai utilizatorii autentificati au acces!</div>';
};
echo '<div class="foot"><a href="/umenu.php">Meniul meu</a></div>';
include_once 'sys/inc/tfoot.php';
?>

i reveceive the error: Notice: Undefined index: action in /home/wapcomun/public_html/bere/vinde_pesti.php on line 23 on

$action=htmlspecialchars(trim($_GET['action']));

in this line. I don't know how to define $action.

something else Fellow · 2,296 posts #17

tzapone wrote: i came with another problem and i hope is the last one: i reveceive the error: Notice: Undefined index: action in /home/wapcomun/public_html/bere/vinde_pesti.php on line 23 on

$action=htmlspecialchars(trim($_GET['action']));

in this line. I don't know how to define $action.

$action = (isset($_GET['action'])) ? htmlspecialchars(trim($_GET['action'])) : '';
tzapone Junior · 30 posts #18

thank you. I will take a break untill next year. I wish you marry christmas and a happy new year 😀

Ghost Senior · 366 posts #19

tzapone wrote: yes is very good 😀 but need one more update. If i put wink for example like spam word , and i write .wink. ( to show smiley ) appear .wi*k. If you can fix that is a perfect code.

you could also try it like this:

$str = preg_replace(trim('/^\b'.$spam['text'].'\b$/i'), trim($spam['word']), $str);

adding the ^ modifier at start and $ modifier at end could possibly help further since it asks to match from the beginning and end exactly. which should then match wink Wink WiNk etc but not .wink.

<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close