Dev Shed Forums - PHP Development http://forums.devshed.com/ PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm. en Tue, 11 Dec 2018 04:20:10 GMT vBulletin 60 http://forums.devshed.com/images/misc/rss.png Dev Shed Forums - PHP Development http://forums.devshed.com/ Graceful Exit after MySQL error http://forums.devshed.com/php-development/981212-graceful-exit-mysql-error-new-post.html Tue, 27 Nov 2018 14:37:35 GMT Hi:

Is there a way to display a polite error page when MySQL encounters an error. For example, if a "$_GET" variable gets corrupted, a MySQL command may fail and the user sees just a blank white screen that says "You have an error in your SQL syntax..."

Obviously, it would be best if there never was a MySQL error in the first place, but sometimes it happens.

Is there a way to have the page diver to a nicely formatted "Oops, we encountered an error..." page?

Thanks ]]>
PHP Development SeanF http://forums.devshed.com/php-development-5/graceful-exit-mysql-error-981212.html
Drop down options issue http://forums.devshed.com/php-development/981195-drop-options-issue-new-post.html Wed, 21 Nov 2018 06:58:52 GMT I feel like I am close with this one. Very simply I have a drop down where the items are drawn from a table. We could have an item selected by checking another table. However, if the user has selected an item and hit submit that will either override the existing value or if an existing value doesnt exist: create a new record. So my problem from the code below is that while when selecting or... I feel like I am close with this one. Very simply I have a drop down where the items are drawn from a table. We could have an item selected by checking another table. However, if the user has selected an item and hit submit that will either override the existing value or if an existing value doesnt exist: create a new record.

So my problem from the code below is that while when selecting or drawing the existing value the outcome is expected, when the user hits submit, the page returns with the selected option not displaying in the drop down.

PHP Code:


//get the records for the drop down
    $uprecord_status = 'active';
    $up_rec_select = $DB_con2->prepare('select up_table_names_id, recordname, record_label from setup_user_preference_table_names where status = :status');
    $up_rec_select->execute(array(":status"=>$uprecord_status));
    $up_rec_select_result = $up_rec_select->fetchAll(); 
?>


  <select name="up_recordname_select">
    <option>Select</option>
    <?php 
    
//if the user has submited the form then display the selected value
           
if (isset($_POST['display']) && isset($_POST['up_recordname_select'])){
           
$uprecordname_selected $_POST['up_recordname_select'];
          echo 
"<option value='$uprecordname_selected' selected:selected>$record_label</option>";           
       }    
        
//for each value form the database display them, if one is equal to the record stored in the database then show that as selected               
      
foreach ($up_rec_select_result as $up_row) { 
      
$uprecordname_original $up_row['recordname'];
      
$up_table_names_id_original $up_row['up_table_names_id'];
      
$record_label $up_row['record_label'];

      if (
$uprecordname_selected ==  $uprecordname_original){
          echo 
"<option value='$uprecordname_selected' selected:selected>$record_label</option>";
      }
     
//show the values in the drop down
        
echo  "<option value='$uprecordname_original'>$record_label</option>";
      }
    


?>
    </select>
    </div>

How can I organize this better to meet my requirement?

Thanks,

G ]]>
PHP Development genista http://forums.devshed.com/php-development-5/drop-options-issue-981195.html
Grouping Duplicate Results http://forums.devshed.com/php-development/981183-duplicate-results-new-post.html Wed, 14 Nov 2018 08:40:45 GMT I need to group duplicate results so that the output is: A, B, C etc. The code Iím using that the moment is giving me: AA, BBB, CC etc. My database query returns the last ĎDistinctí name, and I take the first letter of that and run it through my code so I understand why Iím getting duplicates because there are several Anthony, Bert, Connor, etc. in the Ďlastí name but when I run it... I need to group duplicate results so that the output is:

A, B, C etc.

The code Iím using that the moment is giving me:

AA, BBB, CC etc.

My database query returns the last ĎDistinctí name, and I take the first letter of that and run it through my code so I understand why Iím getting duplicates because there are several Anthony, Bert, Connor, etc. in the Ďlastí name but when I run it through my code below I canít seem to find a way to remove the duplicates.

I have tried multiple things such as array_unique but nothing seems to work as I keep getting the same result. Iíd appreciate any help that I can get as Iím not the most experienced with PHP.

Thanks

[CODE]SELECT DISTINCT (last_name) FROM books GROUP BY last_name[CODE/]
[php]
<?PHP
do {

$str = $row_GetPeople['last_name'];

$first_letter = $str[0];

echo '<a href="results.php?id='.$first_letter.' ">'.$first_letter .'<a/><br>';

} while ($row_GetPeople = mysql_fetch_assoc($GetPeople)); ?>[php/] ]]>
PHP Development Addos http://forums.devshed.com/php-development-5/duplicate-results-981183.html
TCPDF Documentation? http://forums.devshed.com/php-development/981180-tcpdf-documentation-new-post.html Tue, 13 Nov 2018 16:10:24 GMT Hi:

I was looking for an easy to use PDF document generator that plays nicely with PHP.

I found TCPDF which seems to work well, once you can figure out the syntax. But... that's a real problem...

Typically, the documentation looks like this:

Code:

// MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0)

// set some text for example
$txt = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';

// Multicell test
$pdf->MultiCell(55, 5, '[LEFT] '.$txt, 1, 'L', 1, 0, '', '', true);
$pdf->MultiCell(55, 5, '[RIGHT] '.$txt, 1, 'R', 0, 1, '', '', true);
$pdf->MultiCell(55, 5, '[CENTER] '.$txt, 1, 'C', 0, 0, '', '', true);
$pdf->MultiCell(55, 5, '[JUSTIFY] '.$txt."\n", 1, 'J', 1, 2, '' ,'', true);
$pdf->MultiCell(55, 5, '[DEFAULT] '.$txt, 1, '', 0, 1, '', '', true);

And your best bet is really just changing values to see what happens... But that's incredibly time consuming, frustrating and confusing.

Does anyone know if any proper documentation exists for this library? The web site is:
https://tcpdf.org
But the docs are terrible and the examples require too much trial and error.

Otherwise, what PDF libraries have people used that are reasonably intuitive and rely on native PHP?

Thanks ]]>
PHP Development SeanF http://forums.devshed.com/php-development-5/tcpdf-documentation-981180.html