Shaun Posted January 17, 2007 Share Posted January 17, 2007 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] Link to comment https://forums.phpfreaks.com/topic/34652-some-kind-of-array-maybe-i-dont-know-very-simple/ Share on other sites More sharing options...
fert Posted January 17, 2007 Share Posted January 17, 2007 [code]while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $in[$count] = "<a href={$row['url']}>{$row['description']}</a><br>"; $count++;}for($count=0;$count<num($in);$count++){fwrite($fp, $in[$count]);}[/code] Link to comment https://forums.phpfreaks.com/topic/34652-some-kind-of-array-maybe-i-dont-know-very-simple/#findComment-163285 Share on other sites More sharing options...
Shaun Posted January 18, 2007 Author Share Posted January 18, 2007 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] Link to comment https://forums.phpfreaks.com/topic/34652-some-kind-of-array-maybe-i-dont-know-very-simple/#findComment-163294 Share on other sites More sharing options...
Shaun Posted January 18, 2007 Author Share Posted January 18, 2007 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. Link to comment https://forums.phpfreaks.com/topic/34652-some-kind-of-array-maybe-i-dont-know-very-simple/#findComment-163304 Share on other sites More sharing options...
anatak Posted January 18, 2007 Share Posted January 18, 2007 $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 wPlease let me know if and how you solved this as I will have to get into writing to files soon.anatak Link to comment https://forums.phpfreaks.com/topic/34652-some-kind-of-array-maybe-i-dont-know-very-simple/#findComment-163463 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.