Jump to content

help with php function


mast3rpyr0

Recommended Posts

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

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);
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.