Patrick3002 Posted March 8, 2007 Share Posted March 8, 2007 My script will not get the info from the db, i have no idea why... Heres the code: <?php /******************************************************** ****-------------------------------------------------**** ****---- Get Services Script Starts Here ------------**** ****-------------------------------------------------**** ****---------Copyright ©2007 Patrick Smith-----------**** ********************************************************/ $host="localhost"; $dbuser="root"; $dbpass="pass"; $db="php_01"; mysql_connect($host,$dbuser,$dbpass); @mysql_select_db($db) or die("Cant connect to db"); $sTable="jos_services"; if (!$selorder || !$seldisplay) { $selorder="sname ASC"; $seldisplay="10"; } else { $getserv = "SELECT `date`, `sname`, `author`, `views` FROM $sTable ORDER BY $selorder LIMIT $seldisplay"; $servResult=mysql_query($getserv); $resNum=mysql_num_rows($servResult); $sI=0; $sCount=1; $x=0; while ($sI < $resNum) { $servDate=mysql_result($servResult,$sI,"date"); $servName=mysql_result($servResult,$sI,"sname"); $servAuthor=mysql_result($servResult,$sI,"author"); $servViews=mysql_result($servResult,$sI,"views"); if ($x=='0') { $color="#FFFFFF"; $x=1; } else { $color="#CCCCCC"; $x=0; } echo "$servDate"; echo "$servName"; echo "$servAuthor"; echo "$servViews"; echo "<tr bgcolor=\"$color\"> <td width=\"5%\" align=\"right\">$servDate</td> <td width=\"73%\"><a href=\"\">$servName</a></td> <td align=\"left\" width=\"25%\">$servAuthor</td> <td align=\"left\" width=\"25%\">$servViews</td> </tr>"; $sI++; $sCount++; } } ?> Link to comment https://forums.phpfreaks.com/topic/41750-while-script-problems/ Share on other sites More sharing options...
Patrick3002 Posted March 8, 2007 Author Share Posted March 8, 2007 Please help i cannot figure this out... Link to comment https://forums.phpfreaks.com/topic/41750-while-script-problems/#findComment-202397 Share on other sites More sharing options...
vbnullchar Posted March 8, 2007 Share Posted March 8, 2007 do it like this.... see below <? $host="localhost"; $dbuser="root"; $dbpass="pass"; $db="php_01"; mysql_connect($host,$dbuser,$dbpass); @mysql_select_db($db) or die("Cant connect to db"); $sTable="jos_services"; if (!$selorder || !$seldisplay) { $selorder="sname ASC"; $seldisplay="10"; } else { $getserv = "SELECT `date`, `sname`, `author`, `views` FROM $sTable ORDER BY $selorder LIMIT $seldisplay"; $servResult=mysql_query($getserv); $i=1; echo "<table>"; while($row=mysql_fetch_array($servResult)) { $servDate=$row['date']; $servName=$row['sname']; $servAuthor=$row['author']; $servViews=$row['views']; echo "<tr bgcolor='".($i % 2 ? '#FFFFFF' : '#CCCCCC' ) ."'>"; echo "<td width=5% align=right>$servDate</td>"; echo "<td width=73%><a href=#>$servName</a></td>"; echo "<td align=left width=25%>$servAuthor</td>"; echo "<td align=left width=25%>$servViews</td>"; echo "</tr>"; $i++; } echo "</table>"; } ?> Link to comment https://forums.phpfreaks.com/topic/41750-while-script-problems/#findComment-202402 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.