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 Link to comment https://forums.phpfreaks.com/topic/288912-page-displays-but-not-data/ Share on other sites More sharing options...
Ch0cu3r Posted June 1, 2014 Share Posted June 1, 2014 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> 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 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
Archived
This topic is now archived and is closed to further replies.