I started learning learning PHP a couple of days ago and have started to make an SQL Database management webpage using AJAX. I am having a problem with errors if I restrict the search to less than all [*] the column's.
Because of this I thought it would be relatively easy to use regular expression on the string sent through AJAX and dynamically write the required table back to the webpage.
I am having issues understanding how to do a loop based on the returned array from preg_split(), append to a new string and then echo the new string out as a new table that I can write the sql table to.
this is the bit I can't figure out
$newString = 'this and ';
for ($i=0; $i < $arrayLength; $i++) {
$newString += $repArray[$i];
}
echo $newString;
the regular expression in the code simply gets the text between the 'SELECT' and 'FROM' statements, deletes the whitespace and splits the words into an array. and there are various echo's to show what is happening.
Thanks for any help
Regards,
Andrew
here is my full php code for testing the idea
<?php
$string = 'SELECT ID, username, password, firstName, IP FROM users WHERE ID > 100';
$pattern = '/SELECT (.*) FROM (.*)/i';
$replacement = '$1';
$replaced = preg_replace($pattern, $replacement, $string);
echo '<br> ' . $replaced;
$replaced2 = preg_replace('/\s/' , '', $replaced);
echo '<br> ' . $replaced2;
$repArray = preg_split('/,/', $replaced2, -1, PREG_SPLIT_NO_EMPTY);
echo '<br> ';
print_r($repArray);
$arrayLength = count($repArray);
echo '<br> Array length = ' . $arrayLength;
$newString = 'this and ';
for ($i=0; $i < $arrayLength; $i++) {
$newString += $repArray[$i];
}
echo $newString;
?>