Jump to content

while script problems....


Patrick3002

Recommended Posts

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

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

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.