adam.adamski.96155 43 Junior Poster

I found an answer using the GROUP BY clause:
SELECT * FROM goethe_search GROUP BY (SUBSTRING(msg_text FROM 10 FOR 75));
Easy when you know how :D

adam.adamski.96155 43 Junior Poster

Hello :D
I am using the twitter API to perform a search for a certain author, and storing the results in a database so that I can perfrom an action on each entry. However, there are many duplicate results that have small differences at the beginning of the string or at the end that I do not want to respond to. I have managed to select all the distinct entries based on a substring:
SELECT DISTINCT (SUBSTRING(msg_text FROM 10 FOR 75)) AS res FROM goethe_search;
...which gives me the dinstinct substrings but not the other fields that corelate to the distinct results. I tried this:
SELECT * FROM (SELECT DISTINCT (SUBSTRING(msg_text FROM 10 FOR 75)) FROM goethe_search) AS res;,
and this:
SELECT DISTINCT (SUBSTRING(msg_text FROM 10 FOR 75)) AS res, id FROM goethe_search GROUP BY id;,
but they both give me all the results and I lose the distinct aspect. Can anyone point me in the right direction?
Thanks in advance :D

adam.adamski.96155 43 Junior Poster

It's perfect!
Thank you Pritaeious, as usual, a fast and concise solution :D

adam.adamski.96155 43 Junior Poster

For a moment I thought I was being REALLY stupid :D
Goedendag Pritaeious, but that only returns 1000 results even if there are 25000 matches. I want to make an initial query that will tell me the exact amount of matches and no data, and then a second query collecting the data with a limit of 1000, or one that does both if it is possible.
Thanks for your speedy consideration :D

adam.adamski.96155 43 Junior Poster

Hello :)
I'm working with a database of postcodes. I have an existsing query that returns the postcodes within a certain radius:

select *, acos(cos(51.496502411798 * (PI()/180)) *cos(-0.13982862499836 * (PI()/180)) *cos(lat * (PI()/180)) *cos(lng * (PI()/180))+cos(51.496502411798 * (PI()/180)) *sin(-0.13982862499836 * (PI()/180)) *cos(lat * (PI()/180)) *sin(lng * (PI()/180))+sin(51.496502411798 * (PI()/180)) *sin(lat * (PI()/180))) * 3959 as Dist from SW having Dist < 1 order by Dist

Dist 1 is the number of miles for the search radius.

I am making a script that will allow the user to enter a postcode and return a list of postcodes in the given radius. There can be over 20,000 results of which only 1000 will be displayed. Currently, I get all results into a PHP array and use the count() function to return the total, and just display upto 1000.
I would like to make the query produce only a count of relevant matches, and then make a follow up query with a limit of 1000 which will stop the unneccesary collection of data over 1000 rows.

Thanks for your time :D

adam.adamski.96155 43 Junior Poster

Ah I see, line 20, change:
$values = $max; to $values = $row;.
Also, I think line 27 will give a problem:
$this->inputBookingRef($values, true), because the
inputBookingRef() function takes only one parameter,
as it is in the commented out line 28:
$this->inputBookingRef($max)
Hope this helps, happy coding :D

adam.adamski.96155 43 Junior Poster

if(isset($_POST['id']) && ($row['bankID'] == $_POST['id']))
or,
if(isset($row['bankID']) && ($row['bankID'] == $_POST['id']))
depending which key is not set.

It's good that you have all errors showing.

adam.adamski.96155 43 Junior Poster

