jcbones
Staff Alumni-
Posts
2,653 -
Joined
-
Last visited
-
Days Won
8
Everything posted by jcbones
-
Yeah, I added a function exists because of my benchmark class, and how it works. That is why I ran the third test with just the string.
-
You would think, but here is some benchmark'ing
-
You will need to join the items table to the users table to limit the query based on the rank. example SELECT i.* FROM items AS i JOIN users AS u ON i.user_id = u.id WHERE u.rank = 'staff'; MySQL JOIN Syntax
-
Here is one that should work, although, it only takes the 10 digit format without any other characters (or it will break). <?php $pattern = '~([0-9]{3})([0-9]{3})([0-9]{4})~'; $replacement = '$1-$2-$3'; $number = 1112223333; echo preg_replace($pattern,$replacement,$number); //add parenthesis around the area code. $replacement = '($1)-$2-$3'; echo preg_replace($pattern,$replacement,$number); ?>
-
Problem with creating an array from fetched data
jcbones replied to Schaarschmidt's topic in PHP Coding Help
No problem, we all start somewhere. Cheers, Happy Coding, JC -
//all lines but the last 8 $firstLines = array_slice($lines, 0, count($lines)-9); //last 8 lines $lastLines = array_slice($lines,count($lines)-9);
-
Problem with creating an array from fetched data
jcbones replied to Schaarschmidt's topic in PHP Coding Help
How do you know it isn't working? Do you have error_reporting and display errors on full in your php.ini? It should be for development. Of course you can set these at runtime with. error_reporting(-1); ini_set('display_errors',1); Now on to your particular problem. Does the book use mysqli or just mysql? I cannot tell with your snippet. I am assuming that you are using mysqli as you didn't define the fetch properties for PDO (they both have a fetch() method). So, did you bind the results prior to calling the fetch() method? It would be easier to help you if you posted the entire script you are working with. Minus any passwords or usernames of course. -
Before adding data to the database, it should be trim'd and then checked for being empty. This way you don't have a bunch of spaces like you are describing.
-
Try these changes, I commented up what I changed and why. <?PHP include ('php only scripts/db.php'); error_reporting(E_ALL); ?> <!DOCTYPE html> <head> <title>Removals | Removalspace.com</title> <style type="text/css"> <!-- body { background-image: url(styles/downloaded%20styles/todo/todo/images/bg.png); } --> </style> <link href="styles/downloaded styles/todo/todo/css/style.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" type="text/css" href="styles/downloaded styles/todo/todo/css/style9.css" /> <link rel="stylesheet" type="text/css" href="styles/downloaded styles/todo/todo/css/demo.css" /> <link href='http://fonts.googleapis.com/css?family=Terminal+Dosis' rel='stylesheet' type='text/css' /> <style type="text/css"> <!-- .Stile1 {color: #333333} .aa { font-size: 13px; } #container header nav #logo p .cursive { font-size: 9px; } #apDiv1 { position:absolute; width:466px; height:24px; z-index:1; left: 585px; top: 191px; } --> </style> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-31656176-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> <style type="text/css"> <!-- .pagNumActive { color: #000; border:#060 1px solid; background-color: #D2FFD2; padding-left:3px; padding-right:3px; } .paginationNumbers a:link { color: #000; text-decoration: none; border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px; } .paginationNumbers a:visited { color: #000; text-decoration: none; border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px; } .paginationNumbers a:hover { color: #000; text-decoration: none; border:#060 1px solid; background-color: #D2FFD2; padding-left:3px; padding-right:3px; } .paginationNumbers a:active { color: #000; text-decoration: none; border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px; } #apDiv2 { position:absolute; width:587px; height:40px; z-index:1; left: 261px; top: 541px; } --> </style> </head> <body> <!--start container --> <div id="container"> <header> <nav> <div id="apDiv1"><span class="cursive">Upagrade Now For Your Logo Here!</span></div> <div id="logo"> <p><a href="index.php"><img src="images/header2.png" alt="Logo here" width="219" height="161" /></a></p> <p><span class="cursive">Company Logo's/Upgraded UK Listings Shown Below (enter your postcode for your area)</span></p> <p> </p> <p>click <a href="register00.php">here</a> to add your company</p> </div> <div id="search-top"><img src="styles/downloaded styles/todo/todo/images/quote-right.png" alt="images" /><span class="cursive">Enter your postcode here</span><img src="styles/downloaded styles/todo/todo/images/quote-left.png" alt="images" /> <form method="post" action="search.php"> <input type="text" name="strSearch" onFocus="if(this.value=='Search Area')this.value='';" onBlur="if(this.value=='')this.value='Search Area';" value="Search Area" id="search-field"/> <input type="submit" value="" id="search-btn"/> </form> </div> <div id="nav_social"><a href="http://www.facebook.com/pages/Removalspace/181434181939226"><img src="styles/downloaded styles/todo/todo/images/facebook_32.png" alt="Become a fan" width="32" height="32" /></a><a href="#"><img src="styles/downloaded styles/todo/todo/images/twitter_32.png" alt="Follows on Twitter" /></a><a href="id=183427956&trk=tab_pro"><img src="styles/downloaded styles/todo/todo/images/linkedin_32.png" alt="Linked in" /></a><a href="contact.php"><img src="styles/downloaded styles/todo/todo/images/email_32.png" alt="Contact" width="32" height="32" /></a><!-- Place this tag where you want the +1 button to render --> <g:plusone size="small" annotation="inline"></g:plusone> <!-- Place this render call where appropriate --> <script type="text/javascript"> (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/plusone.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); </script></div> </nav> </header> <p><figure><a href="removals.php">Search Removals</a></figure> |</p> <p><figure><a href="storage.php">Search Storage</a></figure> |</p> <p><figure><a href="register00.php">Add Listing</a></figure> |</p> <p><figure><a href="about.php">About</a></figure> |</p> <p><figure><a href="contact.php">Contact</a></figure> |</p> <p><figure><a href="login00.php">Login</a></figure></p> <div class="content"> <!--star main --> <main> <?php /************************************CHANGES IN THIS BLOCK ********************************************************/ $nr = 0; //default for number of rows. $query = "SELECT COUNT(*) FROM companies WHERE what_services IN('R','B') ORDER BY approved DESC, company_name ASC"; //changed to a count query. if ($result = mysql_query($query)) { //added brackets, as the fetch row resided outside of the if clause, making no sense. $what_services = "R"; //No idea what this is, as it isn't used anywhere, accept to reference itself on line 215, and in an empty switch on line 220. $row = mysql_fetch_row($result); //changed to a fetch row (faster). $nr = $row[0]; //changed $nr to get the number of rows. } if(isset($_GET['pn'])){ $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); //you could simply typecast by using (int)$_GET['pn']; but isn't a problem the way you are doing. }else{ $pn = 1; } $itemsPerPage = 10; //$nr = ('nr'); //I have no Idea why you are passing a string to $nr, as you are using it in the ceil function which requires NUMERICAL data. $lastPage = ceil($nr / $itemsPerPage); /********************************CHANGES IN THE BLOCK ABOVE************************************************/ if($pn < 1){ $pn = 1; }else if($pn > $lastPage){ $pn = $lastPage; } // This creates the numbers to click in between the next and back buttons $centerPages = ""; // Initialize this variable $sub1 = $pn - 1; $sub2 = $pn - 2; $add1 = $pn + 1; $add2 = $pn + 2; if ($pn == 1) { $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; } else if ($pn == $lastPage) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; } else if ($pn > 2 && $pn < ($lastPage - 1)) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '">' . $sub2 . '</a> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '">' . $add2 . '</a> '; } else if ($pn > 1 && $pn < $lastPage) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; } // This line sets the "LIMIT" range... the 2 values we place to choose a range of rows from database in our query $limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage; // Now we are going to run the same query as above but this time add $limit onto the end of the SQL syntax // $sql2 is what we will use to fuel our while loop statement below $sql2 = mysql_query("SELECT * FROM companies WHERE what_services IN('R','B') ORDER BY approved DESC, company_name ASC $limit"); //////////////////////////////// END Adam's Pagination Logic /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////// Adam's Pagination Display Setup /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $paginationDisplay = ""; // Initialize the pagination output variable // This code runs only if the last page variable is not equal to 1, if it is only 1 page we require no paginated links to display if ($lastPage != "1"){ // This shows the user what page they are on, and the total number of pages $paginationDisplay .= 'Page <strong>' . $pn . '</strong> of ' . $lastPage. '<img src="images/clearImage.gif" width="48" height="1" alt="Spacer" />'; // If we are not on page 1 we can place the Back button if ($pn != 1) { $previous = $pn - 1; $paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '"> Back</a> '; } // Lay in the clickable numbers display here between the Back and Next links $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>'; // If we are not on the very last page we can place the Next button if ($pn != $lastPage) { $nextPage = $pn + 1; $paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '"> Next</a> '; } } ///////////////////////////////////// END Adam's Pagination Display Setup /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $sql2 = "SELECT * FROM companies WHERE what_services IN('R','B') ORDER BY approved DESC, company_name ASC $limit"; if( $result = mysql_query($query)); while ( $row = mysql_fetch_array($result)) { $approved = $row['approved']; $what_services = $what_services; SWITCH ($approved) { case 0: break; case 1: ?> <div class="abox"> <figure> <fcapion> <p> </p> <p><?PHP echo $row['company_name']; ?></p> <p> </p> </figure> </div> <div class="abox"> <figure> <fcapion> </fcaption> <?PHP echo $row['street1'] . "<br>" . $row['street2'] . "<br>" . $row['city'] . "," . $row['postcode'] . "<br>phone: " . $row['phone'] ?> </figure> </div> <div class="abox"> <figure> <fcapion> <p> </p> <h1><?PHP echo $row['company_name']; ?></h1> <p> </p> </figure> </div> <p> <?PHP break; case 2: ?> </p> <div class="abox"> <figure> <fcapion> <p> </p> <p><?PHP echo $row['company_name']; ?> </p> <p> </p> </figure> </div> <div class="abox"> <figure> <fcapion> </fcaption> <?PHP echo $row['street1'] . "<br>" . $row['street2'] . "<br>" . $row['city'] . "," . $row['postcode'] . "<br>phone: " . $row['phone'] ?> </figure> </div> <div class="abox"> <figure> <fcapion> <p> </p> <h1><img src="images/thumbs/<?PHP echo $row['upload']; ?>" alt="logo"/></h1> <p> </p> </figure> </div> <?PHP break; case 3: ?> <div class="abox"> <figure> <fcapion> <p> </p> <p><a href="view00.php?id=<?PHP echo $row['id']; ?>"><?PHP echo $row['company_name']; ?></a></p> <p> </p> </figure> </div> <div class="abox"> <figure> <fcapion> <p> </p> <p><a href="view00.php?id=<?PHP echo $row['id']; ?>"> <?PHP echo $row['street1'] . "<br>" . $row['street2'] . "<br>" . $row['city'] . "," . $row['postcode'] . "<br>phone: " . $row['phone'] . "<br>mobile/other: " . $row['phone'] ?> </a></p> <p> </p> </figure> </div> <div class="abox"> <figure> <fcapion> <h1>click logo to read more...<a href="view00.php?id=<?PHP echo $row['id']; ?>"><img src="images/thumbs/<?PHP echo $row['upload']; ?>" alt="logo"/></a></h1> </figure> </div> <p> </p> <p> <?PHP break; } } ?> </p> </main> <!--end main --> <!--start middle --> </div> <!--end middle --> <!--start footer --> <footer> <div style="margin-left 58px, margin-right 58px, padding 6px border #999, 1px solid"><?php echo $paginationDisplay;?></div> <div id="footer"> <div id="footerleft"> <h2>removalspace</h2> <ul> <li><a href="contact.php">Contact</a></li> <li><a href="about.php">About Us</a></li> <li><a href="other-info.php">Other</a></li> <li></li> </ul> </div> <div id="footermiddle"> <h2>User Comments</h2> <ul> <li><a href="#">Read Reviews</a></li> <li><a href="contact.php">Leave A Comment</a></li> <li><a href="#">Read Blogs</a></li> <li></li> </ul> </div> <div id="footerright"> <h2>our mission</h2> <ul> <li><a href="about.php">Who Are We?</a></li> <li><a href="about.php">What We Do</a></li> <li><a href="about.php">Our Mission</a></li> <li></li> </ul> </div> <details> <summary> <p><a href="http://www.imediacreatives.it" target="_blank">Imediacreatives.it</a><a href="http://freehtml5templates.com">Designers</a> Copyright © removalspace.com -2012.</p></summary><p></p> </details> </div> </footer> <!--end footer --> </div> <!--end container --> </body> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> </html>
-
Post the exact code (in full) that you have now. This thread needs clarification on what we are working with currently.
-
Sorry, didn't know there was more to the string. remove the ; (semicolon), and add a . ' (period, single quote).
-
It works for that too. But, I was trying to lead you, not feed you. while($info = mysql_fetch_array( $data )) echo '<table width="550" border="0" align="center" cellpadding="10" cellspacing="0"> <tr> <td width="175" align="right" style="background:#C8E9EB; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC;">Name:</td> <td width="335" align="left" style="background:#C5D7EF; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC; border-right: solid 1px #CCCCCC;">'.$info['name'].'</td> </tr>' . (!empty($info['email']) ? '<tr> <td align="right" style="background:#C8E9EB; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC;">Email:</td> <td align="left" style="background:#C5D7EF; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC; border-right: solid 1px #CCCCCC;">' . $info['email'] . '</td> </tr>' : NULL);
-
Nor the fact that the Javascript was written wrong, as there was no id for the element they were trying to get.
-
A little code I can't migrate from PHP 4 to PHP 5
jcbones replied to radio_fan's topic in PHP Coding Help
You need to look at your $settings object, and de-bug it. I think it is empty, and causing all of these errors (Just like PFM stated in his first post). -
What Pik is telling you, but you don't seem to understand, is: <form id="form1" name="form1" method="get" action="results.php"> //$detnum in this case is = 78.. <label> </label> <table border="0"> <tr> <td> <div align="center"><br /> <input name="Details" type="hidden" value="<?php echo $detnum ;?>" /> <input name="findthis" type="text" id="findthis" size="15" /> <input type="submit" name="submit" id="submit" value="Search" /> </div></td> </tr> </table> </form>
-
2 of the same values in a select list would confuse the user. str_replace would work well here.
-
Try: while($info = mysql_fetch_array( $data )) echo '<table width="550" border="0" align="center" cellpadding="10" cellspacing="0"> <tr> <td width="175" align="right" style="background:#C8E9EB; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC;">Name:</td> <td width="335" align="left" style="background:#C5D7EF; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC; border-right: solid 1px #CCCCCC;">'.$info['name'].'</td> </tr> <tr> <td align="right" style="background:#C8E9EB; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC;">Email:</td> <td align="left" style="background:#C5D7EF; border-top: solid 1px #CCCCCC; border-left: solid 1px #CCCCCC; border-right: solid 1px #CCCCCC;">' . (!empty($info['email']) ? $info['email'] : 'Not Available') . '</td> </tr>
-
Form submit value not being sent please check
jcbones replied to $php_mysql$'s topic in PHP Coding Help
This is marked as solved? Not sure that it is. Have you echo'd the $sql variable to see if it contains the data you want? echo $sql; Have you made sure there is not a problem on the database's end, by catching any database errors? $result = mysql_query($sql) or exit($sql . ' has an error <br />' . mysql_error()); Are you getting any notices about undefined indexes? if so, paste them. if not, Do you have error reporting on, and display errors? //runtime setting error_reporting(-1); ini_set('display_errors',1); -
ternary operator. We have all been there with the long hours. So, I understand completely.
-
Form submit value not being sent please check
jcbones replied to $php_mysql$'s topic in PHP Coding Help
Put this code at the top of the page, and copy/paste the results: echo '<pre>' . print_r($_GET,true) . print_r($_POST,true) . '</pre>'; -
<input type="checkbox" name="call" value="Yes" <?php echo (isset($_POST['call'])) ? 'checked="checked"' : NULL; ?> /> Do you wish to receive a call from us? checkboxes will only be set IF it is checked, so you can use isset. If it is set, then it should be checked.
-
Form submit value not being sent please check
jcbones replied to $php_mysql$'s topic in PHP Coding Help
There lies your problem. -
What exactly is involved with using Authorize.net?
jcbones replied to Zane's topic in Application Design
http://stackoverflow.com/questions/6130436/is-posted-information-from-non-ssl-to-an-ssl-secure So, it's secure, but the form page isn't SSL, and this might scare the buyer. If you loop closely at the picture, they are telling you that your form must be HTTPS. -
A little code I can't migrate from PHP 4 to PHP 5
jcbones replied to radio_fan's topic in PHP Coding Help
So, $catloop is empty. You need to find out why $this->$catloop is empty. You could try removing $this->, as $catloop is not in the object scope. It is being defined from your explode. Even if it were in object scope, it should be $this->catloop. -
A little code I can't migrate from PHP 4 to PHP 5
jcbones replied to radio_fan's topic in PHP Coding Help
Why do you think this code is unsuitable for PHP5?