PHP - Break In Id Numbers Breaks Echo?!
I have a list which is echo line by line from a database using the ID number as the identifier. However, the echo has now stopped because I have removed 3 lines. Instead of skipping from ID13 to ID17 it stops at ID13 so whatever else goes into the database it will not display it. Can anyone advise why this may have happened?
ID 12 ID 13 break break break ID 17 ID 18 ID 19 Similar Tutorialshello guys, suppose I want to echo out the text given below exactly as what has been set against, including the line breaks. How do I do it? coz each time i did it so, there s no line breaks but the output is usually a dense lump of words with no paragraphs. Code: [Select] I took her out it was a Friday night I wore cologne to get the feeling right We started making out and she took off my pants But then I turned on the TV And that's about the time she walked away from me Nobody likes you when you're 23 I'm still more amused by TV shows What the hell is ADD? My friends say I should act my age What's my age again? What's my age again? please help P.S. The whole set of phrase give above are treated as a single variable coz I use a WHILE loops when making an echo. tthanks Hey all - What is the appropriate syntax to echo out each character name (vanity_name), and their total number of "ties" "wins" and "losses" Thanks for your help! $q1 = "SELECT Wins, Ties, Losses from game_char WHERE vanity_name='mario'"; $mario_sql = mysql_query($q1); Code: [Select] <?php echo "Mario: " . $mario_sql; ?> Hi, I need to sort variables in groups of up to 15 and put it in an array. For example: $exstract['center_tabOpBody_0'] =5 $exstract['center_tabOpBody_1'] =6 $exstract['center_tabOpBody_2'] =8 $exstract['center_tabOpBody_3'] =1 Should yield: ARRAY( = center_tabOpBody_1,center_tabOpBody_2,center_tabOpBody_3 // <-----15 [1] = center_tabOpBody_0 //<----5 ) Is there some simple function do do the "efficiency" sort? Thanks, Vadim OK, have no idea what's going on... I've done this a million times... why wont this output!?? I must have a major brain meltdown and dont know it yet!!! Code: [Select] <?php // this echoes just fine: echo $_POST['testfield']; // but this wont echo: echo if (isset($_POST['testfield'])) { $_POST['testfield'] = $test; } echo $test; /// or even this DOESNT echo either!: $_POST['testfield'] = $test; echo $test; ?> Hi All, I'm trying to echo the response from an SLA query, the query works and returns the data when I test it on an SQL application.. but when I run it on my webpage it won't echo the result. Please help? <?php $mysqli = mysqli_connect("removed", "removed", "removed", "removed"); $sql = "SELECT posts.message FROM posts INNER JOIN threads ON posts.pid=threads.firstpost WHERE threads.firstpost='1'"; $result = mysqli_query($mysqli, $sql); echo {$result['message']}; ?> I have a log system that allows 10 logs on each side(Left and right). I am trying to make it so that the left side has the 10 most recent logs, then the right as the next 10. Any ideas? So I need to echo a row from my database with php, but where i need to echo is already inside an echo. This is my part of my code: $con = mysql_connect("$host","$username","$password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("main", $con); $result = mysql_query("SELECT * FROM Vendor"); while($row = mysql_fetch_array($result)) { //I need to echo right here .................. but I get a blank page when I try this. Please Help. echo '<option value=$row['vendor_id']>'; echo $row['vendor_id']; echo '</option>'; } mysql_close($con); Result: A Blank page. Thanks in advance! I'm trying to insert the contents of a textarea into a MySQL database but I am wondering what the best way is to preserve the users line breaks. I know that you can use nl2br() to convert "\n" into "<br />" when the retrieve data from the database but I am looking at a way to insert these line breaks when I enter the data. Thanks for any help. Just a general question, but could someone help me and tell me how to allow the user to enter a <br> without actually typing it. Like when they're typing in the forums, I want it to automatically go on a new line when they hit the ENTER key. Or could someone lead me to a guide? I tried searching everywhere and just can't seem to find it. Hi
I try to echo out random lines of a html file and want after submit password to whole content of the same html file. I have two Problems.
1st Problem When I echo out the random lines of the html file I don't get just the text but the code of the html file as well. I don't want that. I just want the text. How to do that?
for($x = 1;$x<=40;$x++) { $lines = file("$filename.html"); echo $lines[rand(0, count($lines)-1)]."<br>"; }I tried instead of "file("$filename.html");" "readfile("$filename.html");" But then I get the random lines plus the whole content. Is there anything else I can use instead of file so that I get the random lines of text without the html code?P.S file_get_contents doesn't work either have tried that one. 2nd Problem: As you could see in my first problem I have a file called $filename.html. After I submit the value of a password I want the whole content. But it is like the program did forget what $filename.html is. How can I make the program remember what $filename.html is? Or with other words how to get the whole content of the html file? My code: if($_POST['submitPasswordIT']){ if ($_POST['passIT']== $password ){ $my_file = file_get_contents("$filename.html"); echo $my_file; } else{ echo "You entered wrong password"; } }If the password isn't correct I get: You entered wrong password. If the password is correct I get nothing. I probably need to create a path to the file "$filename.html", but I don't know exactly how to do that. I have an XML file (differences.xml) <element> <item code="lM" name="castle" type="building"> <cost>5000</cost> </item> ...more items.... </element> I have parser.php whih parses the XML and displays all item names in a checklist for the user to select items. These selected items are method=post back to parser.php which re-parses the XML where selected item = item name and SHOULD then display all selected items' names (and more): <?php if (isset($_GET['formSubmit'])) { $option = $_POST['option']; $option = array_values($option); if (!empty($option)){ $xml = simplexml_load_file('differences.xml'); $i = 0; $count = count($option); while($i < $count) { $selected = $xml->xpath("//item[@name='".$option[$i]."']"); echo $selected[$i]['name']; $i++; } }else{ echo "No items selected, Please select:"; } }else{ $xml = simplexml_load_file('differences.xml'); $object = $xml->xpath('//item'); $count = count($object); $i = 0; echo "<form method='POST' action='parser.php'>"; while($i < $count){ $xmlname = $object[$i]['name']; echo "<input type='checkbox' name='option[".$i."]' value='$xmlname'>".$xmlname; echo "<br>"; $i++; } echo "<br><input type='submit' name='formSubmit' value='Proceed'><br>"; echo "</form>"; } ?> The problem is, the parser is only displaying the first selected item and isn't outputting the rest. To clarify the code: - The first half executes only if items have been previously selected in the form. If no items were selected, it goes to the secod half, which parses the XML file and presents the checklist form for the user to select items. THIS WORKS GREAT. - After pressing the submit button, the items are sent using POST and the page is reloaded. THIS WORKS GREAT. - After reloading, the first half executes and finds the $_POST and resets the array so that it works with the coming loop. THIS WORKS GREAT. - The loop parses the XML and returns only those item names that have been selected in the $_POST. THIS DOES NOT WORK. So my question is: what's wrong with my code? The array $options has all the proper information, but the parser is only outputting the first item. All consecutive loops result in empty space with no output. I've been at this for 2 weeks and can't find the solution. Any help is appreciated! Here's the code that I have: Code: [Select] <?php if (get_magic_quotes_gpc()) { function undoMagicQuotes($array, $topLevel=true) { $newArray = array(); foreach($array as $key => $value) { if (!$topLevel) { $key = stripslashes($key); } if (is_array($value)) { $newArray[$key] = undoMagicQuotes($value, false); } else { $newArray[$key] = stripslashes($value); } } return $newArray; } $_GET = undoMagicQuotes($_GET); $_POST = undoMagicQuotes($_POST); $_COOKIE = undoMagicQuotes($_COOKIE); $_REQUEST = undoMagicQuotes($_REQUEST); } function safe($value){ return mysql_real_escape_string($value); } $subject1 = "It's just a test."; $message1 = // $subject1 and message1 are actually submitted from a form on the page... "Here's a test. // so this section would really be $subject = safe($_POST['subject']); same w/ message // I did it this way to simplify... I'm pretty sure it would be the same either way. Thanks, Me"; // this is what is typed in the text area of the form. $subject = safe($subject1); $message = safe($message1); ?> When these variables are mailed using php mail(), they display like this: Code: [Select] Subject: It\'s just a test. Message: Here\'s a test.\r\n\r\nThanks,\r\nMe When they are inserted into a database, they are inserted correctly, as they were typed. My question is this: Is there a way to mail these and have them display correctly? Should I just insert them into the database, then select them again to mail? Thanks for any help. php5 I am using json_encode() to store an array of data as a string in a mysql data base. I then extract the sting from the data base and convert the back into an array using json_decode. This works great up until I have any line breaks in any of the data. When there is a line break, the json_decode() function chokes and returns nothing. I would really like to keep the line breaks. Has anyone come across this issue/have an suggestions/solutions? I have developed the following code, which queries a MySQL database and returns multiple results using several WHILE loops: Code: [Select] <?php # if submit_hash is present, then pull up the attendance from specified hash if($_GET['submit_hash']) { # select all the hashers from the specified hash $query = " SELECT h.*, ha.* FROM hashes as h, hashers as ha, hash_records as hr WHERE hr.hash_id = " . $_GET['hash_id'] . " && hr.hash_id = h.hash_id && hr.hasher_id = ha.hasher_id ORDER BY ha.hasher_name "; $result = mysql_query($query) or die('Error selecting Hash attendance.'); $x = 1; while($row = mysql_fetch_array($result)) { if($x == 1) { echo '<strong>' . $row['hash_num'] . ' ' . $row['hash_name'] . ' - ' . date("D, d M Y", strtotime($row['hash_date'])) . '</strong><em>Total Hashers: ' . mysql_num_rows($result) . '</em>'; $x++; } # see if this person was the hare if($row['hare_id'] == $row['hasher_id'] || $row['hare2_id'] == $row['hasher_id'] || $row['hare3_id'] == $row['hasher_id']) { $hare = '- hare'; } else { $hare = ''; } echo $row['hasher_name'] . ' <b>' . $hare . '</b>'; } } else if($_GET['submit_hasher']) { # if submit_hasher is present, pull up all of their hashes and aliases # select all the hashes that this person has attended $a_query = " SELECT h.*, ha.* FROM hashes as h, hashers as ha, hash_records as hr WHERE hr.hash_id = h.hash_id && hr.hasher_id = ha.hasher_id && hr.hasher_id = " . $_GET['hasher_id'] . " ORDER BY h.hash_date DESC "; $a_result = mysql_query($a_query) or die('Error selecting the person\'s Hashes . '); $x = 1; while($a_row = mysql_fetch_array($a_result)) { if($x == 1) { echo '<strong>Hash Attendance Record For ' . $a_row['hasher_name'] . '</strong> <em>(' . mysql_num_rows($a_result) . ' total hashes)</em>'; $x++; } echo '#' . $a_row['hash_num'].' ' . $a_row['hash_name'] . ' on ' . date("D, d M Y", strtotime($a_row['hash_date'])); # see if this person was a hare if($a_row['hasher_id'] == $a_row['hare_id'] || $a_row['hasher_id'] == $a_row['hare2_id'] || $a_row['hasher_id'] == $a_row['hare3_id']) { echo ' - <b>hare</b>'; } echo ''; } echo ''; } echo ' <table width="100%"> <br /> <tbody> <tr> <br /> <td> '; ?> The problem is that everything that is returned from the WHILE loops is displayed in a single line. However, I want the data displayed with a line break between each result, like this: Header Return 1 from WHILE loop Return 2 from WHILE loop Return 3 from WHLIE loop How do I need to modify the code to make it display appropriately? Hey I am trying to write to a csv file with the data in my database. My problem I am having is that when I echo out to the browser everything is fine, but when I try writing to the file I get a lot of line breaks and that throws everything off for the csv file. Here's my code: Code: [Select] $query = "SELECT * FROM $table"; $result = mysql_query($query); $numcolumns = mysql_num_fields($result); $numrows = mysql_num_rows($result); $file = "testFile.csv"; $fh = fopen($file, 'w') or die("can't open file"); while($row = mysql_fetch_array($result)) { for($i = 0; $i <= ($numcolumns - 1); $i++) { if($i < ($numcolumns - 1)) { $string = $row[$i] . ","; echo $string; fwrite($fh, $string); } else { $string = $row[$i]; echo $string; fwrite($fh, $string); } } $string = "\n"; echo "<br />"; fwrite($fh, $string); } fclose($fh); My output to the browser looks like this for one record.. which is how it should look: (Had to edit the content a bit for confidential reasons) Code: [Select] ######,12/31/99 ,123 Drive,City,TX ,##### ,County And here is what I get in the csv file when I open it up on notepad: Code: [Select] ######,12/31/99 ,123 Drive ,City ,TX ,##### ,County Any idea where these line breaks are coming from? Is it because the data is being pulled from a database? Any help on how to fix this would be great!! Thanks. I am constructing an XML file with PHP. I read information from a template XML file and then add elements and save it. The line breaks from the template are preserved in the saved file, but all the new elements are on one line. Is there a way to break them up so it is easier to read the file? Here is the original template: Code: [Select] <InternationalShippingServiceOption> <ShippingService> token </ShippingService> <ShippingServiceAdditionalCost currencyID="CurrencyCodeType"> AmountType (double) </ShippingServiceAdditionalCost> <ShippingServiceCost currencyID="CurrencyCodeType"> AmountType (double) </ShippingServiceCost> <ShippingServicePriority> int </ShippingServicePriority> </InternationalShippingServiceOption> Here is the saved information (all the ShipToLocation elements on one line): Code: [Select] <InternationalShippingServiceOption> <ShippingService>StandardInternational</ShippingService> <ShippingServiceAdditionalCost currencyID="CurrencyCodeType">26.994</ShippingServiceAdditionalCost> <ShippingServiceCost currencyID="CurrencyCodeType">44.99</ShippingServiceCost> <ShippingServicePriority>2</ShippingServicePriority> <ShipToLocation>BE</ShipToLocation><ShipToLocation>FR</ShipToLocation><ShipToLocation>IE</ShipToLocation><ShipToLocation>LU</ShipToLocation><ShipToLocation>MC</ShipToLocation><ShipToLocation>NL</ShipToLocation><ShipToLocation>GB</ShipToLocation><ShipToLocation>DE</ShipToLocation><ShipToLocation>IT</ShipToLocation></InternationalShippingServiceOption> I am using the $doc->formatOutput = true; option. probably another overly-newbie-ish question, but I built a series of pages for inputting data. Page 1 inputs data to table 1, pulls the item id and passes it to page 2 to input to table 2. This all works fine. But now I want to add a header and footer to include the site design. And when I add my <? include("header.php"); ?>, it stops working. I tried naming the header something else, in case it was just a duplicate name somewhere, but the problem is still there. When i submit, it goes to the next page and generates this error: Warning: Cannot modify header information - headers already sent by (output started at header.php:62) in file.php on line 65 Is there a way to include a header without it creating this issue? Or do I put it lower down in the code? Here's the main idea of the code: Code: [Select] if (isset($_POST['submitted'])) { $errors = array(); $descriptor1 = trim($_POST['plant_id']); $descriptor2 = trim($_POST['existence_status']); $descriptor3 = etc. etc. if (empty($errors)) { require ('connection.php'); $query = "INSERT INTO habits (plant_id, existence_status, reproduction_methods, etc.) VALUES ('$descriptor1', '$descriptor2', etc.)"; $result = @mysql_query ($query); $plant_id=mysql_insert_id(); header ("Location: thisfile.php?var1=$plant_id"); and, if it helps any, here's the header file: Code: [Select] <div id="ugg" style="background-color:#CDE472; height:80px; padding:10px;"> <h1>Twigzy</h1> </div> <style type="text/css" media="screen"> /**************** menu coding *****************/ #menu { width: 100%; background: #eee; float: left; } #menu ul { list-style: none; margin: 0; padding: 0; width: 12em; float: left; } #menu a, #menu h2 { font: bold 11px/16px arial, helvetica, sans-serif; display: block; border-width: 1px; border-style: solid; border-color: #ccc #888 #555 #bbb; margin: 0; padding: 2px 3px; } #menu h2 { color: #fff; background: #324F17; text-transform: uppercase; } #menu a { color: #000; background: #efefef; text-decoration: none; } #menu a:hover { color: #a00; background: #fff; } #menu li {position: relative;} #menu ul ul { position: absolute; z-index: 500; } #menu ul ul ul { position: absolute; top: 0; left: 100%; } div#menu ul ul, div#menu ul li:hover ul ul, div#menu ul ul li:hover ul ul {display: none;} div#menu ul li:hover ul, div#menu ul ul li:hover ul, div#menu ul ul ul li:hover ul {display: block;} </style> <!--[if IE]> <style type="text/css" media="screen"> #menu ul li {float: left; width: 100%;} </style> <![endif]--> <!--[if lt IE 7]> <style type="text/css" media="screen"> body { behavior: url(csshover.htc); font-size: 100%; } #menu ul li a {height: 1%;} #menu a, #menu h2 { font: bold 0.7em/1.4em arial, helvetica, sans-serif; } </style> <![endif]--> <!-- start menu HTML --> <div id="menu"> <ul> <li><a href="link"">Home</a> </li> </ul> <ul> <li><h2>About</h2> <ul> <li><a href="link0.com">About site</a> </li> </ul> </li> </ul> <ul> <li><h2>Search for a plant</h2> <ul> <li><a href="link1.php">Basic Search</a></li> <li><a href="link2.php">Search by Leaf</a></li> <li><a href="link3.php">Search by Flower</a></ul> </li> </ul> <ul> <li><h2>Login</h2> <ul> <li><a href="link4.php">Login</a></li> <li><a href="asdf.html">asdfasdf</a><!-- fully working sample --> <ul> <li><a href="test.html">asdf</a> </li> </ul> </li> </ul> </li> </ul> </div> Hi there. I have a javascript code that packages an array as a string and sends it to a php mailer, which then separates the string into an array for mailing using a preg_split regular expression that searches for a comma followed by an html tag.
$myWrongArray = preg_split("/,(?=<)/",$myVar); // lookahead splits the string when the comma is before a tag (the opening bracket < ) Everything works great EXCEPT when the string contains a degree sign or an &, in which case the array is returned up to the degree or & and then stops. I can’t for the life of me understand it. Any ideas? Okay, so I keep crashing my server while trying to get a simple script to run. Firstly, here's the code. <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql'); $dbname = 'businessletters'; mysql_select_db($dbname); $files = getFiles("parseme.txt"); for($i=0;$i<200;$i++) { $file = getReadFile($files[$i][0]); insertIntoDb($files[$i][1], $file); //echo "Inserted successfully - " . $files[$i][0] . "<br />"; } function getFiles($file) { $fh = fopen($file, "rb"); $data = fread($fh, filesize($file)); fclose($fh); $dataArr = explode("\n", $data); for($i=0;$i<count($dataArr);$i++) { $dataArr[$i] = explode(",", $dataArr[$i]); } return($dataArr); } function getReadFile($file) { $fh = fopen($file, "rb"); $data = fread($fh, filesize($file)); fclose($fh); return $data; } function insertIntoDb($title, $body) { $sql = "insert into letters values('', '".mysql_real_escape_string($title)."', '".mysql_real_escape_string($body)."')\n"; //mysql_query($sql) or die("Error inserting"); echo $sql; } mysql_close(); ?> And now, here's what it's supposed to do. Open and read File A - this file has file names and titles in a CSV file. File,Title is the format. Then the loop starts. Here I would like to do everything in one run, which could be done by counting the records in the CSV file, which I can do with count(), but even 200 is too much. I have 600. Anyway, it goes through the CSV file and opens every file referenced and pulls out the content. Then it creates a simple SQL statement where the content is entered into the database. And the problem is that Apache keeps crashing on me... There must be a better way for me to do this without having my server crash on me! |