Jump to content

some kind of array maybe, i dont know, very simple.


Shaun

Recommended Posts

Hi all, been a while eye?  :-[

I need a little help with something...

this is just a little snippit that pulls the urls and a description from my db and suposedly writes the results to a html file... well as you can imagine, im doing something wrong here and its really anoying me.

I think i need to chuck the info into an array or something.. but i dont know, its baffeled me. probly very simple to fix.

any help would be greatly appreciated.

thank you, Shaun

[code]<?PHP
include('includes/config.inc.php');
$query  = "SELECT url, description FROM blah";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    $in =  "<a href={$row['url']}>{$row['description']}</a><br>";
}
$fp = fopen("out.html","w") or die("Can't update links!");
fwrite($fp, $in);
fclose($fp);

?>[/code]
thanks for that, i think we are getting somewhere with this now..

just that the following causes a giant loop..
[code]<?PHP
include('includes/config.inc.php');
$query  = "SELECT url, description FROM blah";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    $in[$count] =  "<a href={$row['url']}>{$row['description']}</a><br>";
    $count++;
}

for($count=0;$count<($in);$count++)
{
$fp = fopen("out.html","w") or die("Can't update links!");
fwrite($fp, $in[$count]);
fclose($fp);
}

?>[/code]
maybe if there was a way to sort this lot of information out into an array or something then maybe it could then be written to the html file..

if i use echo "<a href={$row['url']}>{$row['description']}</a><br>"; all the links show up fine,

but obviously only one link with is description gets written to the html file... for some strange reason.

thanks everyone.
$fp = fopen("out.html","w") or die("Can't update links!");

I am not sure but I think you have to put this outside the for loop.
otherwise you open your file everytime and I guess you overwrite it (not sure about this I never did writing to files in php)
I think you have to open the file with append instead of write (that is how it is in asp)
maybe like this
$fp = fopen("out.html","a") or die("Can't update links!");
a instead of w

Please let me know if and how you solved this as I will have to get into writing to files soon.

anatak

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.