herghost Posted April 26, 2009 Share Posted April 26, 2009 Hi All, I am not sure if this is an HTML or PHP question but thought I would try in here first: I have this <form id="banddisco" name="banddisco" method="post" action="do/banddiscodo.php"> <table border="0"> <tr> <td width="216">Album Name</td> <td width="216"><input name="albumname" type="text" id="albumname" size="60"></td> </tr> <tr> <tr> <td width="216" valign="top">Tracks Names (One Per Line)</td> <td width="216"><textarea name="tracks" cols="60" rows="30" id="tracks"></textarea></td> </tr> </table> <br /> <br /> <input type="submit" name="Submit" value="Go" /> </form> Which is a simple form for entering an albbum name and then the tracks. Is it possibe to add a line break at the end of each line in the tracks field? Basically when echoed from the database I want them one line after another. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/155757-form-help/ Share on other sites More sharing options...
gnawz Posted April 26, 2009 Share Posted April 26, 2009 You can do one of 3 things: -Use the n tag at every result line -Echo them in a table -Use CSS Quote Link to comment https://forums.phpfreaks.com/topic/155757-form-help/#findComment-819884 Share on other sites More sharing options...
coalgames Posted April 26, 2009 Share Posted April 26, 2009 What gnawz is saying on using the n tag, is when you echo, use "\n" to create a new line. When printing out each row, use the \n character in double quotes: foreach ( $track_names_array as $value ) { echo $value . "\n"; } This way will have a result of : sometrack another track Beetles Track The text area will have line breaks. I hope this is what you are looking for. Quote Link to comment https://forums.phpfreaks.com/topic/155757-form-help/#findComment-819897 Share on other sites More sharing options...
gnawz Posted April 26, 2009 Share Posted April 26, 2009 I guess that is what herghost is looking for Quote Link to comment https://forums.phpfreaks.com/topic/155757-form-help/#findComment-819908 Share on other sites More sharing options...
herghost Posted April 26, 2009 Author Share Posted April 26, 2009 Ok, so I am currently showing the results like so: <?php $sql = "SELECT * FROM banddisco WHERE userid = '$userid' ORDER BY RAND() LIMIT 10"; $result = mysql_query($sql ,$con); while($myrow = mysql_fetch_array($result)) { echo "<table width ='90%'>"; echo "<tr>"; echo "<td>"; echo $myrow['albumname']; echo "</td>"; echo "<td>"; echo $myrow['tracks']; echo "</td>"; echo "</table>"; } ?></p> and they are being stored in a database like so: <?php //Start session session_start(); //Include database connection details require_once('../include/database.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $userid = $_SESSION['SESS_USERID']; $albumname = clean($_POST['albumname']); $tracks = clean($_POST['tracks']); $sql = mysql_query("SELECT * FROM banddisco WHERE userid = '$userid'"); if(mysql_num_rows($sql) == 0) { //Create INSERT query $qry = "INSERT INTO banddisco (userid, albumno, albumname, tracks) VALUES ('$userid', '', '$albumname', '$tracks')"; } $result = mysql_query($qry) or die(mysql_error()); //Check whether the query was successful or not if($result) { header("location: ../member_home.php?disco=1"); exit(); }else { die(mysql_error()); } ?> What would I have to do to save them to an array so I can display using /n? Guess this has moved to an php question now! Quote Link to comment https://forums.phpfreaks.com/topic/155757-form-help/#findComment-819926 Share on other sites More sharing options...
gnawz Posted April 27, 2009 Share Posted April 27, 2009 Simply add /n to your echo. otherwise the tabular way can achieve it very well too <? echo $myrow['albumname']; echo "\n"; echo $myrow['tracks']; echo "\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/155757-form-help/#findComment-819939 Share on other sites More sharing options...
herghost Posted April 27, 2009 Author Share Posted April 27, 2009 Hi mate, cant get this to work, do you think its because when they are entered its all as one text block? Quote Link to comment https://forums.phpfreaks.com/topic/155757-form-help/#findComment-820471 Share on other sites More sharing options...
gnawz Posted April 27, 2009 Share Posted April 27, 2009 Nope. You must be doing something wrong. Show your code A table in a loop would come in handy Quote Link to comment https://forums.phpfreaks.com/topic/155757-form-help/#findComment-820474 Share on other sites More sharing options...
herghost Posted April 27, 2009 Author Share Posted April 27, 2009 <?php session_start(); include('include/database.php'); $userid = $_GET['userid']; $_SESSION['bandid'] = $userid; ?> <?php $sql = "SELECT * FROM banddisco WHERE userid = '$userid' ORDER BY RAND() LIMIT 10"; $result = mysql_query($sql ,$con); while($myrow = mysql_fetch_array($result)) { echo "<table width ='90%'>"; echo "<tr>"; echo "<td>"; echo $myrow['albumname']; echo "\n"; echo "</td>"; echo "<td>"; echo $myrow['tracks']; echo "\n"; echo "</td>"; echo "</table>"; } ?></p> Table in loop? Gap in my knowledge I think! Quote Link to comment https://forums.phpfreaks.com/topic/155757-form-help/#findComment-820520 Share on other sites More sharing options...
gnawz Posted April 28, 2009 Share Posted April 28, 2009 Something like: echo '<br><h5>These are your results</h5></br>';//showing featured listings echo '<table border=1 table width="980" align="center">'; echo "<tr>"; $count = 5;//rows $l = 0; for($i=0;$i<mysql_num_fields($listing);$i++) { echo "<th>"; echo mysql_field_name($listing, $i); echo "</th>"; } while($l < $count) { $row=mysql_fetch_row($listing); echo "<tr>"; for($j=0;$j<$i;$j++) { echo "<td>"; echo $row[$j]; echo "</td>"; } echo "</tr>"; $l++; } echo "</tr>"; echo "</table>"; ////////OR echo '<table border = "1" bordercolor="#000000">'; echo '<tr>'; //displaying the headings echo '</tr>'; echo '<tr>'; echo '<td width="20" height="20">'; echo '<b>Fld1</b>'; echo '</td>'; echo '<td width="20" height="20">'; echo '<b>Fld2</b>'; echo '</td>'; echo '<td width="20" height="20">'; echo '<b>Fld3</b>'; echo '</td>'; echo '<td width="20" height="20">'; echo '<b>Fld4</b>'; echo '</td>'; echo '<td width="20" height="20">'; echo '<b>Fld5</b>'; echo '</td>'; echo '<td width="20" height="20">'; echo '<b>Fld6</b>'; echo '</td>'; echo '</tr>'; //getting the database fields while($row = mysql_fetch_array($query)) { echo '<tr>'; echo '<td>'; $name = $row["Fld1"]; echo $name. "<br>"; echo '</td>'; echo '<td>'; $add = $row["Fld2"]; echo $add. "<br>"; echo '</td>'; echo '<td>'; $email = $row["Fld3"]; echo $email. "<br>"; echo '</td>'; echo '<td>'; $web = $row["Fld4"]; echo ('<b><a href="'.$web.'">'.$web.'</a></b>'); echo '</td>'; echo '<td>'; $tel = $row["Fld5"]; echo $tel. "<br>"; echo '</td>'; echo '<td>'; $loca = $row["Fld6"]; echo $loca. "<br>"; echo '</td>'; echo '<td>'; } echo '</table><br/>'; } Hope it helps.... Quote Link to comment https://forums.phpfreaks.com/topic/155757-form-help/#findComment-820956 Share on other sites More sharing options...
herghost Posted April 28, 2009 Author Share Posted April 28, 2009 Thanks, I have this error: These are your results Warning: mysql_num_fields(): supplied argument is not a valid MySQL result resource in C:\wamp\www\fanjunky\banddiscoview.php on line 41 Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\fanjunky\banddiscoview.php on line 50 Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\fanjunky\banddiscoview.php on line 50 Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\fanjunky\banddiscoview.php on line 50 Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\fanjunky\banddiscoview.php on line 50 Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\fanjunky\banddiscoview.php on line 50 and this is my code <?php session_start(); include('include/database.php'); $userid = $_GET['userid']; $_SESSION['bandid'] = $userid; ?> //$sql = "SELECT * FROM banddisco WHERE userid = '$userid' ORDER BY RAND() LIMIT 10"; //$result = mysql_query($sql ,$con); //while($myrow = mysql_fetch_array($result)) //{ //echo "<table width ='90%'>"; //echo "<tr>"; //echo "<td>"; //echo $myrow['albumname']; //echo "\n"; //echo "</td>"; //echo "<td>"; //echo $myrow['tracks']; //echo "\n"; //echo "</td>"; //echo "</table>"; //} // <?php $sql = "SELECT * FROM banddisco WHERE userid = '$userid' ORDER BY RAND() LIMIT 10"; $result = mysql_query($sql ,$con); echo '<br><h5>These are your results</h5></br>';//showing featured listings echo '<table border=1 table width="980" align="center">'; echo "<tr>"; $count = 5;//rows $l = 0; for($i=0;$i<mysql_num_fields($userid);$i++) { echo "<th>"; echo mysql_field_name($userid, $i); echo "</th>"; } while($l < $count) { $row=mysql_fetch_row($userid); echo "<tr>"; for($j=0;$j<$i;$j++) { echo "<td>"; echo $row[$j]; echo "</td>"; } echo "</tr>"; $l++; } echo "</tr>"; echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/155757-form-help/#findComment-821313 Share on other sites More sharing options...
herghost Posted April 28, 2009 Author Share Posted April 28, 2009 Ignore Aove! I have now had a long overdue brainwave and have this: <?php $sql = "SELECT * FROM banddisco WHERE userid = '$userid' ORDER BY RAND() LIMIT 10"; $result = mysql_query($sql ,$con); echo '<br><h5>These are your results</h5></br>';//showing featured listings echo '<table border=1 table width="980" align="center">'; echo "<tr>"; $count = 5;//rows $l = 0; for($i=0;$i<mysql_num_fields($result);$i++) { echo "<th>"; echo mysql_field_name($result, $i); echo "</th>"; } while($l < $count) { $row=mysql_fetch_row($result); echo "<tr>"; for($j=0;$j<$i;$j++) { echo "<td>"; echo $row[$j]; echo "</td>"; } echo "</tr>"; $l++; } echo "</tr>"; echo "</table>"; ?> However it still lists the tracks one after another and not on a seperate line, as well as displaying all the fields in the database. I can I get it to display just the fields `album` and `tracks`, with the tracks one per line? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/155757-form-help/#findComment-821331 Share on other sites More sharing options...
gnawz Posted April 28, 2009 Share Posted April 28, 2009 Now I think yo might have to use the \n tag else... create a table with one column and multiple rows to display your results. echo each variable you want to display in the rows Quote Link to comment https://forums.phpfreaks.com/topic/155757-form-help/#findComment-821397 Share on other sites More sharing options...
TheFilmGod Posted April 29, 2009 Share Posted April 29, 2009 /n only creates a new linebreak in the source - not necessarily the final image. Html is non-white-space sensitive. You could format Hello like this: <!-- HTML --> H e l l o <!-- End of HTML --> And you still get: Hello. To create a linebreak in html/final image, use a <br /> Quote Link to comment https://forums.phpfreaks.com/topic/155757-form-help/#findComment-821556 Share on other sites More sharing options...
gnawz Posted April 29, 2009 Share Posted April 29, 2009 herghost, Actually <br> is pretty good. Quote Link to comment https://forums.phpfreaks.com/topic/155757-form-help/#findComment-821683 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.