Jump to content

If Statment And Arrays


user4fun

Recommended Posts

Can this be any cleaner? Can it be organized better?

WeHave($num_rows){for ($i=1; $i<=$num_rows; $i++)		{	  while($foundrow = mysql_fetch_array($result))	  {	  echo $i " - ";	 echo $row['FirstName'] . " " . $row['LastName'];	  echo "<br />";	  }		}}$result = mysql_query("SELECT * FROM $tblname WHERE $colname = $neededvar && Price <= Budget ORDER BY BPM, PKID);	$num_rows = mysql_num_rows($result);	$foundrow = mysql_fetch_row($result);if$num_rows == 0{echo "Nothing found";}Else {WeHave($num_rows);}

What would the code do it if find that rows that have the same BPM value?

Link to comment
Share on other sites

hi use this code.<?phperror_reporting(E_ALL);ini_set('html_errors', 1);ini_set('log_errors', 0);ini_set('display_errors', 1);include ("dbcon.php");$sql=mysql_query("Select * From admin");$i = 0;$j = 3;echo "<table>";while($query = mysql_fetch_array($sql)){ if(($i%3) == 0) { echo "<tr>"; } $rename = $query['subcategory']; ?><td><?php echo $rename; ?></td><?phpif (($i % $j) == ($j - 1)) { echo "</tr>"; } $i++;}echo "</table>";?>

Link to comment
Share on other sites

Silvia, that code is totally different than the original code and doesn't do the same thing. I don't know why you posted that.user4fun - that code is pretty bad. You're missing several basic things. First, if you're trying to define a function, you start it with the word "function".http://www.php.net/manual/en/functions.user-defined.phpAlso, keep in mind that if you want to use a variable inside of a function that does not get passed to the function, then you need to declare it globally. In other words, if you want your function to use $result, then either pass $result to the function or declare it globally.Why are you passing $num_rows to the function? Shouldn't you just pass the result? The function can figure out how many records are in the result.You're also going to skip the first row because you call mysql_fetch_assoc once without doing anything with the row. You're fetching the first row but not doing anything with it.Also, refresh what the syntax of an if statement looks like.http://www.php.net/manual/en/control-structures.if.php

Link to comment
Share on other sites

How does this look? The pointis to list the first three results and give the option to see more if there are infact any. If there aren't, then the option would not be available.

Function WeHave(){global $num_rows;$num_rows = mysql_num_rows($result);while($foundrow = mysql_fetch_array($result))	{	 $i = 1;	 echo $i " - ";	 echo $foundrow['FirstName'] . " " . $foundrow['LastName'];	 echo "<br />"; 	 $i++;	 	 if i = 4;			 {			   echo $num_rows . " RESULTS were found but we have to STOP at 3"; 			   DoMore($num_rows);			   Endif;			 }	} echo " By reaching this it means that ONLY 3 or less results were found. The function DoMore() will not be reached.";echo " We had " $num_rows;}$result = mysql_query("SELECT * FROM tblBusiness INNER JOIN tblCampaign ON tblBusiness.BusinessPKID = tblCampaign.BusinessFKID WHERE tblCampaign.StartDate <= $timemark && tblCampaign.EndTime >= $timemark && tbl.Campaign.Price <= tblCampaign.Budget ORDER BY tblCampaign.BPM, tblCampaign.PKID);WeHave($result);

JUSTSOMEGUY;You opinions are always very well respected. I hope you read this post.

Link to comment
Share on other sites

I always start here:http://www.php.net/manual/en/install.windows.phpI don't use the installer, I follow the manual installation steps. I know it sounds trite and boring, but it's important to read that entire thing carefully. Every time I've installed it I've followed that guide and gotten it to work on the first time. Every time I've fixed someone else's broken installation it was because they were following that guide and skipped one or more steps because they didn't read them. The sections in that manual I follow are the Manual Installation Steps, Microsoft IIS-specific steps, and the Installation of extensions on Windows steps.Also, keep in mind you can only have 1 web server running on the normal HTTP port. It would probably be best if you uninstalled Apache before trying to install IIS, and also to install IIS and make sure it's working before installing PHP. Thankfully IIS is easy enough to install and set up, as long as you have the Windows CD.

Link to comment
Share on other sites

I know, it's hard to debug when you can't test the code.The WeHave function still isn't accepting parameters, you need to add the parameter list to the function definition. You're sending $result to it, but it's not set up to accept anything.The syntax for this if statement is wrong:if i = 4;That should be if ($i == 4) instead.You're also missing a quote on the SQL statement.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...