mast3rpyr0 Posted November 8, 2007 Share Posted November 8, 2007 hi, i have this function to switch between two different strings for each variable it uses so that it creates a properly formatted table (ya i know who uses tables...). the function is called but it doesnt change anything, is there somethign wrong? <?php $start = '<tr><td>'; $end = '</td>'; function doSwitch($a, $b) { if ($a == '<tr><td>') $start = '<td>'; else if ($a == '<td>') $start = '<tr><td>'; if ($b == '</td>') $end = '</td></tr>'; else if ($b == '</td>') $end = '</td>'; } if(!isset($_GET['img'])) { $folder=dir("imgpath/."); $path = "imgpath"; echo '<table border="1">'; while($folderEntry=$folder->read()){ if ($folderEntry !="." & $folderEntry !=".." & $folderEntry !="folder.php" & $folderEntry !="Thumbs.db") { echo $start; echo '<a href="?p=gallery&img=' . $folderEntry . '">'; echo '<img src="' . $path . $folderEntry . '" alt="image" />'; echo $end; doSwitch($start, $end); } } if($end == '</td>') echo '</table>'; else echo '</tr></table>'; $folder->close(); } else{ echo 'You have selected image ' . $_GET['img']; } ?> thanks Link to comment https://forums.phpfreaks.com/topic/76506-help-with-php-function/ Share on other sites More sharing options...
MadTechie Posted November 8, 2007 Share Posted November 8, 2007 try using pointers doSwitch(&$start, &$end); Link to comment https://forums.phpfreaks.com/topic/76506-help-with-php-function/#findComment-387503 Share on other sites More sharing options...
mast3rpyr0 Posted November 8, 2007 Author Share Posted November 8, 2007 no that still didnt seem to do it. i set it up to work with a few images and they should have 2 to a row and then go down. http://pyroaudio.cpcdesigns.com/files/public_html/ Link to comment https://forums.phpfreaks.com/topic/76506-help-with-php-function/#findComment-387768 Share on other sites More sharing options...
MadTechie Posted November 10, 2007 Share Posted November 10, 2007 untested, but should work <?php $start = '<tr><td>'; $end = '</td>'; if(!isset($_GET['img'])) { $folder=dir("imgpath/."); $path = "imgpath"; echo '<table border="1">'; while($folderEntry=$folder->read()) { if ($folderEntry !="." & $folderEntry !=".." & $folderEntry !="folder.php" & $folderEntry !="Thumbs.db") { echo $start; echo '<a href="?p=gallery&img=' . $folderEntry . '">'; echo '<img src="' . $path . $folderEntry . '" alt="image" />'; echo $end; list($start, $end) = doSwitch($start, $end); } } if($end == '</td>') { echo '</table>'; }else{ echo '</tr></table>'; } $folder->close(); }else{ echo 'You have selected image ' . $_GET['img']; } function doSwitchA($a, $b) { if($a == '<tr><td>') { $start = '<td>'; }elseif($a == '<td>'){ $start = '<tr><td>'; } if($b == '</td>') { $end = '</td></tr>'; }elseif ($b == '</td>'){ $end = '</td>'; } return array($start, $end); } ?> Link to comment https://forums.phpfreaks.com/topic/76506-help-with-php-function/#findComment-388265 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.