johny_d 23 Junior Poster in Training

You would probably have to loop through the resultset and assign each row to an array; you can't just split the resultset;
it might be easier/faster to just have to queries with their own resultset

johny_d 23 Junior Poster in Training

UPDATE:

The query returns "0 row(s) affected". I'm still looking at the code, but if you find something, do let me know.

The code is fine, but it's probably something that don't match the real structure of your tables. Or maybe you don't have users/dealers in the db that match those conditions in the query.
Do a mysql export for the dealers and users tables structure and data, put it in a zip and post it here as an attachment, so I can test with the same structure and data you have.

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

First of all, why do you require the "Wordsarray.php" file in each cycle of the while loop?
You should include (require) that file only once, before the loop and than do the while loop.
Than, about your error, I can only guess here, since you didn't provide the $normal and $tidied arrays: my guess is the problem is from one of the values in the $normal array and the opening and closing slashes ("/" and "/i") of your matching strings.
Let me expalin: if one of the values (strings) from $normal array contains a slash (/), let's say the string is "abcde/gb--", than your matching string in your expression becomes "/abcde/gb--/i"; now, the problem is that, in this case" your script thinks the second slash (the one before gb--) is the closing one (instead of the third one, the one before i), so it takes every character after that slash (gb--/i) as a pattern modifier, which, of course, is an error: "g", "b", "-" are not valid modifiers.
So, check to see if you have any slash "/" in the values of the $normal array, and if you have, you must escape them (put a backslash before any slash) before inserting them in the regular expression.
You can also use some other delimiter ("#" for instance), if it doesn't appear in your pattern strings.
From PHP manual: If the delimiter character has to be used in the expression itself, it needs to be escaped …

johny_d 23 Junior Poster in Training

You should use:
for ($i = 0; $i <= 28; $i++) ......
since the keys of your $random_array are from 0 to 28

johny_d 23 Junior Poster in Training

$random_array = array_rand($sAdText, 3);

johny_d 23 Junior Poster in Training

Try this

$query_1 = "SELECT billingStatementNo, transactionDate, transactionType, subjectCode, clientID, attorneyID, rateHour, consumedHour, currency, legalFees, checkInvoice FROM billingstatement";
 
$result_1 = mysql_query ($query_1) or die (mysql_error());
if (mysql_num_rows($result_1) <1) {
die ('No data to transfer');
}
else {
while ($src_row = mysql_fetch_row($result_1)) {
$row = implode ("','",$src_row);
$query_2 = "insert into billingstatementhistory(billingStatementNo, transactionDate, transactionType, subjectCode, clientID, attorneyID, rateHour, consumedHour, currency, legalFees, checkInvoice) values ('$row')";
$result_2 = mysql_query($query_2) or die (mysql_error());
}
}
johny_d 23 Junior Poster in Training

Well, all that's there are basic tables that you can find in php manual.
The way you structure the tables is another thing and that you don't find in books. First, you have to understand what you want to accomplish and than how to put it in maths matrixes (which I think tables expressions are).

So, let's start with what we want to get:
we have 3 levels of info, each level being the parent of the next one.

level 0: PROCESS
level 1: STEP; has PROCESS as parent
level 2: SUBSTEP; has STEP as parent

so, we want 3 arrays, each with information from one level and the connection to its parent, so we can see later who's child is each table; (for the sake of the clearness I'll write without $ and quotes and any other php grammar; all I want is to emphasize the structure)

first one: process array
process[process_id] = process_name

second one: step array
What we want next is to create an array of steps (children) for each process;
step[process_id] (eg: step[1], step[2], step[3], where 1,2,3 are the ids of the parent processes
)
so if we have 3 processes in the process array, we'll have 3 step arrays, each one with its own pairs of keys=>values, which are the steps corresponding to the respective process.
Eg:
step[1] = array(s1_key_1=>s1_value_1, s1_key_2=>s1_value_2, ....);
This translates as: the steps for process …

johny_d 23 Junior Poster in Training

I'm glad to be of help ;)

johny_d 23 Junior Poster in Training

here's your code:

$query = "SELECT `process`.`process`,`process`.id as pid,step.step,step.id as sid,substep.substep, substep.id as bid FROM `process`, step, substep WHERE `process`.id =step.process_id AND step.id=substep.step_id";
$rows = mysql_query ($query);
     
while ($d  = mysql_fetch_assoc ($rows)) {
 $process[$d['pid']] = $d['process'];
 $step[$d['pid']][$d['sid']] = $d['step'];
 $substep[$d['sid']][$d['bid']] = $d['substep'];
 }
 
$result = "<ul>";
foreach ($process as $kp => $vp) {
 $result .= "<li>".$vp."\r\n <ul>\r\n";
 foreach ($step[$kp] as $ks => $vs) {
  $result .= "  <li>".$vs."\r\n  <ul>\r\n";
  foreach ($substep[$ks] as $kb => $vb) {
   $result .= "   <li>".$vb."</li>\r\n";
   }
  $result .= "  </ul></li>\r\n";
  }
 $result .= " </ul></li>\r\n";
 }
$result .= "</ul>\r\n";
 
echo $result;
johny_d 23 Junior Poster in Training

The error you get (...unexpected T_STRING ...) means you try to use an unquoted string; the mysql_query (the part between parenthesis) must be quoted.
Anyway, I'm not sure the mysql statement works that way!!!

johny_d 23 Junior Poster in Training

Try this:

$query = "SELECT `order`.`order`,`order`.id as oid,genus.genus,genus.id as gid,species.species, species.id as sid FROM `order`, genus, species WHERE `order`.id =genus.order_id AND genus.id=species.genus_id";
$rows = mysql_query ($query);
     
while ($v  = mysql_fetch_assoc ($rows)) {
 $order[$v['oid']] = $v['order'];
 $genus[$v['oid']][$v['gid']] = $v['genus'];
 $species[$v['gid']][$v['sid']] = $v['species'];
 }
 
$result = "<ul>";
foreach ($order as $ko => $vo) {
 $result .= "<li>".$vo."\r\n <ul>\r\n";
 foreach ($genus[$ko] as $kg => $vg) {
  $result .= "  <li>".$vg."\r\n  <ul>\r\n";
  foreach ($species[$kg] as $ks => $vs) {
   $result .= "   <li>".$vs."</li>\r\n";
   }
  $result .= "  </ul></li>\r\n";
  }
 $result .= " </ul></li>\r\n";
 }
$result .= "</ul>\r\n";
 
echo $result;

It worked on my comp.

johny_d 23 Junior Poster in Training

You're welcome! :)

johny_d 23 Junior Poster in Training

You can find it in the php manual if you do a little search :)
Here is that code adjusted to what you need:

<?php
 
/// here is your database connection
 
/// than the query
$result = mysql_query ("select field_1, field_2, field_3 from table") or die (mysql_error());
 
$filename = $_SERVER['DOCUMENT_ROOT'].'/test.xls'; //// or whatever.txt
 
if (!$handle = fopen($filename, 'a')) { 
        print "Cannot open file ($filename)"; 
        exit; 
   } 
// Let's make sure the file exists and is writable first. 
if (is_writable($filename)) { 
 
while ($row = mysql_fetch_row($result)) {
 $row_content = implode ("\t",$row)."\r\n";
   // Write $row_content to our opened file. 
   if (!fwrite($handle, $row_content)) { 
       print "Cannot write to file ($filename)"; 
       exit; 
   } 
   }
 
   print "Success, content wrote to file ($filename)"; 
 
   fclose($handle); 
 
} else { 
   print "The file $filename is not writable"; 
} 
 
?>

Try to do the basics first (like reading the manual) ;)