Jump to content

Write a large amount of data to a text file


kiwis-are-cool
Go to solution Solved by PravinS,

Recommended Posts

I'm trying to create a text file from a foreach loop (code below) but i'm not sure how. So far I have tried to use fwrite but I'm not to sure how to write that much data to a txt file. I also tried to use file_put_content(), it worked but it displayed all of the HTML and had no line breaks. Any ideas on how to do display it?


Foreach loop



echo "<p>" . 'custom_weapons_v3' . "</p>";
echo "<p>" . '{' . "</p>";


foreach($arr as $key => $a){
echo "<br>";
$check = $a['steamid'];
echo $check;

echo "<br>";
echo "{";
echo "<br>";
foreach($data as $key => $r){
$check2 = $r['steam'];
if($check == $check2){

echo " \"{$r['wepid']}\" //{$r['wepname']}<br />";
echo '{' . "<br />";
echo '"level"' . ' "' . $r['weplvl'] . '"' . "<br />";
echo '"quality"' . ' ' . '"' . $r['weprare'] . '"' . "<br />";

if($r['attr1'] === 0 || $r['attr1'] === ''){
echo '';
}else{
echo '"1"' . ' "' . $r['attr1'] . ' ; ' . $r['val1'] . '"' . "<br />";
}

if($r['attr2'] === 0 || $r['attr2'] === ''){
echo '';
}else{
echo '"2"' . ' "' . $r['attr2'] . ' ; ' . $r['val2'] . '"' . "<br />";
}

if($r['attr3'] === 0 || $r['attr3'] === ''){
echo '';
}else{
echo '"3"' . ' "' . $r['attr3'] . ' ; ' . $r['val4'] . '"' . "<br />";
}

if($r['attr4'] === 0 || $r['attr4'] === ''){
echo '';
}else{
echo '"4"' . ' "' . $r['attr4'] . ' ; ' . $r['val4'] . '"' . "<br />";
}

if($r['attr5'] === 0 || $r['attr5'] === ''){
echo '';
}else{
echo '"5"' . ' "' . $r['attr5'] . ' ; ' . $r['val5'] . '"' . "<br />";
}

if($r['attr6'] === 0 || $r['attr6'] === ''){
echo '';
}else{
echo '"6"' . ' "' . $r['attr6'] . ' ; ' . $r['val6'] . '"' . "<br />";
}

if($r['attr7'] === 0 || $r['attr7'] === ''){
echo '';
}else{
echo '"7"' . ' "' . $r['attr7'] . ' ; ' . $r['val7'] . '"' . "<br />";
}

if($r['attr8'] === 0 || $r['attr8'] === ''){
echo '';
}else{
echo '"8"' . ' "' . $r['attr8'] . ' ; ' . $r['val8'] . '"' . "<br />";
}

if($r['attr9'] === 0 || $r['attr9'] === ''){
echo '';
}else{
echo '"9"' . ' "' . $r['attr9'] . ' ; ' . $r['val9'] . '"' . "<br />";
}

if($r['attr10'] === 0 || $r['attr10'] === ''){
echo '';
}else{
echo '"10"' . ' "' . $r['attr10'] . ' ; ' . $r['val10'] . '"' . "<br />";
}

if($r['attr11'] === 0 || $r['attr11'] === ''){
echo '';
}else{
echo '"11"' . ' "' . $r['attr11'] . ' ; ' . $r['val11'] . '"' . "<br />";
}

if($r['attr12'] === 0 || $r['attr12'] === ''){
echo '';
}else{
echo '"12"' . ' "' . $r['attr12'] . ' ; ' . $r['val12'] . '"' . "<br />";
}

if($r['attr13'] === 0 || $r['attr13'] === ''){
echo '';
}else{
echo '"13"' . ' "' . $r['attr13'] . ' ; ' . $r['val13'] . '"' . "<br />";
}

if($r['attr14'] === 0 || $r['attr14'] === ''){
echo '';
}else{
echo '"14"' . ' "' . $r['attr14'] . ' ; ' . $r['val14'] . '"' . "<br />";
}

if($r['attr15'] === 0 || $r['attr15'] === ''){
echo '';
}else{
echo '"15"' . ' "' . $r['attr15'] . ' ; ' . $r['val15'] . '"' . "<br />";
}

if($r['attr16'] === 0 || $r['attr16'] === ''){
echo '';
}else{
echo '"16"' . ' "' . $r['attr16'] . ' ; ' . $r['val16'] . '"' . "<br />";
}
echo "}";
echo "<br>";

}
}
echo "}";
echo "<br>";
}

