user4fun Posted February 22, 2009 Share Posted February 22, 2009 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 More sharing options...
jsilvia Posted February 23, 2009 Share Posted February 23, 2009 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 More sharing options...
justsomeguy Posted February 23, 2009 Share Posted February 23, 2009 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 More sharing options...
user4fun Posted February 24, 2009 Author Share Posted February 24, 2009 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 More sharing options...
justsomeguy Posted February 24, 2009 Share Posted February 24, 2009 It looks better, but it's still got several problems. You aren't testing this code as you write it are you? Link to comment Share on other sites More sharing options...
user4fun Posted February 24, 2009 Author Share Posted February 24, 2009 No, I am still tyring to get XAMPP working. I am about to give up and just follow the instruction on stalling Apache, SQL, PHP, and PhpMy Admin seperatly. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 24, 2009 Share Posted February 24, 2009 I've always installed everything separately, but I haven't installed Apache, I've just used IIS with PHP when testing. Link to comment Share on other sites More sharing options...
user4fun Posted February 25, 2009 Author Share Posted February 25, 2009 Just about every tutorial that I have used to far is horrible and nothing works. Any ideas where to get a good one. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 25, 2009 Share Posted February 25, 2009 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 More sharing options...
user4fun Posted February 26, 2009 Author Share Posted February 26, 2009 Thank you for the link. It looks like I might get it done this time.You never told me about the problems in teh last code I psoted.Thank you Link to comment Share on other sites More sharing options...
justsomeguy Posted February 26, 2009 Share Posted February 26, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.