Jump to content

JPark

Members
  • Posts

    75
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

JPark's Achievements

Member

Member (2/5)

0

Reputation

  1. salathe, Well, I changed the code and tested it and doggonit you are right! While your analogy makes sense NOW, before I was just thinking of them as line breaks in different languages as in "Hi! Hola!" is pretty much the same as "Hola! Hi!" I stand sit corrected. Thanks for clarifying!! Joe
  2. So \n\r is different than \r\n??
  3. I have a php page with a form that, upon submit, generates a text file of the person's choices -- using it as a flat file. I want to start a new line with each entry so I used \n\r as in $line1= $today."^".$_POST['email']."^".$value; foreach ($sector_numbers as $key => $value) { $line = "{$line1}^{$value}\n\r"; $file_write = fwrite($file_handle, $line); } The problem is that my text file shows little boxes instead of new lines (see attachment). Why? How can I fix it? Thanks! Joe [attachment deleted by admin]
  4. Warning: Noob Alert... I am playing around with forms and functions and am getting an error. Here's the form: <form action="functions.php" method="post" > <p>Pick one or more colors:</p> <p><input name="colors[]" type="checkbox" value="red"> Red | <input name="colors[]" type="checkbox" value="orange"> Orange | <input name="colors[]" type="checkbox" value="yellow"> Yellow | <input name="colors[]" type="checkbox" value="green"> Green | <input name="colors[]" type="checkbox" value="blue"> Blue | <input name="colors[]" type="checkbox" value="indigo"> Indigo | <input name="colors[]" type="checkbox" value="violet"> Violet</p> <hr align="left" width="560"> <p><input type="reset" name="Reset" value="Clear"> <input type="submit" name="Submit" value="Submit"></p> </form> and here's the php results page: <form action="<?=$_SERVER['PHP_SELF'];?>" method="post"> <tr> <td colspan='2' style='background: #E5E5E5; padding:3px 10px;'> <p style='font-weight:bold; text-align:center;'>You are almost done...</p></td> <tr> <td colspan='2' style='background: #E5E5E5; border-bottom: 1px solid #000; padding:3px 10px;'> <input type="submit" value="ENTER" /></td> </tr> </table> </form> <?php echo "<hr width='200px' align='left'>"; echo "<h4>My Function:</h4>"; $colors = $_POST['colors']; function showColors(&$colors) { foreach ($colors as $key => $value) { echo $key." ==> ".$value." "; } } showColors($colors); ?> The first time I get the results page, I get my selected colors displayed no problem. However, if I click Enter on the results page, I get Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\functions.php on line 87 What am I doing wrong? Thanks! Joe
  5. We need to move all of our documents (pdf, doc, wpd, xls, ppt) off of the web server and into a document management system. Groan. I want to start at the top level and search most -- but not all -- the sub-folders and spit out a nice pretty list of all the documents (and folder location). Anyone have something like that? Thanks!!
  6. That works great! I appreciate your help.
  7. I have an intranet page where people can make comments or suggestions. The powers-that-be would like to review the comments before they are posted on the web page. Right now, I have a form that the 'customer' can fill out. When they hit submit, their name, e-mail and comments get posted to a mysql database and the powers-that-be get an e-mail notification. I would like them to be able to go to an approval page and see all (or one at a time) the posts that are pending approval and be given a choice to approve or delete each comment. I would like to keep it all on one page and, each time a comment is approved or deleted, the page is refreshed with the next comment to approve/delete. Is that an option with php? I know I can query one row at at a time with mysql_fetch_array, but I can't seem to get past the first row. On the other hand, if I display all the comments, the page doesn't refresh right. I will continue to see the comments that have already been deleted or F5 will attempt the same query. This is what I am am working with... $query = 'SELECT * FROM `comments` WHERE `approved` = 1'; //1 = new, 2 = approved $result=mysql_query($query) or die(mysql_error() ); while($row = mysql_fetch_array($result)){ echo $row['name']. " - ". $row['email']; $id = $row['id']; ?> <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" name="test"> <input name="decision" type="radio" value="approve" /> Approve this comment<br /><input name='id' type='hidden' value='<?php echo $row['id']; ?>' /> <input name="decision" type="radio" value="delete" /> Delete this comment<br /> <input name="Submit" type="submit" /> <input name="Reset" type="reset" value="Reset" /> </form> <?php if ($_POST['decision'] == 'delete') { mysql_query("DELETE FROM comments WHERE id = '$id'"); echo $row['id']."<br />"; } } Any thoughts?
  8. ok... : "hello"; does what I thought it should do to begin with but I don't quite understand what you wrote... Is the problem from the return ($row[4])? Is that why the page is looking for something to be returned?
  9. Ok. Makes a bit of sense... So, why does my page crap out (nothing at all displays) if I change it to return ($row[4]) ? sprintf($html, $row[3], htmlentities( $row[1] ) ) : echo "hello"; Isn't this saying that $row[4] is true then do sprintf($html, $row[3], htmlentities( $row[1] ) ) but if $row[4] is false then echo "hello"? Joe
  10. I am trying to rework a page written by someone else and there is a function function generate_click_box($row) { $html = <<<HTML <div style="height:1px; font-size:1px; width:181px; margin:0 auto; background:#036; overflow:hidden;"></div> <div style="height:1px; font-size:1px; width:185px; margin:0 auto; background:#036; overflow:hidden;"></div> <div style="height:1px; font-size:1px; width:187px; margin:0 auto; background:#036; overflow:hidden;"></div> <div style="height:2px; font-size:2px; width:189px; margin:0 auto; background:#036; overflow:hidden;"></div> <div id="%1\$s_toggle" style="height:45px; width:191px; margin:0 auto; background:#036; color:#fff; cursor:pointer; font-size:12px; font-weight:bold; text-align:center; padding:0; margin:0;"><div style="padding:2px; vertical-align:middle;">%2\$s</div></div> <div style="height:2px; font-size:2px; width:189px; margin:0 auto; background:#036; overflow:hidden;"></div> <div style="height:1px; font-size:1px; width:187px; margin:0 auto; background:#036; overflow:hidden;"></div> <div style="height:1px; font-size:1px; width:185px; margin:0 auto; background:#036; overflow:hidden;"></div> <div style="height:1px; font-size:1px; width:181px; margin:0 auto; background:#036; overflow:hidden;"></div> HTML ; $html_disabled = <<<HTML <div style="height:1px; font-size:1px; width:181px; margin:0 auto; background: #cccccc; overflow:hidden;"></div> <div style="height:1px; font-size:1px; width:185px; margin:0 auto; background: #cccccc; overflow:hidden;"></div> <div style="height:1px; font-size:1px; width:187px; margin:0 auto; background: #cccccc; overflow:hidden;"></div> <div style="height:2px; font-size:2px; width:189px; margin:0 auto; background: #cccccc; overflow:hidden;"></div> <div style="height:45px; width:191px; margin:0 auto; background: #cccccc; color:#036; font-size:12px; font-weight:bold; text-align:center; padding:0; margin:0;"><div style="padding:2px; vertical-align:middle;"> <a href="http://factfinder.census.gov/servlet/EconSectorServlet?caller=dataset&sv_name=*&_SectorId=%1\$s&ds_name=EC0700A1&_lang=en&_ts=272288383987" target="_blank" alt="Click for %2\$s data">%2\$s<br />COMPLETED</a><br /></div></div> <div style="height:2px; font-size:2px; width:189px; margin:0 auto; background: #cccccc; overflow:hidden;"></div> <div style="height:1px; font-size:1px; width:187px; margin:0 auto; background: #cccccc; overflow:hidden;"></div> <div style="height:1px; font-size:1px; width:185px; margin:0 auto; background: #cccccc; overflow:hidden;"></div> <div style="height:1px; font-size:1px; width:181px; margin:0 auto; background: #cccccc; overflow:hidden;"></div> HTML ; return ($row[4]) ? sprintf($html, $row[3], htmlentities( $row[1] ) ) : sprintf($html_disabled, htmlentities( $row[5] ), htmlentities( $row[1] ) ); } Can someone translate (put into pseudo code) the following piece return ($row[4]) ? sprintf($html, $row[3], htmlentities( $row[1] ) ) : sprintf($html_disabled, htmlentities( $row[5] ), htmlentities( $row[1] ) ); Thanks! Joe
  11. Ok... that was dumb Here's a query of the database: mysql_connect($hostname, $user, $password); @mysql_select_db($database) or die( "Unable to select database"); $sql = "SELECT * FROM shirts WHERE sex='Unisex'"; //EDIT $result=mysql_query($sql); $num=mysql_num_rows($result); mysql_close(); $i=0; echo "<table border='1' width='75%'>"; while ($i < $num) { $item[$i] = mysql_result($result,$i,"item"); $title[$i] = mysql_result($result,$i,"title"); $url[$i] = mysql_result($result,$i,"url"); $imageUrl[$i] = mysql_result($result,$i,"imageUrl"); $alt[$i] = mysql_result($result,$i,"alt"); $sex[$i] = mysql_result($result,$i,"sex"); $shirtType[$i] = mysql_result($result,$i,"shirtType"); echo "<tr>"; echo "<td>".$i."</td>"; echo "<td>".$imageUrl[$i]."</td>"; echo "<td>".$item[$i]."</td>"; echo "<td>".$title[$i]."</td>"; echo "<td>".$shirtType[$i]."</td>"; echo "</tr>"; $i++; } ?> </table> <p>A total of <?php echo $num ?> rows were found.</p> and I do get 23 items http://funny.teamspirittees.com/testing/shirts/sweats/test.php vs the 19 on http://funny.teamspirittees.com/testing/shirts/sweats/funny_sweats_for_guys_and_girls.php. And here's what's even more curious to me. When I log into phpMyAdmin and query the database (SELECT * FROM shirts WHERE sex='Unisex'), I get all 23 sweatshirts. What could be going on? Thanks, Joe
  12. I have a t-shirt web site that I am redesigning. I have a pagination script and thought things were looking good until I found that I was not showing all of my records. 1. Here is a page on the site: http://funny.teamspirittees.com/testing/shirts/sweats/funny_sweats_for_guys_and_girls.php If you count the sweatshirts, you will find 19. However, there are 23 total. 2. Here is a page that lists and counts them: http://funny.teamspirittees.com/testing/shirts/sweats/test.php I don't know why I am missing 3 sweatshirts... it is happening on my other pages as well and I am hoping that fixing this page will help me fix the others. Here's the pagination code: <?php ################################# ### Begin Pagination Coding ##### ################################# $conn = mysql_connect($hostname, $user, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); // find out how many rows are in the table $sql = "SELECT COUNT(shirtType) FROM shirts WHERE sex='Unisex'"; // EDIT $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; $columns= 2; // number of shirts to show per page $rowsperpage = 7; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db $sql = "SELECT * FROM shirts WHERE sex='Unisex' LIMIT $offset, $rowsperpage"; //EDIT $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); echo "<div class='shirts'>"; $row = mysql_fetch_array($result) or die(mysql_error()); // mysql_fetch_array() returns both an assocative array and a numerically indexed array -- // a combination of the mysql_fetch_row() and the mysql_fetch_assoc() functions // set some basic variables; $tr=0; $flag= 0; $i=0; // run through the all the arrays to break them into individual items that I can reference later while($row = mysql_fetch_object( $result )) { $item[$flag]= $row->item; $title[$flag]= $row->title; $url[$flag]= $row->url; $imageUrl[$flag]= $row->imageUrl; $alt[$flag]= $row->alt; $sex[$flag]= $row->sex; $shirtType[$flag]= $row->shirtType; $flag++; } // find out how many rows we need $totalRows=($flag/2); // begin the table -- 6 rows and 3 columns echo "<table border='0' cellpadding='5' align='center'>"; while ($tr <= $totalRows) { // create the rows $td=1; // each time through, re-start the column counter echo "<tr>"; while ($td <= 2) { //create the columns echo "<td>"; if ($item[$i] == NULL) { break; } echo "<a href='".$url[$i]."'><img src='".strtolower($imageUrl[$i])."' border='0' alt='".$alt[$i]."' /></a>"; // EDIT $i++; echo "</td>\n"; $td++; } echo "</tr>"; $tr++; } echo "</table>"; /****** build the pagination links ******/ // range of num links to show $range = 3; echo "<div align='center'>"; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo "<br /> <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if echo "</div>"; /****** end build pagination links ******/ echo "</div"; echo "</div>"; ############################# ### End Pagination Coding ### ############################# ?> and the code for the test.php page <?php $i = 0; $dir = opendir ("."); while (false !== ($file = readdir($dir))) { if (strpos($file, '.gif',1)||strpos($file, '.jpg',1) ) { echo $i.":<a href='".$file."'>$file</a><br />"; $i++; } } echo "<br /><br />".$i." total items"; ?> What am I missing? Please and thank you! Joe
  13. I am trying to display the contents of an array and having a problem. I am getting an array of states (and state abbreviations) from a form and throwing this into a SESSION array ($_SESSION['states'] = $_POST['states'] Later, I want to echo these choices back, without the state abbreviations. Let's say the customer gives me Maryland-MD, Virginia-VA and Delaware-DE. If I use foreach($_SESSION['states'] as $key=>$value) { $stateName = explode("-",$_SESSION['states']); echo $stateName[0].' <br />'; } echo "</blockquote>"; . I get Notice: Array to string conversion in /vs/webdev/docs/econ/notifyme/state_entry.php on line 469 Array Notice: Array to string conversion in /vs/webdev/docs/econ/notifyme/state_entry.php on line 469 Array What am I doing wrong? What should I do? Thanks, Joe
×
×
  • 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.