FreakingOUT Posted June 1, 2014 Share Posted June 1, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/288912-page-displays-but-not-data/ Share on other sites More sharing options...
Solution Ch0cu3r Posted June 1, 2014 Solution Share Posted June 1, 2014 (edited) 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 June 1, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/288912-page-displays-but-not-data/#findComment-1481559 Share on other sites More sharing options...
FreakingOUT Posted June 1, 2014 Author Share Posted June 1, 2014 Thank you so very much, Ch0cu3r ... it works !!! Yes, I know, I need to clean things up with CSS. - FreakingOUT Quote Link to comment https://forums.phpfreaks.com/topic/288912-page-displays-but-not-data/#findComment-1481561 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.