Jump to content

Print the results of a query


Mr Chris

Recommended Posts

Hi, say I have a query like so:

 


foreach($_REQUEST['r'] as $position => $row) 
    
  {   $row = implode("', '",$row);
      $result = mysql_query("Insert into player_stats (position,shirt_number,player_id,goals,cards,substituted,used_sub,injury,season,report_id)   
                             values('$position','$row','$currentSeason','$report_id')");
  }

 

How do I print the results of that query to my Browser for each time?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/210725-print-the-results-of-a-query/
Share on other sites

You would do a separate query to get the results and print them. This is an example of how I would do it:

 

 
// Fill in the information for your database values here:
$dbc = mysqli_connect('db_host', 'dbuser', 'dbpassword', 'dbname');

$query = "SELECT * FROM player_stats"; // You could add a condition here WHERE player_id = $playerid"; as an example
$data = mysql_query($dbc, $query);
while ($row = mysqli_fetch_array($data)) {
    echo $row['position'] . '<br>'; // Repeat for what you wish to display
    echo $row['shirt_number'] . '<br>';
    echo $row['player_id'] . '<br>';
}

 

Or using what you have and just print that information.

 

// Add this under your values('$position','$row','$currentSeason','$report_id')");
   echo "$position position was added.<br>";
   echo "$row row was added.<br>";
   echo "$currentSeason season was added.<br>";
   echo "$report_id report id was added.<br>";

} // close the foreach loop

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.