Jump to content

Outputting an array into a textarea field


Go to solution Solved by Barand,

Recommended Posts

Hello, this is my first post here.

 

I am trying to output the rows of a certain query in sequence after a POST has been requested.

 

I have been successful in getting the output in a pure php file but when I try to implement this in a web page with html/css, I can't echo the array in arbitrary locations after the post has processed.

 

This is the code which outputs successfully in a pure php file, but I need it to work in a <textarea> field as the results of a search

$rows2 = array();
$rows3 = array();
while($stmt->fetch()){
$rows2[] = $stratoparse;
$rows3[] = $date;
}
 $search = array();
for($i=0;$i<=$num_rows;$i++){
echo $rows3[$i].' '.$rows2[$i].'<br>'.'<br>';
}
}

To further iterate what I am asking. When errors are stored, you write something like

$errors['username']="A username is required.";

Then in any location of a webpage I can call this or show it, provided by this

<?php isset($errors['username']) ? $errors['username']:" ");?>

That is the same thing I am trying to do with this array which can be an arbitrary count of rows...

 

I have not been successful in getting this to work... I have been told of string concatenation...

 

I don't know what to do

 

 

 

Thank you for any help

 

 

None of your code samples make sense, nor your supposed working code.

 

Whatever do you mean by "I have been successful in getting the output in a pure php file"? What is a pure php file? A file that has nothing but php code in it and no html? And how do you know this thing works?

I know it works because it outputs, here is a basic file and yes "pure" as in no front end, it's just a script executing.

 

I will enter these three strings with the keyword php, "Test 1", "Test 2", "Test 3". Then, ideally if the code works, (what I need help with now) I would enter php in the keyphrase field, and hit search, then in the search results field, all of the rows with php as a keyphrase would be displayed.

 

This is the interface I used to enter that data

 

this is a photo, not a website / ads

 

http://parsemebro.com/interface.png

 

Search does not work... that's why I am here

however I will provide the userrname / keyphrase directly rather than getting it from a POST <- problem?

 

So, when I enter this link into a browser

 

http://parsemebro.com/tent.php

 

This is the output

 

01-07-2015 Test 3

01-07-2015 Test 2

01-07-2015 Test 1

 

This, is exactly what I want to happen on this page, in the text field  with the placeholder "paste here or view search results"

 

http://parsemebro.com/interface.png

 

The buttons are not different, so technically you can push pmb to search, I haven't learned that yet, I just built some control statements based on what is entered eg. what is empty, what is not, to take in the single control (POST) which might as well be one button.

 

Here is the code for the tent.php file

 

Notice the function, I was going to try and include the file then call this as a function like password_hash() which I have to use a library extension eg. include

<?php
session_start();


function list_result(){

$userrname = "moose";
$keyphrase = "php";

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
 
}

$servername = " ";
$username = " ";
$password = " ";
$dbname = " ";

$link = new mysqli("$servername", "$username", "$password", "$dbname");
$stmt=$link->prepare('SELECT stratoparse,date FROM stock WHERE user=? AND keyphrase=? ORDER BY ID DESC');
$stmt->bind_param('ss',$userrname,$keyphrase);
$stmt->execute();
$stmt->store_result();
$num_rows = $stmt->num_rows;
$stratoparse=null;
$date=null;
$stmt->bind_result($stratoparse,$date);

$rows2 = array();
$rows3 = array();
while($stmt->fetch()){
$rows2[] = $stratoparse;
$rows3[] = $date;
}
 $search = array();
for($i=0;$i<=$num_rows;$i++){
echo $rows3[$i].' '.$rows2[$i].'<br>'.'<br>';
}
}

echo list_result();
?>
  • Solution

Use "\n" and not "<br>" in textareas.

<?php
$txt = '';
while($stmt->fetch()){
    $txt .= $date . " " . $stratoparse . "\n\n";
}
?>

<textarea cols="50" rows="10">
    <?php echo $txt; ?>
</textarea>

 

Use "\n" and not "<br>" in textareas.

<?php
$txt = '';
while($stmt->fetch()){
    $txt .= $date . " " . $stratoparse . "\n\n";
}
?>

<textarea cols="50" rows="10">
    <?php echo $txt; ?>
</textarea>

 

Wow, thank you so much. It finally works. The problem as it turns out is the keyphrase parameter, I requested to search "all" so the keyphrase was set or expected to be "all" not anything else. <- this means that I'm just returning every entry by a user and so keyphrase is not needed aside from determining that the input was "all" as defined in the control statements.

 

Anyway thank you very much this simple output helps me a lot.

Edited by moose-en-a-gant
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.