Yep, that's works :D
I've used this for years but always hated it because I didn't understand it. Now I guess that although the original function returns false, there is nowhere calling for a return value as there would be if you wrote:
$bool = doFunction(this); if ($bool){...
so by writing:
return doFunction()
The 'return false' returned from the function has some where to return to?

adam.adamski.96155 43 Junior Poster

I tested without return false; initially. The alert alerted and the colours coloured, and when I clicked 'OK', the form went a head and submitted anyway, in FF, Chrome and IE. Yet when I added return false;, it stopped the form submitting, also in all three browsers. There is probably a proper way of acheiving this, and I would like to know what it is :D

adam.adamski.96155 43 Junior Poster

I once put all the UK postcode blocks with their accompanying longitudes/latitudes and northings/westings into a MySQL database, I dont remember exactly how many records, but I think it was more than 20,000. I set up a script that would insert 10 to each query, and 100 queries, and the page would then reload and go on with the next 100X10 block. The whole thing took over 15 mins to complete, but it was all there at the end of it.
Would you really need to recreate the whole database everytime? Could you not only take the new entries to the CSV file since your last update? Maybe check DB for last entry, search CSV for that entry, and grab all previous lines and insert them to DB? How many entries are likely to have backlogged between each user visit? Could the user visit itself not trigger the update process? How often is the CSV file written to? Is data being overwritten or appended?
I love challenges like this, ones you can get your teeth into, rather than making a few bits of text dance :D

adam.adamski.96155 43 Junior Poster

I see the problem:
function validateForm(Qform) expects a parameter passed with the function call, but you pass nothing:
onSubmit="validateForm();
change it to:
onSubmit="validateForm(this); return false;"
and it should work okay.

adam.adamski.96155 43 Junior Poster

I mentioned two errors, did you fix them both?

What do you want to happen if the email address already exists?

adam.adamski.96155 43 Junior Poster

Okay, I'm lost now :)
Can you repost your updated code and as clearly and simply as possible tell me what exactly what you want to achieve.
You are collecting data in one place and hoping to show it in another place, you need to check each place where the data is transferred. It's like a relay race, we need to look at each changeover and see who is dropping the baton.

adam.adamski.96155 43 Junior Poster

This hurts me more than it hurts you, but...
Let me google that for you!

phorce commented: Brilliant! +6
adam.adamski.96155 43 Junior Poster

Line 32: $sql="INSERT INTO tbl_candidate(email_id) VALUES('$email_id1'); has a missing quote before the semi-colon.
Line 39: else{ is missing the preceding curly brace.
Fix those, see what happens.

adam.adamski.96155 43 Junior Poster

Your database section looks a little mamlformed, specifically this line:
while ($query !=-1 && $row = mysql_fetch_assoc($query)) {
I would guess that the previous line:
$values = mysql_fetch_assoc($query);
already collected the necessary information, so if this line:
echo print_r($values, true);
prints the correct information, I would try changing your code at line 12(ish) to:

if(!$res = mysql_query("SELECT MAX(ballpark_details_booking_ref) as max_booking_ref FROM `ballpark_details`")){//error check the db interaction.
    die(mysql_error());
} else {//we are selecting 'MAX', there will only be one row
    $row = mysql_fetch_assoc($res);//no need for a while loop to collect one line.
    $max = $row['max_booking_ref'];
}

...does it work as intended?

adam.adamski.96155 43 Junior Poster

Welcome to Daniweb albertsibanda9 :)
The long answer:
Read This Before Posting A second Question
The short answer:
Post your code before LastMitch gets hold of you :D

diafol commented: Hilarious +14
LastMitch commented: LOL - that's a good one Adam! =) +6
<M/> commented: well said... +5
adam.adamski.96155 43 Junior Poster

but i want to show the error in such a way that name of the tables couldn't be shown...

Is that all?

$query = mysql_query("DELETE FROM table_2 WHERE tchr_id='".$id."'") or die("Oops, we have a problem, please contact the administrator.");

Change message to suit.

adam.adamski.96155 43 Junior Poster

@diafol Haha! Looking at your funny man links, I guess it could be 'David Hill' with a Welsh accent. I had not heard of Vanilla JS and was impressed with the performance stats, but as you mentioned, cross browser compatibility is a real pain with Javascript and jQuery separates the developer from this concern. Also, the jQuery UI looks like it will speed development of User Interfaces like the one I need to administer my quotes database.

adam.adamski.96155 43 Junior Poster

@diafol Ahhhh, so it is JSON format, that's a tidy solution.

adam.adamski.96155 43 Junior Poster

check for result

    if($result = mysql_query("SELECT * FROM table")){
        while ($row = mysql_fetch_array($result)){
            // don't echo immediately, store in $string
            $string .= '["' .$row[1]. '",' .$row[2].'],';
        }
    // now $string has an extra comma...
    $string = substr($string, 0, -1);
    }    

use substr() to select all but last character, then echo the whole thing.

adam.adamski.96155 43 Junior Poster

@dafodil It's high time I learnt jQuery!
I sussed the issue was not the duplicate name, but rather the use of:
div.innerHTML += "<textarea name='new_quote[]' />";
as when it grabbed the existing html it was collecting the textarea but not the user-added input. This was solved by adding a new textarea to the DOM rather than the above method, and I googled some jQuery assistance:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript">
        $(function(){
            $("#button_add_input").click(function(event){
                var textArea = "<textarea name='new_quote[]' />";
                $("#div_quotes").append(textArea);
                $("#div_quotes").append("\n<br />");
            });
        });

And the button to add a text area needed an id: <input type="button" value="Add Text Area" id="button_add_input">
I looked for a way to add the textarea without specifying the html as in something like $("#div_quotes").append(html.textarea), but could not find how to reference a textarea directly, so just added the HTML instead.

adam.adamski.96155 43 Junior Poster

I have the same requirement so I wrote a few lines that would demonstrate the answer to your question and give me a base to work from.

<?php
if (isset($_POST['submitted'])){
    print_r($_POST);
}
?>
<html>
<head>
    <script type="text/javascript">
        function addTextArea(){
            var div = document.getElementById('div_quotes');
            div.innerHTML += "<textarea name='new_quote[]' />";
            div.innerHTML += "\n<br />";
        }
    </script>
</head>
<body>
<form method="post">
<input type="text" name="text_new_author" /><br />
<div id="div_quotes"></div>
<input type="button" value="Add Text Area" onClick="addTextArea();">
<input type="submit" name="submitted">
</form>
</body>
</html>

I thought I would need to keep a total of how many text areas had been added to allow them to have an individual name; area_1, area_2, area_3 etc. However adding [] to the textarea name and using the same name creates an array of values, so no values are lost and a unique name is not needed, print_r($_POST) produces:
Array ( [text_new_author] => New Author [new_quote] => Array ( [0] => New quote 1 [1] => New quote 2 [2] => New quote 3 ) [submitted] => Submit Query )
But this solution causes another problem; if the user adds a new quote and then clicks the 'add text area' button the text entered into the first textarea disappears. I presume this is because a new textarea with the same name is added to the DOM, so maybe I will need a unique name for each added textarea after all :)

adam.adamski.96155 43 Junior Poster

$alert_error = "<script type=\"text/javascript\"> alert('".mysql_error()."') </script>";
In the above line you are referencing 'mysql_error()', but it doesn't exist yet because you did not run the query that produces the error.
Also, you wanted Javascript to alert the value of 'mysql_error()':

if (!$query = mysql_query("DELETE FROM abc WHERE id ='$id'")){
    echo "<script type=\"text/javascript\"> alert('".mysql_error()."') </script>";
    }

The above works when I test it.

adam.adamski.96155 43 Junior Poster

Hey GraficRegret, welcome to Daniweb :)
Your description sounds like a typical use of PHP and MySql, but what help do you specifically need? Is there some code you need some assistance with? Are you looking for general considerations and tips from those who already walked that road?

