johny_d 23 Junior Poster in Training

Your regex pattern has two problems:
1. it has * as the character counter, which means "0 or any number of charcaters frm the class".
This means that a string containing even none (0) of your characters will match your expression
2. you didn't specify that there cannot be other characters before and after the pattern
Here is how it should be:

$ids_list = '112,5,16,4578';
 
if (preg_match('/^[0-9,]+$/', $ids_list))
  echo'OK!';
else
  echo'KO!';

The "+" sign after the character class says there should be at least 1 character from there
The ^ at the beginning and $ at the end say you cannot have other characters before and after the string matching your pattern.
However, this solution will also match "," - a single comma string.
Maybe a better one would be

$ids_list = '112,5,16,4578';
 
if (preg_match('/^[0-9]+(,[0-9]+)*$/', $ids_list))
  echo'OK!';
else
  echo'KO!';

This matches a string containing a group of 1 or more digits, followed by 0 or more groups of a comma followed by some digits
;)

johny_d 23 Junior Poster in Training

Why do you have to use replace?
Cant you just append the random password to the and of the string without XXXXX ?
Like this

<?php
$password = rand(12345,98765);
$stringtoparse = 'Your new password is ' . $password;
echo $stringtoparse;
?>
Carrots commented: Thanks for the help :) +2
johny_d 23 Junior Poster in Training

Here's a very simple mysql solution:

<?php
mysql_query('UPDATE dealers AS d, (SELECT agent, COUNT(*) AS agentcount, registration_timestamp FROM users GROUP BY agent) AS u
SET d.thisperiodusercount = u.agentcount + d.usercountbalance
WHERE d.username = u.agent AND u.registration_timestamp > d.registration_timestamp AND u.registration_timestamp < d.expiredtime') or die(mysql_error());

I'd suggest you don't use the dealer username as a key in users table; use dealer ID instead! It's basic mysql:
first of all, numeric keys have amuch smaller fingerprint in the db and work much faster than textual keys
second: if you used username as a key and a dealer should change his uername at some point, you would have to update all the rows in the users table that correspond to that dealer ;)

x86phre3x commented: The code provided by this user works exactly as what I intended and it's simpler than what I have imagine. +0
johny_d 23 Junior Poster in Training

You can do it like that, but that's not the optimised way to do it.
You have what is called multiple-to-multiple relationship (many users with many hobbies).
So the principle to connect one to the other is to have a table that defines each one (one table for users and one table for hobbies) and a third table to tie one to the other.
This would be like this:

Users_table:
user_id | username |....
1 | John | ...
2 | Bill | ...
3 | Kate | ...
...

Hobbies_table:
hobby_id | hobby_name
1 | stampcollection
2 | fishing
3 | photography
...

Users_to_hobbies_table
id | user_id | hobby_id
1 | 1 | 1
2 | 1 | 3
3 | 2 | 1
4 | 2 | 2
5 | 3 | 2
6 | 3 | 3
...

We only store the usernames and hobbies names once and than we only work with their IDs, which are very fast and very lightweight for the database to manage.

The third table tells us that:
John like stampcollection and photography
Bill likes stampcollection and fishing
Kate likes fishing and photography

Let's say you want to find users who like phishing, you would do a query like this:

SELECT u.* FROM users_table AS u, hobbies_table AS h, users_to_hobbies_table AS …
almostbob commented: newly designed table is 400MB smaller, and noticebly faster +1
johny_d 23 Junior Poster in Training

Actually, kkeith29 example doesn't load new content in the original page; it just reloads the page with a parameter passed through the $_GET variable, and shows some text as a response of that parameter.
Since php is a server side script, which means it is processed on the server and only the result of the process is sent to the client (browser), in order to process any piece of php code (like an 'include' request), that piece of code must be passed through the server; you cannot execute php code inside the user browser; for that, you need to use a client side script (like javascript).
A simple approach to what you want is to insert in your page, from the beginning, in a hiddend block (div, p etc.), the piece of text that you want to show on click, and make a javascript that simply shows that block of text when you click the link.

If the block of text (or whatever it is) must be the result of a php script, than the only way you can insert that on the page on client side (without reloading the page) is through AJAX, which is, simply put, javascript communicating with the server (the php page in your case) without the page reload.

Eko commented: excelent +1
johny_d 23 Junior Poster in Training
<?php
$string = 'But i am not looking this simple one. what i am looking here is i searched a keyword (for eg php ). After searching I got some results from the database. if the result has a keyword php, then that all (php) word should be highlited. please help me';
$search_str = 'php';
function str_highlight ($string, $search_str) {
 if (trim($string) == '') {
  $return_str = 'Empty string';
  }
 elseif (trim($search_str) == '') {
  $return_str = 'Empty search string';
  }
 else {
// i put style="...." because i don't have a class="highlight" defined
  $return_str = preg_replace ("/$search_str/i",'<span class="highlight" style="background:#f00; color:#fff; font-weight:bold; padding:0 2px;">'.$search_str.'</span>',$string);
  }
 return $return_str;
 }
$new_str = str_highlight ($string, $search_str);
echo $new_str;
 
?>
stymiee commented: kudos +5
Shanti C commented: good +2
johny_d 23 Junior Poster in Training

You're most welcome ;)

jbennet commented: good job +12