Dane Posted November 21, 2007 Share Posted November 21, 2007 Hey guys. Bit of a problem. $resultQuery = "SELECT * FROM results WHERE result_teamid = '$team_url' ORDER BY result_id DESC"; $resultresult = mysql_query($resultQuery, $connect) or die(mysql_error()); while ($resultrow = mysql_fetch_array($resultresult)) { // Start Result While Loop $result_id = escape_data($resultrow['result_id']); $result_teamid = escape_data($resultrow['result_teamid']); } Im using <?php for ($i=0; $i<$result_id; $i++) { results here } ?> If i have 2 results in the database it extracts 2 results, if i have 3 results in the database it extracts 3 results. BUT the 2 or 3 results it shows are of the last entry into the database Quote Link to comment https://forums.phpfreaks.com/topic/78245-solved-extract-from-the-database/ Share on other sites More sharing options...
trq Posted November 21, 2007 Share Posted November 21, 2007 Because your overiding $result_id within each iteration of the while loop. Quote Link to comment https://forums.phpfreaks.com/topic/78245-solved-extract-from-the-database/#findComment-395943 Share on other sites More sharing options...
Dane Posted November 21, 2007 Author Share Posted November 21, 2007 so how would i go about doing it please? Quote Link to comment https://forums.phpfreaks.com/topic/78245-solved-extract-from-the-database/#findComment-395947 Share on other sites More sharing options...
trq Posted November 21, 2007 Share Posted November 21, 2007 What do you want to do where it says 'results here' that you can't do within the while loop? Quote Link to comment https://forums.phpfreaks.com/topic/78245-solved-extract-from-the-database/#findComment-395949 Share on other sites More sharing options...
Dane Posted November 21, 2007 Author Share Posted November 21, 2007 I want all the results out of the database in an order of DESC. Because in the while loop it only extracts one entry for some reason. Quote Link to comment https://forums.phpfreaks.com/topic/78245-solved-extract-from-the-database/#findComment-395956 Share on other sites More sharing options...
trq Posted November 21, 2007 Share Posted November 21, 2007 Use this an an example... <?php $sql = "SELECT result_id,result_teamid FROM results WHERE result_teamid = '$team_url' ORDER BY result_id DESC"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) echo $row['result_id']; echo $row['result_teamid']; } } } else { echo mysql_error(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/78245-solved-extract-from-the-database/#findComment-395959 Share on other sites More sharing options...
Dane Posted November 21, 2007 Author Share Posted November 21, 2007 thanks, works with a little modifiying to fit around my code. thanks mate. Quote Link to comment https://forums.phpfreaks.com/topic/78245-solved-extract-from-the-database/#findComment-395981 Share on other sites More sharing options...
Dane Posted November 21, 2007 Author Share Posted November 21, 2007 Hmm, it did work and i changed it a little and not it isnt working. Here is the full script. <?php session_start(); $resultQuery = "SELECT * FROM results WHERE result_teamid = '$team_url' ORDER BY result_id DESC"; if ($resultresult = mysql_query($resultQuery, $connect)) { if (mysql_num_rows($resultresult)) { while ($resultrow = mysql_fetch_assoc($resultresult)) { // Start Result While Loop $result_id = escape_data($resultrow['result_id']); $result_teamid = escape_data($resultrow['result_teamid']); $result_date = escape_data($resultrow['result_date']); $result_team = escape_data($resultrow['result_team']); $result_competition = escape_data($resultrow['result_competition']); $result_for = escape_data($resultrow['result_for']); $result_against = escape_data($resultrow['result_against']); // Check If The Team URL Is Correct if ($result_teamid == $team_url) { // Include Layout For Team include_once("layouts/".$team_layout."/results.html"); } // End If Statement // If Team URL Is Not Correct, Direct To Main URL else { // Start Else Statement // PHP SELF Re-directs To Main URL header('Location: '.$_SERVER['PHP SELF'].''); } // End Else Statement } } } // End result While Loop include_once('footer.php'); // This Includes The Footer Of The Website Layout ?> Quote Link to comment https://forums.phpfreaks.com/topic/78245-solved-extract-from-the-database/#findComment-395999 Share on other sites More sharing options...
Dane Posted November 21, 2007 Author Share Posted November 21, 2007 In the results.html it just echos out the variables. Quote Link to comment https://forums.phpfreaks.com/topic/78245-solved-extract-from-the-database/#findComment-396004 Share on other sites More sharing options...
trq Posted November 21, 2007 Share Posted November 21, 2007 What does results.html look like? Quote Link to comment https://forums.phpfreaks.com/topic/78245-solved-extract-from-the-database/#findComment-396019 Share on other sites More sharing options...
Dane Posted November 21, 2007 Author Share Posted November 21, 2007 <link href="style/layout1_style.css" rel="stylesheet"> <table width="489" height="1" cellpadding="0" cellspacing="0" border="0"> <tr> <td><img src="images/spacer.gif" height="2"></td> </tr> </table> <table width="489" cellpadding="0" cellspacing="0" border="0" align="center" class="resultstable"> <tr> <td width="80" height="19" align="left" valign="middle" class="headline-small"> <?php echo $result_date ?></td> <td width="30" height="19" align="center" valign="middle" class="headline-small"> vs</td> <td width="170" height="19" align="left" valign="middle" class="headline-small"> <a href="result.php?result_id=<?php echo $result_id ?>"><?php echo $result_team ?></a></td> <td width="149" height="19" align="left" valign="middle" class="headline-small"> <?php echo $result_competition ?></td> <td width="60" height="19" align="left" valign="middle" class="headline-small"> <?php if ($result_for > 15 || $result_for == 1) { echo '<font color="'.$win_colour.'">'.$result_for.'</font>'; } else if ($result_for < 15) { echo '<font color="'.$lose_colour.'">'.$result_for.'</font>'; } else if ($result_for == 15) { echo '<font color="'.$draw_colour.'">'.$result_for.'</font>'; } ?> - <?php if ($result_against > 15 || $result_against == 0) { echo '<font color="'.$win_colour.'">'.$result_against.'</font>'; } else if ($result_against < 15) { echo '<font color="'.$lose_colour.'">'.$result_against.'</font>'; } else if ($result_against == 15) { echo '<font color="'.$draw_colour.'">'.$result_against.'</font>'; } ?> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/78245-solved-extract-from-the-database/#findComment-396027 Share on other sites More sharing options...
trq Posted November 21, 2007 Share Posted November 21, 2007 PHP will not be parsed within a .html file unless your server has specifically been setup for it. You need to make results.html, reults.php. Also, if your expecting more than one result from your query (which I assume you are otherwise the while loop is not needed at all) your code will not work and will only display the last result. Quote Link to comment https://forums.phpfreaks.com/topic/78245-solved-extract-from-the-database/#findComment-396033 Share on other sites More sharing options...
Dane Posted November 21, 2007 Author Share Posted November 21, 2007 The php echos fine. But it only displays the last result. Im expecting 3 results and yes im only getting the last result. So how can i get it to work and etract all results from the database? Quote Link to comment https://forums.phpfreaks.com/topic/78245-solved-extract-from-the-database/#findComment-396041 Share on other sites More sharing options...
trq Posted November 21, 2007 Share Posted November 21, 2007 If your expecting more than one result you need a loop. All this part..... <td width="80" height="19" align="left" valign="middle" class="headline-small"> <?php echo $result_date ?></td> <td width="30" height="19" align="center" valign="middle" class="headline-small"> vs</td> <td width="170" height="19" align="left" valign="middle" class="headline-small"> <a href="result.php?result_id=<?php echo $result_id ?>"><?php echo $result_team ?></a></td> <td width="149" height="19" align="left" valign="middle" class="headline-small"> <?php echo $result_competition ?></td> <td width="60" height="19" align="left" valign="middle" class="headline-small"> needs to happen within your while loop. Make sense? Quote Link to comment https://forums.phpfreaks.com/topic/78245-solved-extract-from-the-database/#findComment-396044 Share on other sites More sharing options...
Dane Posted November 21, 2007 Author Share Posted November 21, 2007 Hmm ok. But the whole .html file is happening within my while loop. I tested putting all the the html in the while loop as code and not as an include and it works perfectly. But how can i make it so the html side of things is in a seperate file? Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/78245-solved-extract-from-the-database/#findComment-396047 Share on other sites More sharing options...
trq Posted November 21, 2007 Share Posted November 21, 2007 Oh... so it is. All you need do is simply change the include_once to include. Quote Link to comment https://forums.phpfreaks.com/topic/78245-solved-extract-from-the-database/#findComment-396051 Share on other sites More sharing options...
Dane Posted November 21, 2007 Author Share Posted November 21, 2007 It really annoys me when its something so simple and obvious but you cant see it..... Thanks for your time thorpe. I appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/78245-solved-extract-from-the-database/#findComment-396060 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.