adam.adamski.96155 43 Junior Poster

There are probably better ways, but If I had to achieve it with existing knowledge, I would do something like this:

$wordString = $_POST['search'];
/* first test there are comma separated values */
if (strpos($wordString, ",")){
    /* split string into array of strings on the comma */
    $words = explode(",", $wordString);
    /* start the sql */
    $sql = "SELECT * FROM table WHERE";
    /* for each word update the query */
    foreach($words as $word){
        $sql.=" field LIKE '%$word%' OR";
    }
    /* remove trailing 'OR' from query */
    $sql = substr($sql, 0, -3);
} else {
    /* NO comma separated values, build normal query */
    $sql = "SELECT * FROM table WHERE filed LIKE '%$wordString%'";
}

If the user enters 'one,two,three', the resulting query would be:
"SELECT * FROM table WHERE field LIKE '%one%' OR field LIKE '%two%' OR field LIKE '%three%'", otherwise a normal query is constructed.

adam.adamski.96155 43 Junior Poster

There are probably better ways, but I would make a temporary database with mysql and store them in there for easier manipulation. I would write a script to insert a few hundred at a time, and add the records gradually to avoid PHP execution limit, with an echo for every insert to show me that it is still running.
Then I would run the query:
"SELECT * FROM table ORDER BY column ASC, limit 10"

