Jump to content

Complex Code Conversion, few errors i need help with


jesushax

Recommended Posts

HI this code ive converted from asp to php

 

i didnt code this but need the same thing done in php this is what i have now

 

the only things i can see not working are...

the equivilent of an asp const in php

the equivlient of an asp mod in php

 

Thanks

 

<?php include($_SERVER['DOCUMENT_ROOT'] . '/new/includes/header.php'); ?>
<p>Browse & print company details by clicking a company name below</p><a name="top">
<? 
//dim $SQL, $row;

$SQL = mysql_query("SELECT * FROM tblData ORDER BY CompanyName ASC") or die (mysql_error());

$strLastLetter = "";
$rCount = 0;
Const $NUM_OF_COLUMNS = 3;


for ($x=65; $x<=90; $x++) {
echo '<a href="#'.chr($x).'">'.chr($x)."</a>";
if ($x < 90) {
	echo " | ";
}
}


echo '<table width="100%">'."\n";
while ($row = mysql_fetch_array($SQL)) {
$strCurLetter = left($row["CompanyName"], 1);
if ($strCurLetter!=$strLastLetter) {
	if ($rCount>0) {
		for ($x=$rCount; $x<=$NUM_OF_COLUMNS-1; $x++) {
			echo Space(4)."<td> </td>"."\n";
		}
		echo Space(2)."</tr>"."\n";
	}
	$rCount = 0;

	echo Space(2).'<tr><td style="height:25px;" colspan="'.$NUM_OF_COLUMNS.'"><br /><b>'.$strCurLetter.'</b><a name="'.strtoupper($strCurLetter).'"></a> <a href="#top"><small>Back To Top</small></a><hr /></td></tr>'."\n";
	echo Space(2).'<tr style="height:20px;">'."\n";
}

if (($rCount > 0) && ($rCount Mod $NUM_OF_COLUMNS == 0)) {
	echo Space(2)."</tr>"."\n";
	echo Space(2).'<tr style="height:20px;">'."\n";
}

echo Space(4).'<td><a class="flood" href="record.asp?ID='.$row["ID"].'">'.$row["CompanyName"]."</a></td>"."\n";

$strLastLetter = $strCurLetter;
$rCount = $rCount + 1;
}
if ($rCount>0) {
for ($x=$rCount; $x<=$NUM_OF_COLUMNS-1; $x++) {
	echo Space(4)."<td> </td>"."\n";
}
echo Space(2)."</tr>"."\n";
}
echo "</table>"."\n";
?>
<?php include($_SERVER['DOCUMENT_ROOT'] . '/new/includes/footer.php'); ?>

 

heres the orginal asp

 

<!--#include virtual='/includes/header.asp'-->
<!--#include virtual='/includes/Tdbconnection.inc'-->
<p>Browse & print company details by clicking a company name below</p><a name=""top"">
<% 
Dim SQL, row

SQL = "Select * From tblData Order By CompanyName ASC"
Set row = Server.CreateObject("ADODB.recordset")

row.Open SQL, adoConT

Dim strLastLetter, strCurLetter, x
Dim rCount


strLastLetter = ""
rCount = 0
Const NUM_OF_COLUMNS = 3


For x = 65 To 90
response.write "<a href=""#" & Chr(x) & """>" & Chr(x) & "</a>"
If x < 90 Then
	response.write " | "
End If
Next


response.write "<table width=""580"">" & vbCrLf
Do Until row.EOF
strCurLetter = Left(row("CompanyName"), 1)
If strCurLetter<>strLastLetter Then
	If rCount>0 Then
		For x=rCount To NUM_OF_COLUMNS-1
			Response.Write Space(4) & "<td> </td>" & vbCrLf
		Next
		Response.Write Space(2) & "</tr>" & vbCrLf
	End If
	rCount = 0

	Response.Write Space(2) & "<tr><td style=""height:25px;"" colspan=""" & NUM_OF_COLUMNS & """><br /><b>" & strCurLetter  & "</b><a name=""" & UCase(strCurLetter) & """></a> <a href=""#top""><small>Back To Top</small></a><hr /></td></tr>" & vbCrLf
	Response.Write Space(2) & "<tr style=""height:20px;"">" & vbCrLf
End If

If (rCount > 0) And (rCount Mod NUM_OF_COLUMNS = 0) Then
	Response.Write Space(2) & "</tr>" & vbCrLf
	Response.Write Space(2) & "<tr style=""height:20px;"">" & vbCrLf
End If

Response.Write Space(4) & "<td><a class=""flood"" href=""record.asp?ID=" & row("ID") & """>" & row("CompanyName") & "</a></td>" & vbCrLf

