Jump to content

Page displays but not data


FreakingOUT

Recommended Posts

I must be mixing apples and oranges here or something trying to get two columns/fields of MySQL data to display.

The basic HTML page display OK and there are no MySQL Connection errors (finally resolved those).

<HTML snipped>

<?php

require '...<URL snipped>...';

if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql="SELECT `name`, `id` FROM `roster`";

$result = mysqli_query($con,$sql);
$num=mysqli_num_rows($result);
mysqli_close($con);
?>

<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td>
<font face="Arial, Helvetica, sans-serif">NAME</font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif">ID</font>
</td>
</tr>
<?php

function mysqli_result($res, $row, $field=0) {
    $res->data_seek($row);
    $datarow = $res->fetch_array();
    return $datarow[$field];
} 

$i=0;
while ($i < $num) {
	$f1=mysqli_result($result,$i,$datarow[$field]);
	$f2=mysqli_result($result,$i,$datarow[$field]);
?>

<tr>
<td>
<font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font>
</td>
</tr>

<?php
         $i++;
}
?>

</table>

<?php
?>

<HTML snipped>


Any assistance is appreciated.

 

Thanks very much.

 

- FreakingOUT

 

Link to comment
https://forums.phpfreaks.com/topic/288912-page-displays-but-not-data/
Share on other sites

Whats with the mysqli_result function? Just use a while loop like so

<table>
<?php
$result = mysqli_query($con, 'SELECT id, name FROM roster');
while(list($id, $name) = mysqli_fetch_row($result))
{
?>
  <tr>
    <td><?php echo $id; ?></td>
    <td><?php echo $name; ?></td>
   </tr>
<?php
}
?>
</table>

Also don't use <font></font> in your HTML. Instead learn to use CSS to stylise your text

<style>
   body { font-family: Arial, Helvetica, sans-serif;   } /* Default text styling for all elements on the page */
</style>

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.