adam.adamski.96155 43 Junior Poster

Hey that's plenty info.
The line needs to be in the while loop (it will change every time), so put it under the line:

while($row = mysql_fetch_array($result)){
    $total = ( $row['field3'] - ($row['field1'] / $row['field2']) );
    //then in the place you want the total to show:
    echo "<td>".$total."</td>";

This presumes your column names really are 'field1', 'field2' and 'field3', if not adjust accordingly. Diafol's idea was good too, well worth investigating, but you would need to show your existing query for instruction on that front.

adam.adamski.96155 43 Junior Poster

Probably can help, but need to see the rest of your code to understand why there is an error.

adam.adamski.96155 43 Junior Poster

This is simple maths, use parentheses to force calculations in correct order:
field3 minus (field1 divided by field2)

$result = ( $row['field3'] - ($row['field1'] / $row['field2']) );
echo "<td>".$result."</td>";
adam.adamski.96155 43 Junior Poster

@kevinp2012 seriously, are you asking the OP to improve his English?
@dodgers125 I'm not sure what you want but maybe I can give some pointers about your code:

<!-- header row, the 1 must be in quotes: border="1"-->
<table border="1">
<tr><th>Sale Number</th>
<th>Item</th>
<th>Item Cost</th>
<th>Units Sold</th>
<th>Sale Cost</th>
</tr>
<?php
/* Initialise the $totalsArray where we will store the total sales amount for each item */
$totalsArray = array('sofa'=>0, 'table'=>0, 'chair'=>0, 'box'=>0, 'tablecloth'=>0);
for ($x=0; $x<=20; $x++){
    $amount = rand(1,10);
    $res = rand(1, 5);
    /* The following line makes the later condition "if ($object==0)" always true.
    Seems a bit pointless to me, but maybe it's only for testing? */
    $object = 0;
    /* $cost doesn't exist in the script yet, so this next line must come under the switch */
    //$total = $amount * $cost;
    /* I prefer a switch than elseif's for this job */
    switch($res){
        case 1:
        $cost = 235.00;
        $item = "sofa";
        $totalsArray['sofa'] += ($cost*$amount);
        break;
        /////
        case 2:
        $cost = 125.00;
        $item = "table";
        $totalsArray['table'] += ($cost*$amount);
        break;
        /////
        case 3: 
        $cost = 25.99;
        $item = "chair";
        $totalsArray['chair'] += ($cost*$amount);
        break;
        /////
        case 4:
        $cost = 15.25;
        $item = "box";
        $totalsArray['box'] += ($cost*$amount);
        break;
        /////
        case 5:
        $cost = 23.50;
        $item = "tablecloth";
        $totalsArray['tablecloth'] += ($cost*$amount);
        break;
    }//switch
    //set the total now that $cost is defined...
    $total = $amount * $cost;
    //write the table and store vars in $table array
    echo "<tr>";
    echo "<td>" . $table[$x][0] = $x+1 . "</td>\n";
    echo "<td>" . $table[$x][1] …
adam.adamski.96155 43 Junior Poster

It does look better when the stylesheet changes immediately, but the choice will be lost when the page is reloaded, unless the choice is saved somehow.
You seem to be storing the choice in a database, but a database call for every page load solely to determine the theme is a bit excessive I feel.
The better way is to save the users choice in a session cookie as Cereal has demonstrated.
The only issue I had with this is the browser caching the stylesheet and using an 'old' choice to style the page, but this may have just been with Jquery Mobile.

adam.adamski.96155 43 Junior Poster

I only noticed afterwards that the title said 'using PHP':

<?php
//check to see if the form was submitted
if(isset($_POST['submit'])){
    $theme = $_POST['theme'];//set to selected theme
} else { 
    $theme = "default.css";//set to default
}
?>
<html>
<head>
<!-- use PHP to echo the location of the stylesheet -->
<link id="stylesheet" rel="stylesheet" type="text/css" href="<?php echo $theme; ?>" />


<!-- The action of the form will default to self -->
<form method="post">
<select name ="theme">
<option value="default.css">Default</option>
<!-- The PHP code in next part would be better in a separate function -->
<!-- It sets the dropdown to selected on the currently selected theme -->
<option value="dark.css"<?php if ($theme == "dark.css") echo " selected"; ?>>Dark</option>
</select>
<input type="submit" name="submit" />

Learn, don't just copy :)

adam.adamski.96155 43 Junior Poster

Using javascript:

<head>
<!-- You must have the id set in the next line -->
<link id="stylesheet" rel="stylesheet" type="text/css" href="default.css" />
<script type="text/javascript">
function switchStyle(el){
    //get selected theme
    var styleSheet = el.options[el.selectedIndex].value;
    //apply the new style using id set earlier.
    document.getElementById('stylesheet').href = styleSheet;
}
</script>

<body>
<!-- (this) refers to the select element -->
<select id="theme" onchange="switchStyle(this)">
<!-- value corresponds to stylesheet filename --> 
<option value="default.css">Default</option>
<option value="dark.css">Dark</option>
adam.adamski.96155 43 Junior Poster

I believe we have two insert types with MySQL:
"INSERT INTO tablename set field='value', column='amount'...", and
"INSERT INTO tablename (field, column) VALUES ('value', 'amount')"
But your query is a mixture of both and neither:
"INSERT INTO ".$table." values $fld='$this->add_security($val)'"

adam.adamski.96155 43 Junior Poster

$check= mysql_query("SELECT FROM accounts WHERE (email='".$email."')");
Select what from accounts? ALL, Id etc? I guess error checking the query would have given an error.

adam.adamski.96155 43 Junior Poster

I think you are confusing two file system types; localhost is for the browser address bar and relates to hostnames, but the script needs the system path. If 'install.php' is in the same directory, then you can try './install.php' (./ is shorthand for this directory). You need to give the relative system path from the file that uses the require() to the required file itself, or you can give an absolute path: 'C:\xampp\htdocs\phpads\install.php'

adam.adamski.96155 43 Junior Poster

It may well be possible to get all the things you want in one query, using the Join technique, but that is for someone else to tell you, have a look here :D
As for looping through the way you mentioned:

<?php
$cityArray = new array();
$sql = "SELECT city from table where radius <20miles";
if(!$res = mysql_query($sql)){
    echo mysql_error(); die();
} else {
    while ($row = mysql_fetch_assoc($res)){
        $user_sql = "select users from table where city='".$row['city']."'";
        if(!$user_res = mysql_query($user_sql)){
            echo mysql_error(); die();
        } else {
            while($user_row = mysql_fetch_assoc($user_res)){
                $cityArray[$row['city']] = $user_row['users'];
            }
        }
    }
}
//Now you have an array called $cityArray, the key being the city, the value being an array of users in that city:
foreach ($cityArray as $city => $userArr){
    echo "The city of $city has count($userArr) users living there:\n<br />";
    foreach($userArr as $user){
        echo $user."\n<br />";
    }
}

We really should be moving onto PDO or mysqli now:
Using PHP/PDO with error checking
Using PHP/MySQLi with error checking

I haven't tested the above code, so it may have a typo or two, but I hope it helps you to understand. :D

adam.adamski.96155 43 Junior Poster

A standard array of checkboxes:

<input type="checkbox" id="unicycle" name="cycle[]" value="1">I have one wheel.
<input type="checkbox" id="bicycle" name="cycle[]" value="2">I have two wheels.
<input type="checkbox" id="tricycle" name="cycle[]" value="3">I have three wheels.

Now, echoed with PHP:

<?php 
//escaping the double quotes:
echo "<input type=\"checkbox\" id=\"unicycle\" name=\"cycle[]\" value=\"1\">I have one wheel.";
//using single quotes:
echo "<input type='checkbox' id='bicycle' name='cycle[]' value='2'>I have two wheels.";
?>

And finally, echoed with PHP including dynamic vars:

<?php
//escaping double quotes:
echo "<input type=\"checkbox\" id=\"unicycle\" name=\"cycle[]\" value=\"".$rows['id']."\">I have one wheel.";
//single quotes with concatenation:
echo "<input type='checkbox' id='bicycle' name='cycle[]' value='".$rows['id']."'>I have two wheels.<br />";
//for easy writing/reading:
$var_without_quotes = $rows['id'];
echo "<input type='checkbox' id='tricycle' name='cycle[]' value='$var_without_quotes'>I have three wheels.<br />";
?>

Does that answer your question?

adam.adamski.96155 43 Junior Poster

I will show you what I mean:

A standard select menu...

<select id="select" onchange="alertSelected(this)">
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
    <option value="4">Four</option>
    <option value="5">Five</option>
</select>

...will have the select declaration:
<select id="select">
...and will also have some options:

<option value="1">One</option>
<option value="2">Two</option>

Without the options we can't 'select' one and send that selection in the ajax request.
As an example, we will only alert the selected value using a JS function:

function alertSelected(el){
    var selected = el.options[el.selectedIndex].value; 
    alert(selected);
}

I am running this exact code in my browser and it is alerting the selected value when I choose an option. We need to do the same with your code, which means seeing the structure of the '<option>'s. The way to acheive this is to let the page load, then view the source of the page (standard procedure), then look through the source for the section where the options are set.
You can copy that code and paste it here (hopefully) :)

adam.adamski.96155 43 Junior Poster

If I could see how the options are formed, I could be certain how to proceed, but without seeing I can still make a guess.

change your select declaration to this:
<select name="users" onchange="showUser(this)"

...then add this line:
q_str = str.options[str.selectedIndex].value;
...above the line:
xmlhttp.open("GET","testtwopart1.php?q="+q_str,true);
notice that 'str' was changed to 'q_str' in the line above.

There is a special way of finding out which option was selected and your script wasn't configured to discover it. showUser(this) passes the element itself to the function (this element) and str.options[str.selectedIndex].value gets the value of the selected option. Theoretically, you could send the selected option straight to the function but it would get messy in those parenthesis:
showUser(this.options[this.selectedIndex].value)

If it doesn't work now, I need to see the structure of the select element, specifically the options... yes I know they are pulled from the src file, but they must still exist in the page when it is loaded or there could be no 'onchange' taking place. Right-click and view source to see them.
Good luck :)

