Jump to content

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 . " ";
        }
      }
    }
  }
}

?>

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.