strLastLetter = strCurLetter
rCount = rCount + 1
row.MoveNext
Loop
If rCount>0 Then
For x=rCount To NUM_OF_COLUMNS-1
	Response.Write Space(4) & "<td> </td>" & vbCrLf
Next
Response.Write Space(2) & "</tr>" & vbCrLf
End If
Response.Write "</table>" & vbCrLf
row.Close
%>
<?php include($_SERVER['DOCUMENT_ROOT'] . '/new/includes/footer.php'); ?>

thanks the code works now, but definitley not as expected lol

 

the code now prints a name in bold then a name under it

 

its suppsoed to do this

 

A

---------------------------------------------------------

Abacus | Advert | Ages | etc

 

B

---------------------------------------------------------

Bill | Berty | Bob

 

with a anchor list at the top

 

what it does at the moment is

 

Abacus

---------------------------------------------------------

Abacus

 

Advert

---------------------------------------------------------

Advert

 

would you know how to code such code or help me out with whati already have?

 

Thankyou

ok heres where im at...

 

so what i need to figure out now is how to put another <tr> in with a letter eg <tr><a href="#A">A</a></tr> for everytime the records end a current letter

 

<?php include($_SERVER['DOCUMENT_ROOT'] . '/new/includes/header.php'); ?>
<p>Browse & print company details by clicking a company name below</p><a name="top">
<?php 
$res = mysql_query("SELECT `CompanyName` FROM `tblDirectory` ORDER BY `CompanyName` ASC") or die(mysql_error());

$col = 1;
$colMax = 3;
echo '<p>'."\n";
for ($x=65; $x<=90; $x++) {
echo '<a href="#'.chr($x).'">'.chr($x)."</a>";
if ($x < 90) {
	echo " | ";
}
}
echo '</p>'."\n";
echo "<table border=0>\n";

while($row=mysql_fetch_array($res))  {

 if ($col == 1)
	echo " <tr>\n";

echo '<td><a class="smallG" href="record.php?ID='.$row["CompanyName"].'">'.$row["CompanyName"].'</a></td>'."\n";
if ($col == $colMax) {
	echo " </tr>\n";
	$col = 1;
} else
	$col++;
}
while ($col <= $colMax && $col !== 1) {
echo "  <td> </td>\n";
$col++;

if ($col > $colMax)
	echo " </tr>\n";	
}
echo "</table>\n";
?>
<?php include($_SERVER['DOCUMENT_ROOT'] . '/new/includes/footer.php'); ?>

and this is the oringal code that was converted with the error as above...

 

<?php include($_SERVER['DOCUMENT_ROOT'] . '/new/includes/header.php'); ?>
<p>Browse & print company details by clicking a company name below</p><a name="top">
<? 
function Space($times) {
    $str = "";
    return str_pad($str,$times," ");
}

$SQL = mysql_query("SELECT * FROM tblDirectory ORDER BY CompanyName ASC") or die (mysql_error());

$strLastLetter = "";
$rCount = 0;
define($NUM_OF_COLUMNS,3);


for ($x=65; $x<=90; $x++) {
echo '<a href="#'.chr($x).'">'.chr($x)."</a>";
if ($x < 90) {
	echo " | ";
}
}


echo '<table width="100%">'."\n";
while ($row = mysql_fetch_array($SQL)) {
$strCurLetter = trim($row["CompanyName"], 1);
if ($strCurLetter!=$strLastLetter) {
	if ($rCount>0) {
		for ($x=$rCount; $x<=$NUM_OF_COLUMNS-1; $x++) {
			echo Space(4)."<td> </td>"."\n";
		}
		echo Space(2)."</tr>"."\n";
	}
	$rCount = 0;

	echo Space(2).'<tr><td style="height:25px;" colspan="'.$NUM_OF_COLUMNS.'"><br /><b>'.$strCurLetter.'</b><a name="'.strtoupper($strCurLetter).'"></a> <a href="#top"><small>Back To Top</small></a><hr /></td></tr>'."\n";
	echo Space(2).'<tr style="height:20px;">'."\n";
}

if (($rCount > 0) && ($rCount % $NUM_OF_COLUMNS == 0)) {
	echo Space(2)."</tr>"."\n";
	echo Space(2).'<tr style="height:20px;">'."\n";
}

echo Space(4).'<td><a class="flood" href="record.asp?ID='.$row["ID"].'">'.$row["CompanyName"]."</a></td>"."\n";

$strLastLetter = $strCurLetter;
$rCount = $rCount + 1;
}
if ($rCount>0) {
for ($x=$rCount; $x<=$NUM_OF_COLUMNS-1; $x++) {
	echo Space(4)."<td> </td>"."\n";
}
echo Space(2)."</tr>"."\n";
}
echo "</table>"."\n";
?>
<?php include($_SERVER['DOCUMENT_ROOT'] . '/new/includes/footer.php'); ?>

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.