adam.adamski.96155 43 Junior Poster

<option="1">1</option>
I need to see this part.
You can view source when the page has loaded and copy/paste here.

adam.adamski.96155 43 Junior Poster

Can you copy the structure of the select list from the source when the page has loaded and post a few lines here?

adam.adamski.96155 43 Junior Poster

Your script is not selecting the database before it tries to add the new user.
This line:
mysql_select_db($db);
...needs error checking (notice a pattern here?)
if(!mysql_select_db($db)) die(mysql_error());

adam.adamski.96155 43 Junior Poster

It's this line:
xmlhttp.open("GET","testtwopart1.php?q="+str,true);
str is undefined.
utrivedi suggested changing line 35:
<select name="users" onchange="showUser(this.value)"
I agree with him.

You could alert the value of str before you send the ajax request, to make sure it is formed properly.

adam.adamski.96155 43 Junior Poster

@ricardojorge
register.php line 35:
$r = mysql_query($q);
add some error checking:
if(!$r = mysql_query($q)) die(mysql_error());
do you get an error message?

@lastmitch I agree with you, but I fancied the challenge and was already looking :)

adam.adamski.96155 43 Junior Poster

@xbat, from what I can see, 'q' is not defined in your JS code, it is not even referenced, so it can't be JS that's giving the error. The only way I can understand this undefined error regarding 'q' is the processing page, testwopart1.php.
The beginning of the script (testwopart1.php), references $_GET['q'] and if this variable is not defined, you will get an error of type notice concerning an 'undefined key'. Veedeeo's suggestion to use a test: if(isset($_GET['q'])) is the way to avoid this error. If you want to test testwopart1.php, you can go directly to the page and add "?q=something" into the address bar (change the something to what you think should be sent) and see what the output is. If the output looks good, then I would put a line at the top of testwopart1.php: echo "some random words"; die(); and then alert the xmlhttp.responseText to the screen on return to the ajax function. From these two steps you can get a better idea of where the problem lies.
I find this type of problem standard issue whenever I have used Ajax. Good luck :)

