vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Help with writing an array to a .html using fwrite (https://vborg.vbsupport.ru/showthread.php?t=199776)

Jinovich 12-25-2008 05:11 PM

Help with writing an array to a .html using fwrite
 
I have no trouble writing to a file my problem is I can not think of a way to print the array into a variable so I can write it to the file. I can only seem to write one row. Because obviously the variable gets rewrtten in the while loop.

Can someone help me with this I have been struggling with it for sometime.

PHP Code:

<?php
include("../config.php");
$get mysql_query("SELECT * FROM users ORDER BY username ASC"); 
while(
$slot mysql_fetch_array($get))
{
$content "".$slot[username]." - ".$slot[slots]."<br>";
}
$filename 'test.html';


// Let's make sure the file exists and is writable first.
//if (is_writable($filename)) {

// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle fopen($filename'w')) {
echo 
"Cannot open file ($filename)";
exit;
}

// Write $somecontent to our opened file.
if (fwrite($handle$content) === FALSE) {
echo 
"Cannot write to file ($filename)";
exit;
}

echo 
"Success, wrote ($content) to file ($filename)";

fclose($handle);

//} else {
//echo "The file $filename is not writable";
//}
?>

Oh and merry christmas :)

Dismounted 12-26-2008 04:51 AM

Find:
PHP Code:

$content "".$slot[username]." - ".$slot[slots]."<br>"

Replace With:
PHP Code:

$content .= "".$slot[username]." - ".$slot[slots]."<br>"

It's called concatenation, by the way (and it's a lot to say!).

Jinovich 12-26-2008 01:10 PM

Quote:

Originally Posted by Dismounted (Post 1693786)
Find:
PHP Code:

$content "".$slot[username]." - ".$slot[slots]."<br>"

Replace With:
PHP Code:

$content .= "".$slot[username]." - ".$slot[slots]."<br>"

It's called concatenation, by the way (and it's a lot to say!).

Cheers! That worked like a charm.


All times are GMT. The time now is 01:12 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01520 seconds
  • Memory Usage 1,733KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete