Jump to content

Page displays but not data


Go to solution Solved by Ch0cu3r,

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

  • Solution

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>
Edited by Ch0cu3r
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.