Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/78245-solved-extract-from-the-database/
Share on other sites

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();
  }

?>

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

?>

<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>

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.

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?

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.