echo "<p>" . '}' . "</p>"; 

What i'm trying to display the text as



custom_weapons_v3

{


STEAM_0:0:1621342
{
"0" //Bat
{
"level" "0"
"quality" "0"
"1" "23 ; 21"
"2" "231 ; 231"
"3" "231 ; 0"
}
"159" //Dalokohs Bar
{
"level" "4"
"quality" "2"
"1" "22 ; 32"
"2" "12 ; 42"
}
}

}

Link to comment
Share on other sites


query = "SELECT * FROM weapons ORDER BY steamid";
if ($stmt = $mysqli->prepare($query)) {
$stmt->execute();
$stmt->bind_result($id, $steamid, $wepid, $weplvl, $weprare, $attr1, $attr2, $attr3, $attr4, $attr5, $attr6, $attr7, $attr8, $attr9, $attr10, $attr11, $attr12, $attr13, $attr14, $attr15, $attr16, $val1, $val2, $val3, $val4, $val5, $val6, $val7, $val8, $val9, $val10, $val11, $val12, $val13, $val14, $val15, $val16);

while ($row = $stmt->fetch()) {

$wep = $wepid;
$wep = wepname($wep);

$steamids[] = array(
'steamid' => $steamid
);

$data[] = array(
'steam' => $steamid,
'wepid' => $wepid,
'weplvl' => $weplvl,
'wepname' => $wep,
'weprare' => $weprare,
'attr1' => $attr1,
'attr2' => $attr2,
'attr3' => $attr3,
'attr4' => $attr4,
'attr5' => $attr5,
'attr6' => $attr6,
'attr7' => $attr7,
'attr8' => $attr8,
'attr9' => $attr9,
'attr10' => $attr10,
'attr11' => $attr11,
'attr12' => $attr12,
'attr13' => $attr13,
'attr14' => $attr14,
'attr15' => $attr15,
'attr16' => $attr16,
'val1' => $val1,
'val2' => $val2,
'val3' => $val3,
'val4' => $val4,
'val5' => $val5,
'val6' => $val6,
'val7' => $val7,
'val8' => $val8,
'val9' => $val9,
'val10' => $val10,
'val11' => $val11,
'val12' => $val12,
'val13' => $val13,
'val14' => $val14,
'val15' => $val15,
'val16' => $val16,
);






}
$stmt->close();
}

Link to comment
Share on other sites

How do you input php? Would it just be <?php echo "<p>" . 'custom_weapons_v3' . "</p>"; ?>

 

sorry not the SQL query, but what you try to say

 

also <p> tag will also not work in text file and what is "custom_weapons_v3", if it is a PHP variable then use $custom_weapons_v3

Link to comment
Share on other sites

I chose the wrong example. This would be what I need to post, the full foreach loop is in my first post. 

foreach($data as $key => $r){
  	  	$check2 = $r['steam'];
  	  	if($check == $check2){

  	  		echo " \"{$r['wepid']}\" //{$r['wepname']}<br />";
  	  		echo '{' . "<br />";
        			echo '"level"' . '      "' . $r['weplvl'] . '"' . "<br />";
        			echo '"quality"'  . ' ' . '"' .  $r['weprare'] . '"' . "<br />";

        		if($r['attr1'] === 0 || $r['attr1'] === ''){
        			echo '';
        		}else{
        			echo '"1"' . '      "' . $r['attr1'] . ' ; ' . $r['val1'] . '"' . "<br />";
        		}

Link to comment
Share on other sites

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.