jesushax Posted July 7, 2008 Share Posted July 7, 2008 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'); ?> Quote Link to comment Share on other sites More sharing options...
trq Posted July 7, 2008 Share Posted July 7, 2008 the equivilent of an asp const in php define(). the equivlient of an asp mod in php % Quote Link to comment Share on other sites More sharing options...
jesushax Posted July 7, 2008 Author Share Posted July 7, 2008 thanks another problem now with whats the equivilent to an asp space? eg Response.Write Space(4) Thanks Quote Link to comment Share on other sites More sharing options...
trq Posted July 7, 2008 Share Posted July 7, 2008 There is no such function built into vbscript. Find where it is defined and you should find a hint about what it does. Quote Link to comment Share on other sites More sharing options...
jesushax Posted July 7, 2008 Author Share Posted July 7, 2008 are you sure? dreamweaver seems to see it as a function or vbscript of some sort? i can see it defined anywhere, i have no idea what it does either :S Quote Link to comment Share on other sites More sharing options...
trq Posted July 7, 2008 Share Posted July 7, 2008 Sorry, must have forgotten all about it. An equivelent in php would be. <?php function space($times) { $str = ""; return string_pad($str,$times," "); } ?> Quote Link to comment Share on other sites More sharing options...
jesushax Posted July 8, 2008 Author Share Posted July 8, 2008 thanks for your help so far I get Call to undefined function string_pad() using the above function Quote Link to comment Share on other sites More sharing options...
trq Posted July 8, 2008 Share Posted July 8, 2008 Sorry, should be str_pad(). Quote Link to comment Share on other sites More sharing options...
jesushax Posted July 8, 2008 Author Share Posted July 8, 2008 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 Quote Link to comment Share on other sites More sharing options...
trq Posted July 8, 2008 Share Posted July 8, 2008 You might want to post your actual code. Quote Link to comment Share on other sites More sharing options...
jesushax Posted July 8, 2008 Author Share Posted July 8, 2008 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'); ?> Quote Link to comment Share on other sites More sharing options...
jesushax Posted July 8, 2008 Author Share Posted July 8, 2008 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'); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.