Jump to content

[SOLVED] Foreach with from Mysql


DEVILofDARKNESS

Recommended Posts

Hi,

 

How should I do the following?

 

I have made up a mysql table wich looks like the following:

region_id int

region_name varchar(50)

region_population int

region_outputs int

region_landsize int

 

I want to let everything shown (except the region_id) Like this:

region name  region pop.  reg outputs  reg landsize  [Radio Box <= which has as value the region_name]  . "<br>"

 

I thought this had to be with the foreach loop?

Or is it poosible too with a while?

 

Thanks!

 

Link to comment
https://forums.phpfreaks.com/topic/151935-solved-foreach-with-from-mysql/
Share on other sites

this will get you the basic output.

<?php
$sql = "select * from `table_name1";
$result = mysql_query($sql) or die(echo mysql_error());
while($row = mysql_fetch_array($result)) {
   echo "<input type=\"checkbox\" value=\"".$row['region_name']."\" name=\"region_name\">"."  ".$row['region_population']."  ".$row['region_outputs']."  ".$row['region_landsize']."<br>";
}

You might be after?

 

<?php

$sql = "select * from tbl";
if ($result = mysql_query($sql)) {
  if (mysql_num_rows($result)) {
    while ($row = mysql_fetch_array($result)) {
      foreach ($row as $k => $v) {
        if ($k != 'region_id') {
          echo $v . " ";
        }
      }
    }
  }
}

?>

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.