digitalgod Posted July 9, 2006 Share Posted July 9, 2006 Hey guys,I have an echo that displays form elements, 1 of them is a textarea and I need the value to be something that's fetched from my DBso this is what I did but it's now working, keeps giving me an error[code]<? for ($i=1;$i<=$num_news;$i++) { echo '<tr> <td width="151"><strong>Article #'.$i.'</strong></td> <td width="442"></td> </tr> <tr> <td>Upload Pic:</td> <td><input type="file" name="file' . $i . '"></td> </tr> <tr> <td>Content:</td> <td><textarea rows=10 cols=40 name="news_content' . $i . '" value="'. echo $row['content'];.'"></textarea></td> </tr> <tr> <td>Type:</td> <td><select name="type' . $i . '" id="type"> <option>Choose one</option> <option value="house">House</option> <option value="hip hop">Hip Hop</option> <option value="both">Both</option></br></br></td> </tr>'; }?>[/code]I tried it without the second echo and even though the script worked it didn't display anything. I tried using the echo $row['content'] alone and it worked perfectly so I know that's not the problem.Any ideas how can I display the textarea value? Quote Link to comment https://forums.phpfreaks.com/topic/14070-echo-inside-of-another-echo/ Share on other sites More sharing options...
Kurt Posted July 9, 2006 Share Posted July 9, 2006 Remove the second echo and remove the semi-colon after $row['content']. Quote Link to comment https://forums.phpfreaks.com/topic/14070-echo-inside-of-another-echo/#findComment-55008 Share on other sites More sharing options...
digitalgod Posted July 9, 2006 Author Share Posted July 9, 2006 I already tried that and it didn't work, that's why i tried the 2nd echo ;) Quote Link to comment https://forums.phpfreaks.com/topic/14070-echo-inside-of-another-echo/#findComment-55010 Share on other sites More sharing options...
Kurt Posted July 9, 2006 Share Posted July 9, 2006 [quote author=digitalgod link=topic=99923.msg393814#msg393814 date=1152409420]I already tried that and it didn't work, that's why i tried the 2nd echo ;)[/quote]You said you tried removing the second echo, but you never said you removed the semi-colon (;) after $row['content']. Do that, and I guarantee you it will work. Quote Link to comment https://forums.phpfreaks.com/topic/14070-echo-inside-of-another-echo/#findComment-55011 Share on other sites More sharing options...
digitalgod Posted July 9, 2006 Author Share Posted July 9, 2006 I just re-did that and got nothing :P*edit*here's the full code[code]<?php$num_news = $_SESSION['num_news'];$date = $_SESSION['news_date'];$result=mysql_query("SELECT * FROM news WHERE date='". $date ."'") or die(query_error());$row=mysql_fetch_array($result);echo $row['content'];?><div id="article"><form action="admin.php?a=newnews" enctype="multipart/form-data" method="post"><input type="hidden" name="process" value="yes" /><input type="hidden" name="process_b" value="yes" /><input type="hidden" name="size_limit" value="500" /><table width="500" border="0"> <? for ($i=1;$i<=$num_news;$i++) { echo '<tr> <td width="151"><strong>Article #'.$i.'</strong></td> <td width="442"></td> </tr> <tr> <td>Upload Pic:</td> <td><input type="file" name="file' . $i . '"></td> </tr> <tr> <td>Content:</td> <td><textarea rows=10 cols=40 name="news_content' . $i . '" value="'. $row['content'].'"></textarea></td> </tr> <tr> <td>Type:</td> <td><select name="type' . $i . '" id="type"> <option>Choose one</option> <option value="house">House</option> <option value="hip hop">Hip Hop</option> <option value="both">Both</option></br></br></td> </tr>'; }?> </table><br /><input type="submit" value="Submit News" /></form></div>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14070-echo-inside-of-another-echo/#findComment-55012 Share on other sites More sharing options...
kenrbnsn Posted July 9, 2006 Share Posted July 9, 2006 You're problem maybe that you're using the <textarea> tag incorrectly. That tag doesn't have a 'value="' attribute, but the value should go between the <textarea> and the </textarea> tags. Also, are you sure that the value of $num_news is greater than or equal to 1?You do realize that this code will output the same $row['content'] n times, where n = $num_news?For the <textarea> tag, try:[code]<td><textarea rows=10 cols=40 name="news_content' . $i . '">'. $row['content'].'></textarea></td>[/code]Also, you will find that using arrays for the names will make the processing of the information coming back from the form much easier:[code]<?phpfor ($i=1;$i<=$num_news;$i++) { echo '<tr> <td width="151"><strong>Article #'.$i.'</strong></td> <td width="442"></td> </tr> <tr> <td>Upload Pic:</td> <td><input type="file" name="file[' . $i . ']"></td> </tr> <tr> <td>Content:</td> <td><textarea rows=10 cols=40 name="news_content[' . $i . ']">'. $row['content'].'</textarea></td> </tr> <tr> <td>Type:</td> <td><select name="type[' . $i . ']" id="type"> <option>Choose one</option> <option value="house">House</option> <option value="hip hop">Hip Hop</option> <option value="both">Both</option></br></br></td> </tr>'; }?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/14070-echo-inside-of-another-echo/#findComment-55018 Share on other sites More sharing options...
digitalgod Posted July 9, 2006 Author Share Posted July 9, 2006 hey Ken,that worked perfectly thank you.If I use arrays in the form how do I process them?this is what I got in my admin.php[code]for ($i = 1;$i <= $num_news;$i++) { $headline = $i; $content = $_POST['news_content' . $i]; $type = $_POST['type' . $i]; mysql_query("UPDATE " . $prefix . "news SET content='$content',type='$type' WHERE headline='$headline' AND date='$date'") or die(query_error()); }[/code]but it doesn't seem to update anything, it doesn't give me an error either. I think it has to do with $num_news. In the form $num_news is greater than 1. but when I echo $num_news right before the loop it doesn't output anything.this is what defines $num_news[code]if ($_POST['date'] != '') { $_SESSION['news_date'] = $_POST['date']; //gets it from the first form $date = $_SESSION['news_date']; $result = mysql_query("SELECT COUNT(*) AS count FROM " . $prefix . "news WHERE date='$date'"); $_SESSION['num_news'] = mysql_result($result,0,'count'); $num_news = $_SESSION['num_news']; echo $num_news; //works perfectly here }[/code]And yes I did notice that it will output $row['content'] n times, I'm really not sure how to get the correct info from the DB. Let's say I have 3 entries that have the same date but different content, I want to be able to display that content in different textboxes Quote Link to comment https://forums.phpfreaks.com/topic/14070-echo-inside-of-another-echo/#findComment-55023 Share on other sites More sharing options...
Daniel0 Posted July 9, 2006 Share Posted July 9, 2006 Why do you define everything as a session variable first? Quote Link to comment https://forums.phpfreaks.com/topic/14070-echo-inside-of-another-echo/#findComment-55034 Share on other sites More sharing options...
digitalgod Posted July 9, 2006 Author Share Posted July 9, 2006 because most of everything is stored in sessions and if for some reason I decide to rename the session variable, Iwon't have to rename it everywhere Quote Link to comment https://forums.phpfreaks.com/topic/14070-echo-inside-of-another-echo/#findComment-55040 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.