adam.adamski.96155 43 Junior Poster

If I understand you correctly you want to echo more than one line of HTML each iteration of the foreach loop. You can either (a)make this happen within your existing loop, (b)repeat your existing loop and do something different in it, or (c)store the necessary variables in an array and run a second loop:

(a) A single loop that does all:

for($x = 0;$x <count($_FILES['image']['name']);$x++) {
$url = something;
echo "<center><td><input type=\"text\" size=\"50\"value=\"$url\"/></td></center>";
echo "<center><td><input type=\"text\" size=\"50\"value=\"$modify_url\"/></td></center>";
echo "<center><td><input type=\"text\" size=\"50\"value=\"$remodify_url\"/></td></center>";
}

(b) Two loops with same condition, but different output:

for($x = 0;$x <count($_FILES['image']['name']);$x++) {
$url = something;
echo "<center><td><input type=\"text\" size=\"50\"value=\"$url\"/></td></center>";
}
for($x = 0;$x <count($_FILES['image']['name']);$x++) {
$modify_url = something;
echo "<center><td><input type=\"text\" size=\"50\"value=\"$modify_url\"/></td></center>";
}

(c) One loop to output HTML and store vars for use in second loop:

$loopArray = new array();
for($x = 0;$x <count($_FILES['image']['name']);$x++) {
echo "<center><td><input type=\"text\" size=\"50\"value=\"$url\"/></td></center>";
// Store other vars in array for second loop
$loopArray[$x] = $modified_url //if only single var or:
// An array of arrays:
$loopArray[$x] = array($modified_url, $remodified_url, $re_modified_re_urled);
}

then the second loop:

foreach($loopArray as $v){
    //single vars in array?
    $single_variable = $v;

    //arrays in array?
    foreach($v as $arr){ //nested foreach
    $modified_url = $arr[0];
    $remodified_url = $arr[1]; 
    $re_modified_re_urled = $arr[2];
    }
}

Make sense?

adam.adamski.96155 43 Junior Poster

Either way you will be writing HTML with PHP in it, or PHP with HTML in it.
You have the option to open a for loop and then close the PHP block...
<?php for($i=0;$i<$count;$i++){?>
...now you would put standard HTML with PHP variables echoed:
<center><td><input type="text" size="50" value="<?php echo $url ?>"/></td><center>
and then open the PHP block to close the for loop:
<?php } // close brace ?>
which was your original method with a slightly different syntax. Or you can use PHP to produce the HTML and echo the variables:

<?php for($i=0;$i<$count;$i++){
    echo "<center><td><input type='text' size='50' value='$url' /></td><center>\n";
} ?>

If you are looking for further separation, you could put the HTML producing sections of your PHP code into a function that is separated from your main PHP code, or even in another file, but somewhere there will be a mixture.

adam.adamski.96155 43 Junior Poster

I split the echo line into three for readability, it does not have to be that way:
echo "<center><td><input type='text' size='50' value='$url' /></td><center>";
Your original loop had a strange syntax:
<?php for($x = 0;$x <count($_FILES['image']['name']);$x++) : ?>
<?php endfor; ?>
If I was writing the same loop it would look like the following:

<?php
for($x = 0;$x <count($_FILES['image']['name']);$x++){
    echo "<center><td><input type='text' size='50' value='$url' /></td><center>\n";
}
?>

You mention that your loop only produces one line, but what is the value of count($_FILES['image']['name'])?